Projects
home:rottame:vhosts-ng:php8-extensions
php8-xdebug
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
Expand all
Collapse all
Changes of Revision 2
View file
php8-xdebug.spec
Changed
@@ -19,7 +19,7 @@ %define pkg_name xdebug %define pkg_version %{version} Name: php8-%{pkg_name} -Version: 3.1.5 +Version: 3.2.0 Release: 0 Summary: Extended PHP debugger License: PHP-3.0
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/CONTRIBUTING.rst
Deleted
@@ -1,108 +0,0 @@ -Contributing -============ - -Xdebug is hosted on Github. The source code can be browsed there and can be -checked out with:: - - git clone git://github.com/xdebug/xdebug.git - -If you think you want to fix a bug or work on a new feature, then you need to -follow the instructions below. Please reach out first to discuss your -suggested changes as well. - -Initial Set-up --------------- - -- Fork Xdebug on GitHub. -- Make sure you have configured your Author Name and Author Email with GIT. - Xdebug doesn't accept contributions from accounts with unnatural names. -- Clone the repository:: - - git clone git@github.com:{your username}/xdebug.git - -- Change into the ``xdebug`` repository:: - - cd xdebug - -- Add the original repository as ``upstream`` remote:: - - git remote add upstream git://github.com/xdebug/xdebug.git - git fetch upstream - -- Add a tracking branch for ``xdebug 3.0``:: - - git checkout --track origin/xdebug_3_0 - -Branches --------- - -There are two branches in operation: - -``master`` - This is were all new feature Pull Requests should be targeted at -``xdebug_3_0`` - This is were all bug fix Pull Requests should be targeted at. The - maintainer will add them to ``master`` too when merging the Pull Request. - -Working on a Pull Request -------------------------- - -- Make sure that your ``master`` and ``xdebug_3_0`` branches are up to date - with the ``upstream`` repository. -- Create an issue in the `issue tracker <https://bugs.xdebug.org>`_ (if none - exists yet). -- Switch to the right target branch (``master`` for features, ``xdebug_3_0`` - for bug fixes). -- Create a feature branch:: - - git checkout -b issue{issue number}-{description} - - For example:: - - git checkout -b issue1893-crash-with-fiber - -- For a bug fix, write one or more test cases to verify that the problem - currently exists, and also to define what the output should be. Xdebug uses - PHP's `phpt tests <https://qa.php.net/write-test.php>`_. The ``README.rst`` - file contains information on how to run the tests. - - Each of Xdebug's modes has a specific directory where to place tests. For - example, for code coverage that is ``tests/coverage``. Test case names - should follow the following pattern:: - - tests/{feature-group}bug0{issue-number}.phpt - - If you need more than one test, append ``-001`` after the issue number. - - Pull Requests without tests won't be accepted. - -- Fix and/or write the code. - -- Before you submit a PR, make sure each commit is a single logical unit. The - main commit that implements the issue, should have as commit message ``Fixed - bug #1893: `` followed by the Summary of the issue in the issue tracker. The - message should state what the change was about. For example:: - - Fixed bug #1893: Crash with ext-fiber with xdebug.mode=coverage - -- Before you submit a PR, make sure to rebase first on the branch that you - will be targeting, for example to rebase against the current bug fix - branch:: - - git fetch upstream && git rebase upstream/xdebug_3_0 - -- Push your changes to your remote repository:: - - git push origin {branch-name} - - For example:: - - git push origin issue1893-crash-with-fiber - -- Once you're satisfied, generate a pull request. Make sure that the title is - in one line, it's fine if it's a few characters larger than what GitHub - likes. Do not let the title spill over into the description with ``...```. - - In the description, explain what you changed, and why, and how your solution - is the right one. Feel free to include questions, and pointers to specific - things that need close review.
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/README.rst
Deleted
@@ -1,123 +0,0 @@ -Xdebug -====== - -.. image:: https://github.com/xdebug/xdebug/workflows/Build/badge.svg - :target: https://github.com/xdebug/xdebug/actions?query=workflow%3ABuild -.. image:: https://ci.appveyor.com/api/projects/status/glp9xfsmt1p25nkn?svg=true - :target: https://ci.appveyor.com/project/derickr/xdebug -.. image:: https://circleci.com/gh/xdebug/xdebug/tree/master.svg?style=svg - :target: https://circleci.com/gh/xdebug/xdebug - -Xdebug is a debugging tool for PHP. It provides step-debugging and a whole -range of development helpers, such as stack traces, a code profiler, features to -dump the full execution of your script to a file, and more. - -Requirements ------------- - -Xdebug requires a `supported version <https://www.php.net/supported-versions.php>`_ of PHP. For -installation it requires the `pecl` tool (available through the `php-pear` -package), unless your Linux distribution has an Xdebug package (`php-xdebug`). - -Installation ------------- - -On most Linux distributions you can install Xdebug through its package -manager. You can also compile from source with the `pecl` tool through `pecl -install xdebug`. The latter also works for MacOS as long as PHP is installed -with Homebrew. - -On Windows, you need to `download <https://xdebug.org/download#releases>`_ a -binary. Use the `Wizard <https://xdebug.org/wizard>`_. - -Unless you have installed Xdebug with a package manager on Linux, you also -need to add the following line to your `php.ini` file, or create a new Xdebug -specific ini file `xdebug.ini` in the `conf.d` directory. In either case, it -needs the following line added:: - - zend_extension=xdebug - -For more extensive installation instructions, see the documentation at -https://xdebug.org/docs/install - -Configuration -------------- - -Most features in Xdebug have to be opted in into. Each feature has a specific -opt-in. For example to use the `step debugger -<https://xdebug.org/docs/remote>`_ you need to set `xdebug.remote_enable=1` in -your configuration file. The step debugger requires an IDE (client), of which -there are many `available <https://xdebug.org/docs/remote#clients>`_. - -The documentation has instructions for each of Xdebug's features: -https://xdebug.org/docs/ and a full list of `settings -<https://xdebug.org/docs/all_settings>`_ is also available there. - -Contributing ------------- - -Xdebug is written in C, and extensive knowledge of PHP's internals is -necessary to be able to contribute. Contributing guidance is available -`separately <https://github.com/xdebug/xdebug/blob/master/CONTRIBUTING.rst>`_. - -Before you begin to contribute, please reach out first. Either through email -(address at the bottom), an issue in the `issue tracker -<https://bugs.xdebug.org>`_ or preferably through IRC on Freenode's #xdebug -channel. - -Testing -------- - -If you are familiar with compiling PHP extension from source, have a local -checkout of Xdebug's GitHub repository, and have compiled Xdebug in that -directory following the instructions under `installation -<https://xdebug.org/docs/install#source>`_ you can run Xdebug's tests by -running:: - - php run-xdebug-tests.php - -The test framework requires that the PHP binary on the path has Xdebug loaded, -with remote debugging enabled through `xdebug.mode=debug`. It is possible -to skip remote debugging tests by exporting the `SKIP_DBGP_TESTS=1` environment -variable. - -The `SKIP_UNPARALLEL_TESTS=1` can be used to skip tests that can not run in -parallel environments, and the `SKIP_SLOW_TESTS=1` environment variable to skip -slow tests. The `OPCACHE` environment variable can either be `yes` or `no` and -controls whether the test framework enables or disables OpCache. - -Licensing ---------- - -Xdebug is released under `The Xdebug License -<https://github.com/xdebug/xdebug/blob/master/LICENSE>`_, which is based on -`The PHP License <https://github.com/php/php-src/blob/master/LICENSE>`_. It is -an Open Source license (though not explicitly endorsed by the Open Source -Initiative). - -Further Reading ---------------- - -Xdebug has extensive documentation on its `website <https://xdebug.org/docs>`_. -There are over a hundred settings and many functions documented. Please have a -look through the wealth of information that Xdebug can provide to make your -every day development with PHP easier. - -Support -------- - -For questions regarding Xdebug, please use `StackOverflow -<https://stackoverflow.com/questions/tagged/xdebug>`_, and tag your question -with `xdebug`. - -You can also find ad-hoc and sporadic support on IRC: ``freenode/#xdebug``. -You can do that with your favourite client, or by using their `webchat -<http://webchat.freenode.net/?channels=#xdebug>`_. - -If you think that you encountered a bug, please file a detailed bug report -at https://bugs.xdebug.org. You are required to create an account, this is -so that you can be contacted for additional information and to keep out -spam. - - -Derick Rethans — derick@xdebug.org
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/config.m4
Deleted
@@ -1,120 +0,0 @@ -dnl config.m4 for extension Xdebug - -PHP_ARG_ENABLE(xdebug, whether to enable Xdebug support, - --enable-xdebug Enable Xdebug support) - -PHP_ARG_ENABLE(xdebug-dev, whether to enable Xdebug developer build flags, - --enable-xdebug-dev Xdebug: Enable developer flags,, no) - -PHP_ARG_WITH(xdebug-compression, whether to compress profiler files (requires zlib), - --without-xdebug-compression Xdebug: Disable compression through zlib,yes,no) - -m4_include(m4/pkg.m4) -m4_include(m4/clocks.m4) - -if test "$PHP_XDEBUG" != "no"; then - AC_MSG_CHECKING(Check for supported PHP versions) - PHP_XDEBUG_FOUND_VERSION=`${PHP_CONFIG} --version` - PHP_XDEBUG_FOUND_VERNUM=`echo "${PHP_XDEBUG_FOUND_VERSION}" | $AWK 'BEGIN { FS = "."; } { printf "%d", ($1 * 100 + $2) * 100 + $3;}'` - if test "$PHP_XDEBUG_FOUND_VERNUM" -lt "70200"; then - AC_MSG_ERROR(not supported. Need a PHP version >= 7.2.0 and < 8.2.0 (found $PHP_XDEBUG_FOUND_VERSION)) - else - if test "$PHP_XDEBUG_FOUND_VERNUM" -ge "80200"; then - AC_MSG_ERROR(not supported. Need a PHP version >= 7.2.0 and < 8.2.0 (found $PHP_XDEBUG_FOUND_VERSION)) - else - AC_MSG_RESULT(supported ($PHP_XDEBUG_FOUND_VERSION)) - fi - fi - - AC_DEFINE(HAVE_XDEBUG,1, ) - - old_CPPFLAGS=$CPPFLAGS - CPPFLAGS="$INCLUDES $CPPFLAGS" - - AC_XDEBUG_CLOCK - - AC_CHECK_HEADERS(netinet/in.h poll.h sys/poll.h) - - PHP_CHECK_LIBRARY(m, cos, PHP_ADD_LIBRARY(m,, XDEBUG_SHARED_LIBADD) ) - - if test "$PHP_XDEBUG_COMPRESSION" != "no"; then - PKG_CHECK_MODULES(ZLIB, zlib >= 1.2.9, - PHP_EVAL_LIBLINE($ZLIB_LIBS, XDEBUG_SHARED_LIBADD) - PHP_EVAL_INCLINE($ZLIB_CFLAGS) - - AC_DEFINE(HAVE_XDEBUG_ZLIB,1, ) - , ) - fi - - CPPFLAGS=$old_CPPFLAGS - - if test "$PHP_XDEBUG_DEV" = "yes"; then - AX_CHECK_COMPILE_FLAG(-Wbool-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wbool-conversion") - AX_CHECK_COMPILE_FLAG(-Wdeclaration-after-statement, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wdeclaration-after-statement") - AX_CHECK_COMPILE_FLAG(-Wdiscarded-qualifiers, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wdiscarded-qualifiers") - AX_CHECK_COMPILE_FLAG(-Wduplicate-enum, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wduplicate-enum") - AX_CHECK_COMPILE_FLAG(-Wempty-body, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wempty-body") - AX_CHECK_COMPILE_FLAG(-Wenum-compare, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wenum-compare") - AX_CHECK_COMPILE_FLAG(-Werror, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Werror") - AX_CHECK_COMPILE_FLAG(-Wextra, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wextra") - AX_CHECK_COMPILE_FLAG(-Wformat-nonliteral, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wformat-nonliteral") - AX_CHECK_COMPILE_FLAG(-Wformat-security, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wformat-security") - AX_CHECK_COMPILE_FLAG(-Wheader-guard, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wheader-guard") - AX_CHECK_COMPILE_FLAG(-Wincompatible-pointer-types-discards-qualifiers, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wincompatible-pointer-types-discards-qualifiers") - AX_CHECK_COMPILE_FLAG(-Wimplicit-fallthrough, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wimplicit-fallthrough") - AX_CHECK_COMPILE_FLAG(-Winit-self, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Winit-self") - AX_CHECK_COMPILE_FLAG(-Wlogical-not-parentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wlogical-not-parentheses") - AX_CHECK_COMPILE_FLAG(-Wlogical-op, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wlogical-op") - AX_CHECK_COMPILE_FLAG(-Wlogical-op-parentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wlogical-op-parentheses") - AX_CHECK_COMPILE_FLAG(-Wloop-analysis, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wloop-analysis") - AX_CHECK_COMPILE_FLAG(-Wmaybe-uninitialized, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmaybe-uninitialized") - AX_CHECK_COMPILE_FLAG(-Wmissing-format-attribute, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmissing-format-attribute") - AX_CHECK_COMPILE_FLAG(-Wno-missing-field-initializers, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-missing-field-initializers") - AX_CHECK_COMPILE_FLAG(-Wno-sign-compare, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-sign-compare") - AX_CHECK_COMPILE_FLAG(-Wno-unused-but-set-variable, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-but-set-variable") - AX_CHECK_COMPILE_FLAG(-Wno-unused-parameter, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-parameter") - AX_CHECK_COMPILE_FLAG(-Wno-variadic-macros, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-variadic-macros") - AX_CHECK_COMPILE_FLAG(-Wparentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wparentheses") - AX_CHECK_COMPILE_FLAG(-Wpointer-bool-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wpointer-bool-conversion") - AX_CHECK_COMPILE_FLAG(-Wsizeof-array-argument, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wsizeof-array-argument") - AX_CHECK_COMPILE_FLAG(-Wstring-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wstring-conversion") - AX_CHECK_COMPILE_FLAG(-Wwrite-strings, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wwrite-strings") - AX_CHECK_COMPILE_FLAG(-Wpointer-arith, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wpointer-arith") - AX_CHECK_COMPILE_FLAG(-fdiagnostics-show-option, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fdiagnostics-show-option") - AX_CHECK_COMPILE_FLAG(-fno-exceptions, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fno-exceptions") - AX_CHECK_COMPILE_FLAG(-fno-omit-frame-pointer, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fno-omit-frame-pointer") - AX_CHECK_COMPILE_FLAG(-fno-optimize-sibling-calls, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fno-optimize-sibling-calls") - AX_CHECK_COMPILE_FLAG(-fsanitize-address, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fsanitize-address") - AX_CHECK_COMPILE_FLAG(-fstack-protector, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fstack-protector") - - MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS" - STD_CFLAGS="-g -O0 -Wall" - fi - - PHP_XDEBUG_CFLAGS="$STD_CFLAGS $MAINTAINER_CFLAGS" - - XDEBUG_BASE_SOURCES="src/base/base.c src/base/filter.c" - XDEBUG_LIB_SOURCES="src/lib/usefulstuff.c src/lib/compat.c src/lib/crc32.c src/lib/file.c src/lib/hash.c src/lib/headers.c src/lib/lib.c src/lib/llist.c src/lib/log.c src/lib/set.c src/lib/str.c src/lib/timing.c src/lib/var.c src/lib/var_export_html.c src/lib/var_export_line.c src/lib/var_export_text.c src/lib/var_export_xml.c src/lib/xml.c" - - XDEBUG_COVERAGE_SOURCES="src/coverage/branch_info.c src/coverage/code_coverage.c" - XDEBUG_DEBUGGER_SOURCES="src/debugger/com.c src/debugger/debugger.c src/debugger/handler_dbgp.c src/debugger/handlers.c" - XDEBUG_DEVELOP_SOURCES="src/develop/develop.c src/develop/monitor.c src/develop/php_functions.c src/develop/stack.c src/develop/superglobals.c" - XDEBUG_GCSTATS_SOURCES="src/gcstats/gc_stats.c" - XDEBUG_PROFILER_SOURCES="src/profiler/profiler.c" - XDEBUG_TRACING_SOURCES="src/tracing/trace_computerized.c src/tracing/trace_html.c src/tracing/trace_textual.c src/tracing/tracing.c" - - PHP_NEW_EXTENSION(xdebug, xdebug.c $XDEBUG_BASE_SOURCES $XDEBUG_LIB_SOURCES $XDEBUG_COVERAGE_SOURCES $XDEBUG_DEBUGGER_SOURCES $XDEBUG_DEVELOP_SOURCES $XDEBUG_GCSTATS_SOURCES $XDEBUG_PROFILER_SOURCES $XDEBUG_TRACING_SOURCES, $ext_shared,,$PHP_XDEBUG_CFLAGS,,yes) - PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/base) - PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/lib) - PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/coverage) - PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/debugger) - PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/develop) - PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/gcstats) - PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/profiler) - PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/tracing) - PHP_SUBST(XDEBUG_SHARED_LIBADD) - PHP_ADD_MAKEFILE_FRAGMENT - - PHP_ADD_INCLUDE($ext_srcdir/src) - PHP_ADD_INCLUDE($ext_builddir/src) -fi
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/php_xdebug.h
Deleted
@@ -1,111 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2022 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef PHP_XDEBUG_H -#define PHP_XDEBUG_H - -#define XDEBUG_NAME "Xdebug" -#define XDEBUG_VERSION "3.1.5" -#define XDEBUG_AUTHOR "Derick Rethans" -#define XDEBUG_COPYRIGHT "Copyright (c) 2002-2022 by Derick Rethans" -#define XDEBUG_COPYRIGHT_SHORT "Copyright (c) 2002-2022" -#define XDEBUG_URL "https://xdebug.org" -#define XDEBUG_URL_FAQ "https://xdebug.org/docs/faq#api" - -#include "php.h" - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include "base/base_globals.h" -#include "coverage/branch_info.h" -#include "coverage/code_coverage.h" -#include "debugger/debugger.h" -#include "develop/develop.h" -#include "lib/lib.h" -#include "gcstats/gc_stats.h" -#include "profiler/profiler.h" -#include "tracing/tracing.h" -#include "lib/compat.h" -#include "lib/hash.h" -#include "lib/llist.h" -#include "lib/vector.h" -#include "lib/timing.h" - -extern zend_module_entry xdebug_module_entry; -#define phpext_xdebug_ptr &xdebug_module_entry - -#define OUTPUT_NOT_CHECKED -1 -#define OUTPUT_IS_TTY 1 -#define OUTPUT_NOT_TTY 0 - -#ifdef PHP_WIN32 -#define PHP_XDEBUG_API __declspec(dllexport) -#else -#define PHP_XDEBUG_API -#endif - -#ifdef ZTS -#include "TSRM.h" -#endif - -#include "main/SAPI.h" - -#define XDEBUG_ALLOWED_HALT_LEVELS (E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE ) - -PHP_MINIT_FUNCTION(xdebug); -PHP_MSHUTDOWN_FUNCTION(xdebug); -PHP_RINIT_FUNCTION(xdebug); -PHP_RSHUTDOWN_FUNCTION(xdebug); -PHP_MINFO_FUNCTION(xdebug); -ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xdebug); - -int xdebug_is_output_tty(); - -ZEND_BEGIN_MODULE_GLOBALS(xdebug) - struct { - xdebug_base_globals_t base; - xdebug_coverage_globals_t coverage; - xdebug_debugger_globals_t debugger; - xdebug_develop_globals_t develop; - xdebug_gc_stats_globals_t gc_stats; - xdebug_library_globals_t library; - xdebug_profiler_globals_t profiler; - xdebug_tracing_globals_t tracing; - } globals; - struct { - xdebug_base_settings_t base; - xdebug_coverage_settings_t coverage; - xdebug_debugger_settings_t debugger; - xdebug_develop_settings_t develop; - xdebug_gc_stats_settings_t gc_stats; - xdebug_library_settings_t library; - xdebug_profiler_settings_t profiler; - xdebug_tracing_settings_t tracing; - } settings; -ZEND_END_MODULE_GLOBALS(xdebug) - -#ifdef ZTS -#define XG(v) TSRMG(xdebug_globals_id, zend_xdebug_globals *, v) -#else -#define XG(v) (xdebug_globals.v) -#endif - -#define XG_BASE(v) (XG(globals.base.v)) -#define XINI_BASE(v) (XG(settings.base.v)) - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/run-xdebug-tests.php
Deleted
@@ -1,3107 +0,0 @@ -#!/usr/bin/env php -<?php -/* - +----------------------------------------------------------------------+ - | PHP Version 7 | - +----------------------------------------------------------------------+ - | Copyright (c) The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | https://php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Ilia Alshanetsky <iliaa@php.net> | - | Preston L. Bannister <pbannister@php.net> | - | Marcus Boerger <helly@php.net> | - | Derick Rethans <derick@php.net> | - | Sander Roobol <sander@php.net> | - | (based on version by: Stig Bakken <ssb@php.net>) | - | (based on the PHP 3 test framework by Rasmus Lerdorf) | - +----------------------------------------------------------------------+ - */ - -/* $Id: 7c135b2dd493cb5e6f7a785a4ee452a8dbfc4380 $ */ - -define('INIT_DIR', getcwd()); - -// change into the PHP source directory. -if (getenv('TEST_PHP_SRCDIR')) { - @chdir(getenv('TEST_PHP_SRCDIR')); -} -define('TEST_PHP_SRCDIR', getcwd()); - - -/* Sanity check to ensure that pcre extension needed by this script is available. - * In the event it is not, print a nice error message indicating that this script will - * not run without it. - */ - -if (!extension_loaded('pcre')) { - echo <<<NO_PCRE_ERROR - -+-----------------------------------------------------------+ -| ! ERROR ! | -| The test-suite requires that you have pcre extension | -| enabled. To enable this extension either compile your PHP | -| with --with-pcre-regex or if you've compiled pcre as a | -| shared module load it via php.ini. | -+-----------------------------------------------------------+ - -NO_PCRE_ERROR; - exit(1); -} - -if (!function_exists('proc_open')) { - echo <<<NO_PROC_OPEN_ERROR - -+-----------------------------------------------------------+ -| ! ERROR ! | -| The test-suite requires that proc_open() is available. | -| Please check if you disabled it in php.ini. | -+-----------------------------------------------------------+ - -NO_PROC_OPEN_ERROR; - exit(1); -} - -// If timezone is not set, use UTC. -if (ini_get('date.timezone') == '') { - date_default_timezone_set('UTC'); -} - -// Delete some security related environment variables -putenv('SSH_CLIENT=deleted'); -putenv('SSH_AUTH_SOCK=deleted'); -putenv('SSH_TTY=deleted'); -putenv('SSH_CONNECTION=deleted'); - -set_time_limit(0); - -ini_set('pcre.backtrack_limit', PHP_INT_MAX); - -// delete as much output buffers as possible -while (@ob_end_clean()); -if (ob_get_level()) echo "Not all buffers were deleted.\n"; - -error_reporting(E_ALL); - -$environment = $_ENV ?? array(); -// Note: php.ini-development sets variables_order="GPCS" not "EGPCS", in which case $_ENV is NOT populated. -// detect and handle this case, or die or warn -if (empty($environment)) { - // not documented, but returns array of all environment variables - $environment = getenv(); -} -if (empty($environment'TEMP')) { - $environment'TEMP' = sys_get_temp_dir(); - - if (empty($environment'TEMP')) { - // for example, OpCache on Windows will fail in this case because child processes (for tests) will not get - // a TEMP variable, so GetTempPath() will fallback to c:\windows, while GetTempPath() will return %TEMP% for parent - // (likely a different path). The parent will initialize the OpCache in that path, and child will fail to reattach to - // the OpCache because it will be using the wrong path. - die("TEMP environment is NOT set"); - } else if (count($environment) == 1) { - // not having other environment variables, only having TEMP, is probably ok, but strange and may make a - // difference in the test pass rate, so warn the user. - echo "WARNING: Only 1 environment variable will be available to tests(TEMP environment variable)" . PHP_EOL; - } -} -// -if ((substr(PHP_OS, 0, 3) == "WIN") && empty($environment"SystemRoot")) { - $environment"SystemRoot" = getenv("SystemRoot"); -} - -// Don't ever guess at the PHP executable location. -// Require the explicit specification. -// Otherwise we could end up testing the wrong file! - -$php = null; -$php_cgi = null; -$phpdbg = null; - -if (getenv('TEST_PHP_EXECUTABLE')) { - $php = getenv('TEST_PHP_EXECUTABLE'); - - if ($php == 'auto') { - $php = TEST_PHP_SRCDIR . '/sapi/cli/php'; - putenv("TEST_PHP_EXECUTABLE=$php"); - - if (!getenv('TEST_PHP_CGI_EXECUTABLE')) { - $php_cgi = TEST_PHP_SRCDIR . '/sapi/cgi/php-cgi'; - - if (file_exists($php_cgi)) { - putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi"); - } else { - $php_cgi = null; - } - } - } - $environment'TEST_PHP_EXECUTABLE' = $php; -} else { - $php = trim(`which php`); - $environment'TEST_PHP_EXECUTABLE' = $php; -} - -if (getenv('TEST_PHP_CGI_EXECUTABLE')) { - $php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE'); - - if ($php_cgi == 'auto') { - $php_cgi = TEST_PHP_SRCDIR . '/sapi/cgi/php-cgi'; - putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi"); - } - - $environment'TEST_PHP_CGI_EXECUTABLE' = $php_cgi; -} - -if (!getenv('TEST_PHPDBG_EXECUTABLE')) { - if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) . "/phpdbg.exe")) { - $phpdbg = realpath(dirname($php) . "/phpdbg.exe"); - } elseif (file_exists(dirname($php) . "/../../sapi/phpdbg/phpdbg")) { - $phpdbg = realpath(dirname($php) . "/../../sapi/phpdbg/phpdbg"); - } elseif (file_exists("./sapi/phpdbg/phpdbg")) { - $phpdbg = realpath("./sapi/phpdbg/phpdbg"); - } elseif (file_exists(dirname($php) . "/phpdbg")) { - $phpdbg = realpath(dirname($php) . "/phpdbg"); - } else { - $phpdbg = null; - } - if ($phpdbg) { - putenv("TEST_PHPDBG_EXECUTABLE=$phpdbg"); - } -} - -if (getenv('TEST_PHPDBG_EXECUTABLE')) { - $phpdbg = getenv('TEST_PHPDBG_EXECUTABLE'); - - if ($phpdbg == 'auto') { - $phpdbg = TEST_PHP_SRCDIR . '/sapi/phpdbg/phpdbg'; - putenv("TEST_PHPDBG_EXECUTABLE=$phpdbg"); - } - - $environment'TEST_PHPDBG_EXECUTABLE' = $phpdbg; -} - -if (!function_exists("hrtime")) { - function hrtime(bool $as_num = false) - { - $t = microtime(true); - - if ($as_num) { - return $t * 1000000000; - } - - $s = floor($t); - return array(0 => $s, 1 => ($t - $s) * 1000000000); - } -} - -function verify_config() -{ - global $php; - - if (empty($php) || !file_exists($php)) { - error('environment variable TEST_PHP_EXECUTABLE must be set to specify PHP executable!'); - } - - if (!is_executable($php)) { - error("invalid PHP executable specified by TEST_PHP_EXECUTABLE = $php"); - } -} - -if (getenv('TEST_PHP_LOG_FORMAT')) { - $log_format = strtoupper(getenv('TEST_PHP_LOG_FORMAT')); -} else { - $log_format = 'LEODS'; -} - -// Check whether a detailed log is wanted. -if (getenv('TEST_PHP_DETAILED')) { - $DETAILED = getenv('TEST_PHP_DETAILED'); -} else { - $DETAILED = 0; -} - -junit_init(); - -if (getenv('SHOW_ONLY_GROUPS')) { - $SHOW_ONLY_GROUPS = explode(",", getenv('SHOW_ONLY_GROUPS')); -} else { - $SHOW_ONLY_GROUPS = array(); -} - -// Check whether user test dirs are requested. -if (getenv('TEST_PHP_USER')) { - $user_tests = explode(',', getenv('TEST_PHP_USER')); -} else { - $user_tests = array(); -} - -$exts_to_test = array(); -$ini_overwrites = array( - 'output_handler=', - 'open_basedir=', - 'disable_functions=', - 'output_buffering=Off', - 'error_reporting=' . (E_ALL | E_STRICT), - 'display_errors=1', - 'display_startup_errors=1', - 'log_errors=0', - 'html_errors=0', - 'track_errors=0', - 'report_memleaks=1', - 'report_zend_debug=0', - 'docref_root=', - 'docref_ext=.html', - 'error_prepend_string=', - 'error_append_string=', - 'auto_prepend_file=', - 'auto_append_file=', - 'ignore_repeated_errors=0', - 'precision=14', - 'memory_limit=128M', - 'log_errors_max_len=0', - 'opcache.fast_shutdown=0', - 'opcache.file_update_protection=0', - 'opcache.preload=', - 'zend.assertions=1', -); - -$no_file_cache = '-d opcache.file_cache= -d opcache.file_cache_only=0'; - -function write_information() -{ - global $php, $php_cgi, $phpdbg, $php_info, $user_tests, $ini_overwrites, $pass_options, $exts_to_test, $valgrind, $no_file_cache; - - // Get info from php - $info_file = __DIR__ . '/run-test-info.php'; - @unlink($info_file); - $php_info = '<?php echo " -PHP_SAPI : " , PHP_SAPI , " -PHP_VERSION : " , phpversion() , " -ZEND_VERSION: " , zend_version() , " -PHP_OS : " , PHP_OS , " - " , php_uname() , " -INI actual : " , realpath(get_cfg_var("cfg_file_path")) , " -More .INIs : " , (function_exists(\'php_ini_scanned_files\') ? str_replace("\n","", php_ini_scanned_files()) : "** not determined **"); ?>'; - save_text($info_file, $php_info); - $info_params = array(); - settings2array($ini_overwrites, $info_params); - settings2params($info_params); - $php_info = `$php $pass_options $info_params $no_file_cache "$info_file"`; - define('TESTED_PHP_VERSION', `$php -n -r "echo PHP_VERSION;"`); - - if ($php_cgi && $php != $php_cgi) { - $php_info_cgi = `$php_cgi $pass_options $info_params $no_file_cache -q "$info_file"`; - $php_info_sep = "\n---------------------------------------------------------------------"; - $php_cgi_info = "$php_info_sep\nPHP : $php_cgi $php_info_cgi$php_info_sep"; - } else { - $php_cgi_info = ''; - } - - if ($phpdbg) { - $phpdbg_info = `$phpdbg $pass_options $info_params $no_file_cache -qrr "$info_file"`; - $php_info_sep = "\n---------------------------------------------------------------------"; - $phpdbg_info = "$php_info_sep\nPHP : $phpdbg $phpdbg_info$php_info_sep"; - } else { - $phpdbg_info = ''; - } - - if (function_exists('opcache_invalidate')) { - opcache_invalidate($info_file, true); - } - @unlink($info_file); - - // load list of enabled extensions - save_text($info_file, '<?php echo str_replace("Zend OPcache", "opcache", implode(",", get_loaded_extensions())); ?>'); - $exts_to_test = explode(',', `$php $pass_options $info_params $no_file_cache "$info_file"`); - // check for extensions that need special handling and regenerate - $info_params_ex = array( - 'session' => array('session.auto_start=0'), - 'tidy' => array('tidy.clean_output=0'), - 'zlib' => array('zlib.output_compression=Off'), - 'xdebug' => array('xdebug.mode=off','xdebug.start_with_request=default','xdebug.log_level=20'), - 'mbstring' => array('mbstring.func_overload=0'), - ); - - foreach ($info_params_ex as $ext => $ini_overwrites_ex) { - if (in_array($ext, $exts_to_test)) { - $ini_overwrites = array_merge($ini_overwrites, $ini_overwrites_ex); - } - } - - if (function_exists('opcache_invalidate')) { - opcache_invalidate($info_file, true); - } - @unlink($info_file); - - // Write test context information. - echo " -===================================================================== -PHP : $php $php_info $php_cgi_info $phpdbg_info -CWD : " . TEST_PHP_SRCDIR . " -Extra dirs : "; - foreach ($user_tests as $test_dir) { - echo "{$test_dir}\n "; - } - echo " -VALGRIND : " . ($valgrind ? $valgrind->getHeader() : 'Not used') . " -===================================================================== -"; -} - -define('PHP_QA_EMAIL', 'qa-reports@lists.php.net'); -define('QA_SUBMISSION_PAGE', 'http://qa.php.net/buildtest-process.php'); -define('QA_REPORTS_PAGE', 'http://qa.php.net/reports'); -define('TRAVIS_CI', (bool)getenv('TRAVIS')); - -function save_or_mail_results() -{ - global $sum_results, $just_save_results, $failed_test_summary, - $PHP_FAILED_TESTS, $php, $output_file; - - /* We got failed Tests, offer the user to send an e-mail to QA team, unless NO_INTERACTION is set */ - if (!getenv('NO_INTERACTION') && !TRAVIS_CI) { - $fp = fopen("php://stdin", "r+"); - if ($sum_results'FAILED' || $sum_results'BORKED' || $sum_results'WARNED' || $sum_results'LEAKED') { - echo "\nYou may have found a problem in PHP."; - } - echo "\nThis report can be automatically sent to the PHP QA team at\n"; - echo QA_REPORTS_PAGE . " and http://news.php.net/php.qa.reports\n"; - echo "This gives us a better understanding of PHP's behavior.\n"; - echo "If you don't want to send the report immediately you can choose\n"; - echo "option \"s\" to save it. You can then email it to " . PHP_QA_EMAIL . " later.\n"; - echo "Do you want to send this report now? Yns: "; - flush(); - - $user_input = fgets($fp, 10); - $just_save_results = (strtolower($user_input0) == 's'); - } - - if ($just_save_results || !getenv('NO_INTERACTION') || TRAVIS_CI) { - if ($just_save_results || TRAVIS_CI || strlen(trim($user_input)) == 0 || strtolower($user_input0) == 'y') { - /* - * Collect information about the host system for our report - * Fetch phpinfo() output so that we can see the PHP environment - * Make an archive of all the failed tests - * Send an email - */ - if ($just_save_results) { - $user_input = 's'; - } - - /* Ask the user to provide an email address, so that QA team can contact the user */ - if (TRAVIS_CI) { - $user_email = 'travis at php dot net'; - } elseif (!strncasecmp($user_input, 'y', 1) || strlen(trim($user_input)) == 0) { - echo "\nPlease enter your email address.\n(Your address will be mangled so that it will not go out on any\nmailinglist in plain text): "; - flush(); - $user_email = trim(fgets($fp, 1024)); - $user_email = str_replace("@", " at ", str_replace(".", " dot ", $user_email)); - } - - $failed_tests_data = ''; - $sep = "\n" . str_repeat('=', 80) . "\n"; - $failed_tests_data .= $failed_test_summary . "\n"; - $failed_tests_data .= get_summary(true, false) . "\n"; - - if ($sum_results'FAILED') { - foreach ($PHP_FAILED_TESTS'FAILED' as $test_info) { - $failed_tests_data .= $sep . $test_info'name' . $test_info'info'; - $failed_tests_data .= $sep . file_get_contents(realpath($test_info'output')); - $failed_tests_data .= $sep . file_get_contents(realpath($test_info'diff')); - $failed_tests_data .= $sep . "\n\n"; - } - $status = "failed"; - } else { - $status = "success"; - } - - $failed_tests_data .= "\n" . $sep . 'BUILD ENVIRONMENT' . $sep; - $failed_tests_data .= "OS:\n" . PHP_OS . " - " . php_uname() . "\n\n"; - $ldd = $autoconf = $sys_libtool = $libtool = $compiler = 'N/A'; - - if (substr(PHP_OS, 0, 3) != "WIN") { - /* If PHP_AUTOCONF is set, use it; otherwise, use 'autoconf'. */ - if (getenv('PHP_AUTOCONF')) { - $autoconf = shell_exec(getenv('PHP_AUTOCONF') . ' --version'); - } else { - $autoconf = shell_exec('autoconf --version'); - } - - /* Always use the generated libtool - Mac OSX uses 'glibtool' */ - $libtool = shell_exec(INIT_DIR . '/libtool --version'); - - /* Use shtool to find out if there is glibtool present (MacOSX) */ - $sys_libtool_path = shell_exec(__DIR__ . '/build/shtool path glibtool libtool'); - - if ($sys_libtool_path) { - $sys_libtool = shell_exec(str_replace("\n", "", $sys_libtool_path) . ' --version'); - } - - /* Try the most common flags for 'version' */ - $flags = array('-v', '-V', '--version'); - $cc_status = 0; - - foreach ($flags as $flag) { - system(getenv('CC') . " $flag >/dev/null 2>&1", $cc_status); - if ($cc_status == 0) { - $compiler = shell_exec(getenv('CC') . " $flag 2>&1"); - break; - } - } - - $ldd = shell_exec("ldd $php 2>/dev/null"); - } - - $failed_tests_data .= "Autoconf:\n$autoconf\n"; - $failed_tests_data .= "Bundled Libtool:\n$libtool\n"; - $failed_tests_data .= "System Libtool:\n$sys_libtool\n"; - $failed_tests_data .= "Compiler:\n$compiler\n"; - $failed_tests_data .= "Bison:\n" . shell_exec('bison --version 2>/dev/null') . "\n"; - $failed_tests_data .= "Libraries:\n$ldd\n"; - $failed_tests_data .= "\n"; - - if (isset($user_email)) { - $failed_tests_data .= "User's E-mail: " . $user_email . "\n\n"; - } - - $failed_tests_data .= $sep . "PHPINFO" . $sep; - $failed_tests_data .= shell_exec($php . ' -ddisplay_errors=stderr -dhtml_errors=0 -i 2> /dev/null'); - - if (($just_save_results || !mail_qa_team($failed_tests_data, $status)) && !TRAVIS_CI) { - file_put_contents($output_file, $failed_tests_data); - - if (!$just_save_results) { - echo "\nThe test script was unable to automatically send the report to PHP's QA Team\n"; - } - - echo "Please send " . $output_file . " to " . PHP_QA_EMAIL . " manually, thank you.\n"; - } elseif (!getenv('NO_INTERACTION') && !TRAVIS_CI) { - fwrite($fp, "\nThank you for helping to make PHP better.\n"); - fclose($fp); - } - } - } -} - -// Determine the tests to be run. - -$test_files = array(); -$redir_tests = array(); -$test_results = array(); -$PHP_FAILED_TESTS = array('BORKED' => array(), 'FAILED' => array(), 'WARNED' => array(), 'LEAKED' => array(), 'XFAILED' => array(), 'SLOW' => array()); - -// If parameters given assume they represent selected tests to run. -$result_tests_file = false; -$failed_tests_file = false; -$pass_option_n = false; -$pass_options = ''; - -$output_file = INIT_DIR . '/php_test_results_' . date('Ymd_Hi') . '.txt'; - -$just_save_results = false; -$valgrind = null; -$html_output = false; -$html_file = null; -$temp_source = null; -$temp_target = null; -$temp_urlbase = null; -$conf_passed = null; -$no_clean = false; -$slow_min_ms = INF; - -$cfgtypes = array('show', 'keep'); -$cfgfiles = array('skip', 'php', 'after', 'clean', 'out', 'diff', 'exp', 'mem'); -$cfg = array(); - -foreach ($cfgtypes as $type) { - $cfg$type = array(); - - foreach ($cfgfiles as $file) { - $cfg$type$file = false; - } -} - -if (getenv('TEST_PHP_ARGS')) { - - if (!isset($argc, $argv) || !$argc) { - $argv = array(__FILE__); - } - - $argv = array_merge($argv, explode(' ', getenv('TEST_PHP_ARGS'))); - $argc = count($argv); -} - -if (isset($argc) && $argc > 1) { - - for ($i = 1; $i < $argc; $i++) { - $is_switch = false; - $switch = substr($argv$i, 1, 1); - $repeat = substr($argv$i, 0, 1) == '-'; - - while ($repeat) { - - if (!$is_switch) { - $switch = substr($argv$i, 1, 1); - } - - $is_switch = true; - - if ($repeat) { - foreach ($cfgtypes as $type) { - if (strpos($switch, '--' . $type) === 0) { - foreach ($cfgfiles as $file) { - if ($switch == '--' . $type . '-' . $file) { - $cfg$type$file = true; - $is_switch = false; - break; - } - } - } - } - } - - if (!$is_switch) { - $is_switch = true; - break; - } - - $repeat = false; - - switch ($switch) { - case 'r': - case 'l': - $test_list = file($argv++$i); - if ($test_list) { - foreach ($test_list as $test) { - $matches = array(); - if (preg_match('/^#.*\(.*)\\:\s+(.*)$/', $test, $matches)) { - $redir_tests = array($matches1, $matches2); - } else if (strlen($test)) { - $test_files = trim($test); - } - } - } - if ($switch != 'l') { - break; - } - $i--; - // break left intentionally - case 'w': - $failed_tests_file = fopen($argv++$i, 'w+t'); - break; - case 'a': - $failed_tests_file = fopen($argv++$i, 'a+t'); - break; - case 'W': - $result_tests_file = fopen($argv++$i, 'w+t'); - break; - case 'c': - $conf_passed = $argv++$i; - break; - case 'd': - $ini_overwrites = $argv++$i; - break; - case 'g': - $SHOW_ONLY_GROUPS = explode(",", $argv++$i); - break; - //case 'h' - case '--keep-all': - foreach ($cfgfiles as $file) { - $cfg'keep'$file = true; - } - break; - //case 'l' - case 'm': - $valgrind = new RuntestsValgrind($environment); - break; - case 'n': - if (!$pass_option_n) { - $pass_options .= ' -n'; - } - $pass_option_n = true; - break; - case 'e': - $pass_options .= ' -e'; - break; - case '--no-clean': - $no_clean = true; - break; - case 'p': - $php = $argv++$i; - putenv("TEST_PHP_EXECUTABLE=$php"); - $environment'TEST_PHP_EXECUTABLE' = $php; - break; - case 'P': - if (constant('PHP_BINARY')) { - $php = PHP_BINARY; - } else { - break; - } - putenv("TEST_PHP_EXECUTABLE=$php"); - $environment'TEST_PHP_EXECUTABLE' = $php; - break; - case 'q': - putenv('NO_INTERACTION=1'); - break; - //case 'r' - case 's': - $output_file = $argv++$i; - $just_save_results = true; - break; - case '--set-timeout': - $environment'TEST_TIMEOUT' = $argv++$i; - break; - case '--show-all': - foreach ($cfgfiles as $file) { - $cfg'show'$file = true; - } - break; - case '--show-slow': - $slow_min_ms = $argv++$i; - break; - case '--temp-source': - $temp_source = $argv++$i; - break; - case '--temp-target': - $temp_target = $argv++$i; - if ($temp_urlbase) { - $temp_urlbase = $temp_target; - } - break; - case '--temp-urlbase': - $temp_urlbase = $argv++$i; - break; - case 'v': - case '--verbose': - $DETAILED = true; - break; - case 'x': - $environment'SKIP_SLOW_TESTS' = 1; - break; - case '--offline': - $environment'SKIP_ONLINE_TESTS' = 1; - break; - //case 'w' - case '-': - // repeat check with full switch - $switch = $argv$i; - if ($switch != '-') { - $repeat = true; - } - break; - case '--html': - $html_file = fopen($argv++$i, 'wt'); - $html_output = is_resource($html_file); - break; - case '--version': - echo '$Id: 7c135b2dd493cb5e6f7a785a4ee452a8dbfc4380 $' . "\n"; - exit(1); - - default: - echo "Illegal switch '$switch' specified!\n"; - case 'h': - case '-help': - case '--help': - echo <<<HELP -Synopsis: - php run-tests.php options files directories - -Options: - -l <file> Read the testfiles to be executed from <file>. After the test - has finished all failed tests are written to the same <file>. - If the list is empty and no further test is specified then - all tests are executed (same as: -r <file> -w <file>). - - -r <file> Read the testfiles to be executed from <file>. - - -w <file> Write a list of all failed tests to <file>. - - -a <file> Same as -w but append rather then truncating <file>. - - -W <file> Write a list of all tests and their result status to <file>. - - -c <file> Look for php.ini in directory <file> or use <file> as ini. - - -n Pass -n option to the php binary (Do not use a php.ini). - - -d foo=bar Pass -d option to the php binary (Define INI entry foo - with value 'bar'). - - -g Comma separated list of groups to show during test run - (possible values: PASS, FAIL, XFAIL, SKIP, BORK, WARN, LEAK, REDIRECT). - - -m Test for memory leaks with Valgrind. - - -p <php> Specify PHP executable to run. - - -P Use PHP_BINARY as PHP executable to run. - - -q Quiet, no user interaction (same as environment NO_INTERACTION). - - -s <file> Write output to <file>. - - -x Sets 'SKIP_SLOW_TESTS' environmental variable. - - --offline Sets 'SKIP_ONLINE_TESTS' environmental variable. - - --verbose - -v Verbose mode. - - --help - -h This Help. - - --html <file> Generate HTML output. - - --temp-source <sdir> --temp-target <tdir> --temp-urlbase <url> - Write temporary files to <tdir> by replacing <sdir> from the - filenames to generate with <tdir>. If --html is being used and - <url> given then the generated links are relative and prefixed - with the given url. In general you want to make <sdir> the path - to your source files and <tdir> some patch in your web page - hierarchy with <url> pointing to <tdir>. - - --keep-all|php|skip|clean|after - Do not delete 'all' files, 'php' test file, 'skip', 'clean', - or 'after' file. - - --set-timeout n - Set timeout for individual tests, where n is the number of - seconds. The default value is 60 seconds, or 300 seconds when - testing for memory leaks. - - --show-all|php|skip|clean|after||exp|diff|out|mem - Show 'all' files, 'php' test file, 'skip', 'after', or 'clean' file. - You can also use this to show the output 'out', the expected result - 'exp', the difference between them 'diff' or the valgrind log - 'mem'. The result types get written independent of the log format, - however 'diff' only exists when a test fails. - - --show-slow n - Show all tests that took longer than n milliseconds to run. - - --no-clean Do not execute clean section if any. - -HELP; - exit(1); - } - } - - if (!$is_switch) { - $testfile = realpath($argv$i); - - if (!$testfile && strpos($argv$i, '*') !== false && function_exists('glob')) { - - if (substr($argv$i, -5) == '.phpt') { - $pattern_match = glob($argv$i); - } else if (preg_match("/\*$/", $argv$i)) { - $pattern_match = glob($argv$i . '.phpt'); - } else { - die('Cannot find test file "' . $argv$i . '".' . PHP_EOL); - } - - if (is_array($pattern_match)) { - $test_files = array_merge($test_files, $pattern_match); - } - - } else if (is_dir($testfile)) { - find_files($testfile); - } else if (substr($testfile, -5) == '.phpt') { - $test_files = $testfile; - } else { - die('Cannot find test file "' . $argv$i . '".' . PHP_EOL); - } - } - } - - if ($conf_passed && strlen($conf_passed)) { - if (substr(PHP_OS, 0, 3) == "WIN") { - $pass_options .= " -c " . escapeshellarg($conf_passed); - } else { - $pass_options .= " -c '$conf_passed'"; - } - } - - $test_files = array_unique($test_files); - $test_files = array_merge($test_files, $redir_tests); - - // Run selected tests. - $test_cnt = count($test_files); - - if ($test_cnt) { - putenv('NO_INTERACTION=1'); - verify_config(); - write_information(); - usort($test_files, "test_sort"); - $start_time = time(); - - if (!$html_output) { - echo "Running selected tests.\n"; - } else { - show_start($start_time); - } - - $test_idx = 0; - run_all_tests($test_files, $environment); - $end_time = time(); - - if ($html_output) { - show_end($end_time); - } - - if ($failed_tests_file) { - fclose($failed_tests_file); - } - - if ($result_tests_file) { - fclose($result_tests_file); - } - - compute_summary(); - if ($html_output) { - fwrite($html_file, "<hr/>\n" . get_summary(false, true)); - } - echo "====================================================================="; - echo get_summary(false, false); - - if ($html_output) { - fclose($html_file); - } - - if ($output_file != '' && $just_save_results) { - save_or_mail_results(); - } - - junit_save_xml(); - - if (getenv('REPORT_EXIT_STATUS') !== '0' && - getenv('REPORT_EXIT_STATUS') !== 'no' && ($sum_results'FAILED' || $sum_results'BORKED' || $sum_results'LEAKED')) { - exit(1); - } - - exit(0); - } -} - -verify_config(); -write_information(); - -// Compile a list of all test files (*.phpt). -$test_files = array(); -$exts_tested = count($exts_to_test); -$exts_skipped = 0; -$ignored_by_ext = 0; -sort($exts_to_test); -$test_dirs = array(); -$optionals = array('tests', 'ext', 'Zend'); - -foreach ($optionals as $dir) { - if (is_dir($dir)) { - $test_dirs = $dir; - } -} - -// Convert extension names to lowercase -foreach ($exts_to_test as $key => $val) { - $exts_to_test$key = strtolower($val); -} - -foreach ($test_dirs as $dir) { - find_files(TEST_PHP_SRCDIR . "/{$dir}", $dir == 'ext'); -} - -foreach ($user_tests as $dir) { - find_files($dir, $dir == 'ext'); -} - -function find_files($dir, $is_ext_dir = false, $ignore = false) -{ - global $test_files, $exts_to_test, $ignored_by_ext, $exts_skipped; - - $o = opendir($dir) or error("cannot open directory: $dir"); - - while (($name = readdir($o)) !== false) { - - if (is_dir("{$dir}/{$name}") && !in_array($name, array('.', '..', '.svn'))) { - $skip_ext = ($is_ext_dir && !in_array(strtolower($name), $exts_to_test)); - if ($skip_ext) { - $exts_skipped++; - } - find_files("{$dir}/{$name}", false, $ignore || $skip_ext); - } - - // Cleanup any left-over tmp files from last run. - if (substr($name, -4) == '.tmp') { - @unlink("$dir/$name"); - continue; - } - - // Otherwise we're only interested in *.phpt files. - if (substr($name, -5) == '.phpt') { - if ($ignore) { - $ignored_by_ext++; - } else { - $testfile = realpath("{$dir}/{$name}"); - $test_files = $testfile; - } - } - } - - closedir($o); -} - -function test_name($name) -{ - if (is_array($name)) { - return $name0 . ':' . $name1; - } else { - return $name; - } -} - -function test_sort($a, $b) -{ - $a = test_name($a); - $b = test_name($b); - - $ta = strpos($a, TEST_PHP_SRCDIR . "/tests") === 0 ? 1 + (strpos($a, TEST_PHP_SRCDIR . "/tests/run-test") === 0 ? 1 : 0) : 0; - $tb = strpos($b, TEST_PHP_SRCDIR . "/tests") === 0 ? 1 + (strpos($b, TEST_PHP_SRCDIR . "/tests/run-test") === 0 ? 1 : 0) : 0; - - if ($ta == $tb) { - return strcmp($a, $b); - } else { - return $tb - $ta; - } -} - -$test_files = array_unique($test_files); -usort($test_files, "test_sort"); - -$start_time = time(); -show_start($start_time); - -$test_cnt = count($test_files); -$test_idx = 0; -run_all_tests($test_files, $environment); -$end_time = time(); - -if ($failed_tests_file) { - fclose($failed_tests_file); -} - -if ($result_tests_file) { - fclose($result_tests_file); -} - -// Summarize results - -if (0 == count($test_results)) { - echo "No tests were run.\n"; - return; -} - -compute_summary(); - -show_end($end_time); -show_summary(); - -if ($html_output) { - fclose($html_file); -} - -save_or_mail_results(); - -junit_save_xml(); -if (getenv('REPORT_EXIT_STATUS') !== '0' && - getenv('REPORT_EXIT_STATUS') !== 'no' && ($sum_results'FAILED' || $sum_results'LEAKED')) { - exit(1); -} -exit(0); - -// -// Send Email to QA Team -// - -function mail_qa_team($data, $status = false) -{ - $url_bits = parse_url(QA_SUBMISSION_PAGE); - - if ($proxy = getenv('http_proxy')) { - $proxy = parse_url($proxy); - $path = $url_bits'host' . $url_bits'path'; - $host = $proxy'host'; - if (empty($proxy'port')) { - $proxy'port' = 80; - } - $port = $proxy'port'; - } else { - $path = $url_bits'path'; - $host = $url_bits'host'; - $port = empty($url_bits'port') ? 80 : $port = $url_bits'port'; - } - - $data = "php_test_data=" . urlencode(base64_encode(str_replace("\00", '0x0', $data))); - $data_length = strlen($data); - - $fs = fsockopen($host, $port, $errno, $errstr, 10); - - if (!$fs) { - return false; - } - - $php_version = urlencode(TESTED_PHP_VERSION); - - echo "\nPosting to " . QA_SUBMISSION_PAGE . "\n"; - fwrite($fs, "POST " . $path . "?status=$status&version=$php_version HTTP/1.1\r\n"); - fwrite($fs, "Host: " . $host . "\r\n"); - fwrite($fs, "User-Agent: QA Browser 0.1\r\n"); - fwrite($fs, "Content-Type: application/x-www-form-urlencoded\r\n"); - fwrite($fs, "Content-Length: " . $data_length . "\r\n\r\n"); - fwrite($fs, $data); - fwrite($fs, "\r\n\r\n"); - fclose($fs); - - return 1; -} - - -// -// Write the given text to a temporary file, and return the filename. -// - -function save_text($filename, $text, $filename_copy = null) -{ - global $DETAILED; - - if ($filename_copy && $filename_copy != $filename) { - if (file_put_contents($filename_copy, $text) === false) { - error("Cannot open file '" . $filename_copy . "' (save_text)"); - } - } - - if (file_put_contents($filename, $text) === false) { - error("Cannot open file '" . $filename . "' (save_text)"); - } - - if (1 < $DETAILED) echo " -FILE $filename {{{ -$text -}}} -"; -} - -// -// Write an error in a format recognizable to Emacs or MSVC. -// - -function error_report($testname, $logname, $tested) -{ - $testname = realpath($testname); - $logname = realpath($logname); - - switch (strtoupper(getenv('TEST_PHP_ERROR_STYLE'))) { - case 'MSVC': - echo $testname . "(1) : $tested\n"; - echo $logname . "(1) : $tested\n"; - break; - case 'EMACS': - echo $testname . ":1: $tested\n"; - echo $logname . ":1: $tested\n"; - break; - } -} - -function system_with_timeout($commandline, $env = null, $stdin = null, $captureStdIn = true, $captureStdOut = true, $captureStdErr = true) -{ - global $valgrind; - - $data = ''; - - $bin_env = array(); - foreach ((array)$env as $key => $value) { - $bin_env$key = $value; - } - - $descriptorspec = array(); - if ($captureStdIn) { - $descriptorspec0 = array('pipe', 'r'); - } - if ($captureStdOut) { - $descriptorspec1 = array('pipe', 'w'); - } - if ($captureStdErr) { - $descriptorspec2 = array('pipe', 'w'); - } - $proc = proc_open($commandline, $descriptorspec, $pipes, TEST_PHP_SRCDIR, $bin_env, array('suppress_errors' => true)); - - if (!$proc) { - return false; - } - - if ($captureStdIn) { - if (!is_null($stdin)) { - fwrite($pipes0, $stdin); - } - fclose($pipes0); - unset($pipes0); - } - - $timeout = $valgrind ? 300 : ($env'TEST_TIMEOUT' ?? 10); - - while (true) { - /* hide errors from interrupted syscalls */ - $r = $pipes; - $w = null; - $e = null; - - $n = @stream_select($r, $w, $e, $timeout); - - if ($n === false) { - break; - } else if ($n === 0) { - /* timed out */ - $data .= "\n ** ERROR: process timed out **\n"; - proc_terminate($proc, 9); - return $data; - } else if ($n > 0) { - if ($captureStdOut) { - $line = fread($pipes1, 8192); - } elseif ($captureStdErr) { - $line = fread($pipes2, 8192); - } else { - $line = ''; - } - if (strlen($line) == 0) { - /* EOF */ - break; - } - $data .= $line; - } - } - - $stat = proc_get_status($proc); - - if ($stat'signaled') { - $data .= "\nTermsig=" . $stat'stopsig' . "\n"; - } - if ($stat"exitcode" > 128 && $stat"exitcode" < 160) { - $data .= "\nTermsig=" . ($stat"exitcode" - 128) . "\n"; - } - - proc_close($proc); - return $data; -} - -function run_all_tests($test_files, $env, $redir_tested = null) -{ - global $test_results, $failed_tests_file, $result_tests_file, $php, $test_idx; - - foreach ($test_files as $name) { - - if (is_array($name)) { - $index = "# $name1: $name0"; - - if ($redir_tested) { - $name = $name0; - } - } else if ($redir_tested) { - $index = "# $redir_tested: $name"; - } else { - $index = $name; - } - $test_idx++; - $result = run_test($php, $name, $env); - - if (!is_array($name) && $result != 'REDIR') { - $test_results$index = $result; - if ($failed_tests_file && ($result == 'XFAILED' || $result == 'FAILED' || $result == 'WARNED' || $result == 'LEAKED')) { - fwrite($failed_tests_file, "$index\n"); - } - if ($result_tests_file) { - fwrite($result_tests_file, "$result\t$index\n"); - } - } - } -} - -// -// Show file or result block -// -function show_file_block($file, $block, $section = null) -{ - global $cfg; - - if ($cfg'show'$file) { - - if (is_null($section)) { - $section = strtoupper($file); - } - - echo "\n========" . $section . "========\n"; - echo rtrim($block); - echo "\n========DONE========\n"; - } -} - -// -// Run an individual test case. -// -function run_test($php, $file, $env) -{ - global $log_format, $ini_overwrites, $PHP_FAILED_TESTS; - global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx; - global $valgrind, $temp_source, $temp_target, $cfg, $environment; - global $no_clean; - global $SHOW_ONLY_GROUPS; - global $no_file_cache; - global $slow_min_ms; - $temp_filenames = null; - $org_file = $file; - - if (isset($env'TEST_PHP_CGI_EXECUTABLE')) { - $php_cgi = $env'TEST_PHP_CGI_EXECUTABLE'; - } - - if (isset($env'TEST_PHPDBG_EXECUTABLE')) { - $phpdbg = $env'TEST_PHPDBG_EXECUTABLE'; - } - - if (is_array($file)) { - $file = $file0; - } - - if ($DETAILED) echo " -================= -TEST $file -"; - - // Load the sections of the test file. - $section_text = array('TEST' => ''); - - $fp = fopen($file, "rb") or error("Cannot open test file: $file"); - - $bork_info = null; - - if (!feof($fp)) { - $line = fgets($fp); - - if ($line === false) { - $bork_info = "cannot read test"; - } - } else { - $bork_info = "empty test $file"; - } - if ($bork_info === null && strncmp('--TEST--', $line, 8)) { - $bork_info = "tests must start with --TEST-- $file"; - } - - $section = 'TEST'; - $secfile = false; - $secdone = false; - - while (!feof($fp)) { - $line = fgets($fp); - - if ($line === false) { - break; - } - - // Match the beginning of a section. - if (preg_match('/^--(_A-Z+)--/', $line, $r)) { - $section = (string)$r1; - - if (isset($section_text$section) && $section_text$section) { - $bork_info = "duplicated $section section"; - } - - // check for unknown sections - if (!in_array($section, array( - 'EXPECT', 'EXPECTF', 'EXPECTREGEX', 'EXPECTREGEX_EXTERNAL', 'EXPECT_EXTERNAL', 'EXPECTF_EXTERNAL', 'EXPECTHEADERS', - 'POST', 'POST_RAW', 'GZIP_POST', 'DEFLATE_POST', 'PUT', 'GET', 'COOKIE', 'ARGS', - 'FILE', 'FILEEOF', 'FILE_EXTERNAL', 'REDIRECTTEST', - 'CAPTURE_STDIO', 'STDIN', 'CGI', 'PHPDBG', - 'INI', 'ENV', 'EXTENSIONS', - 'SKIPIF', 'XFAIL', 'CLEAN', 'AFTER', - 'CREDITS', 'DESCRIPTION', - ))) { - $bork_info = 'Unknown section "' . $section . '"'; - } - - $section_text$section = ''; - $secfile = $section == 'FILE' || $section == 'FILEEOF' || $section == 'FILE_EXTERNAL'; - $secdone = false; - continue; - } - - // Add to the section text. - if (!$secdone) { - $section_text$section .= $line; - } - - // End of actual test? - if ($secfile && preg_match('/^===DONE===\s*$/', $line)) { - $secdone = true; - } - } - - // the redirect section allows a set of tests to be reused outside of - // a given test dir - if ($bork_info === null) { - if (isset($section_text'REDIRECTTEST')) { - - if ($IN_REDIRECT) { - $bork_info = "Can't redirect a test from within a redirected test"; - } - - } else { - - if (!isset($section_text'PHPDBG') && isset($section_text'FILE') + isset($section_text'FILEEOF') + isset($section_text'FILE_EXTERNAL') != 1) { - $bork_info = "missing section --FILE--"; - } - - if (isset($section_text'FILEEOF')) { - $section_text'FILE' = preg_replace("/\r\n+$/", '', $section_text'FILEEOF'); - unset($section_text'FILEEOF'); - } - - foreach (array('FILE', 'EXPECT', 'EXPECTF', 'EXPECTREGEX') as $prefix) { - $key = $prefix . '_EXTERNAL'; - - if (isset($section_text$key)) { - // don't allow tests to retrieve files from anywhere but this subdirectory - $section_text$key = dirname($file) . '/' . trim(str_replace('..', '', $section_text$key)); - - if (file_exists($section_text$key)) { - $section_text$prefix = file_get_contents($section_text$key); - unset($section_text$key); - } else { - $bork_info = "could not load --" . $key . "-- " . dirname($file) . '/' . trim($section_text$key); - } - } - } - - if ((isset($section_text'EXPECT') + isset($section_text'EXPECTF') + isset($section_text'EXPECTREGEX')) != 1) { - $bork_info = "missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--"; - } - } - } - fclose($fp); - - $shortname = str_replace(TEST_PHP_SRCDIR . '/', '', $file); - $tested_file = $shortname; - - if ($bork_info !== null) { - show_result("BORK", $bork_info, $tested_file); - $PHP_FAILED_TESTS'BORKED' = array( - 'name' => $file, - 'test_name' => '', - 'output' => '', - 'diff' => '', - 'info' => "$bork_info $file", - ); - - junit_mark_test_as('BORK', $shortname, $tested_file, 0, $bork_info); - return 'BORKED'; - } - - if (isset($section_text'CAPTURE_STDIO')) { - $captureStdIn = stripos($section_text'CAPTURE_STDIO', 'STDIN') !== false; - $captureStdOut = stripos($section_text'CAPTURE_STDIO', 'STDOUT') !== false; - $captureStdErr = stripos($section_text'CAPTURE_STDIO', 'STDERR') !== false; - } else { - $captureStdIn = true; - $captureStdOut = true; - $captureStdErr = true; - } - if ($captureStdOut && $captureStdErr) { - $cmdRedirect = ' 2>&1'; - } else { - $cmdRedirect = ''; - } - - $tested = trim($section_text'TEST'); - - /* For GET/POST/PUT tests, check if cgi sapi is available and if it is, use it. */ - if (array_key_exists('CGI', $section_text) || !empty($section_text'GET') || !empty($section_text'POST') || !empty($section_text'GZIP_POST') || !empty($section_text'DEFLATE_POST') || !empty($section_text'POST_RAW') || !empty($section_text'PUT') || !empty($section_text'COOKIE') || !empty($section_text'EXPECTHEADERS')) { - if (isset($php_cgi)) { - $php = $php_cgi . ' -C '; - } else if (!strncasecmp(PHP_OS, "win", 3) && file_exists(dirname($php) . "/php-cgi.exe")) { - $php = realpath(dirname($php) . "/php-cgi.exe") . ' -C '; - } else { - if (file_exists(dirname($php) . "/../../sapi/cgi/php-cgi")) { - $php = realpath(dirname($php) . "/../../sapi/cgi/php-cgi") . ' -C '; - } else if (file_exists("./sapi/cgi/php-cgi")) { - $php = realpath("./sapi/cgi/php-cgi") . ' -C '; - } else if (file_exists(dirname($php) . "/php-cgi")) { - $php = realpath(dirname($php) . "/php-cgi") . ' -C '; - } else { - show_result('SKIP', $tested, $tested_file, "reason: CGI not available"); - - junit_init_suite(junit_get_suitename_for($shortname)); - junit_mark_test_as('SKIP', $shortname, $tested, 0, 'CGI not available'); - return 'SKIPPED'; - } - } - $uses_cgi = true; - } - - /* For phpdbg tests, check if phpdbg sapi is available and if it is, use it. */ - $extra_options = ''; - if (array_key_exists('PHPDBG', $section_text)) { - if (!isset($section_text'STDIN')) { - $section_text'STDIN' = $section_text'PHPDBG' . "\n"; - } - - if (isset($phpdbg)) { - $php = $phpdbg . ' -qIb'; - - // Additional phpdbg command line options for sections that need to - // be run straight away. For example, EXTENSIONS, SKIPIF, CLEAN. - $extra_options = '-rr'; - } else { - show_result('SKIP', $tested, $tested_file, "reason: phpdbg not available"); - - junit_init_suite(junit_get_suitename_for($shortname)); - junit_mark_test_as('SKIP', $shortname, $tested, 0, 'phpdbg not available'); - return 'SKIPPED'; - } - } - - if (!$SHOW_ONLY_GROUPS) { - show_test($test_idx, $shortname); - } - - if (is_array($IN_REDIRECT)) { - $temp_dir = $test_dir = $IN_REDIRECT'dir'; - } else { - $temp_dir = $test_dir = realpath(dirname($file)); - } - - if ($temp_source && $temp_target) { - $temp_dir = str_replace($temp_source, $temp_target, $temp_dir); - } - - $main_file_name = basename($file, 'phpt'); - - $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'diff'; - $log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'log'; - $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'exp'; - $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'out'; - $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'mem'; - $sh_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'sh'; - $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; - $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; - $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; - $test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; - $temp_after = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'after.php'; - $test_after = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'after.php'; - $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; - $test_clean = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; - $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('/phpt.'); - $tmp_relative_file = str_replace(__DIR__ . DIRECTORY_SEPARATOR, '', $test_file) . 't'; - - if ($temp_source && $temp_target) { - $temp_skipif .= 's'; - $temp_file .= 's'; - $temp_clean .= 's'; - $copy_file = $temp_dir . DIRECTORY_SEPARATOR . basename(is_array($file) ? $file1 : $file) . '.phps'; - - if (!is_dir(dirname($copy_file))) { - mkdir(dirname($copy_file), 0777, true) or error("Cannot create output directory - " . dirname($copy_file)); - } - - if (isset($section_text'FILE')) { - save_text($copy_file, $section_text'FILE'); - } - - $temp_filenames = array( - 'file' => $copy_file, - 'diff' => $diff_filename, - 'log' => $log_filename, - 'exp' => $exp_filename, - 'out' => $output_filename, - 'mem' => $memcheck_filename, - 'sh' => $sh_filename, - 'php' => $temp_file, - 'skip' => $temp_skipif, - 'after' => $temp_after, - 'clean' => $temp_clean, - ); - } - - if (is_array($IN_REDIRECT)) { - $tested = $IN_REDIRECT'prefix' . ' ' . trim($section_text'TEST'); - $tested_file = $tmp_relative_file; - } - - // unlink old test results - @unlink($diff_filename); - @unlink($log_filename); - @unlink($exp_filename); - @unlink($output_filename); - @unlink($memcheck_filename); - @unlink($sh_filename); - @unlink($temp_file); - @unlink($test_file); - @unlink($temp_skipif); - @unlink($test_skipif); - @unlink($tmp_post); - @unlink($temp_after); - @unlink($test_after); - @unlink($temp_clean); - @unlink($test_clean); - - // Reset environment from any previous test. - $env'REDIRECT_STATUS' = ''; - $env'QUERY_STRING' = ''; - $env'PATH_TRANSLATED' = ''; - $env'SCRIPT_FILENAME' = ''; - $env'REQUEST_METHOD' = ''; - $env'CONTENT_TYPE' = ''; - $env'CONTENT_LENGTH' = ''; - $env'TZ' = ''; - - if (!empty($section_text'ENV')) { - - foreach (explode("\n", trim($section_text'ENV')) as $e) { - $e = explode('=', trim($e), 2); - - if (!empty($e0) && isset($e1)) { - $env$e0 = $e1; - } - } - } - - // Default ini settings - $ini_settings = array(); - - if (getenv('OPCACHE') !== false) { - if (getenv('OPCACHE') == 'yes') { - $ini_settings'opcache.enable' = 1; - $ini_settings'opcache.enable_cli' = 1; - $ini_settings'opcache.optimization_level' = -1; - } else { - $ini_settings'opcache.enable' = 0; - $ini_settings'opcache.enable_cli' = 0; - $ini_settings'opcache.optimization_level' = 0; - } - } - - // additional ini overwrites - //$ini_overwrites = 'setting=value'; - settings2array($ini_overwrites, $ini_settings); - - // Any special ini settings - // these may overwrite the test defaults... - if (array_key_exists('INI', $section_text)) { - if (strpos($section_text'INI', '{PWD}') !== false) { - $section_text'INI' = str_replace('{PWD}', dirname($file), $section_text'INI'); - } - if (strpos($section_text'INI', '{RUNID}') !== false) { - $section_text'INI' = str_replace('{RUNID}', getenv('UNIQ_RUN_ID'), $section_text'INI'); - } - if (strpos($section_text'INI', '{TMPDIR}') !== false) { - $section_text'INI' = str_replace('{TMPDIR}', sys_get_temp_dir(), $section_text'INI'); - } - - settings2array(preg_split("/\n\r+/", $section_text'INI'), $ini_settings); - } - - settings2params($ini_settings); - - // Check if test should be skipped. - $info = ''; - $warn = false; - - if (array_key_exists('SKIPIF', $section_text)) { - - if (trim($section_text'SKIPIF')) { - show_file_block('skip', $section_text'SKIPIF'); - save_text($test_skipif, $section_text'SKIPIF', $temp_skipif); - $extra = substr(PHP_OS, 0, 3) !== "WIN" ? - "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; - - if ($valgrind) { - $env'USE_ZEND_ALLOC' = '0'; - $env'ZEND_DONT_UNLOAD_MODULES' = 1; - } else { - $env'USE_ZEND_ALLOC' = '1'; - $env'ZEND_DONT_UNLOAD_MODULES' = 0; - } - if (!array_key_exists('XDEBUG_MODE', $env)) { - $env'XDEBUG_MODE' = ""; - } - - junit_start_timer($shortname); - - /* Remove auto prepend and append settings for SKIPIF */ - $skipif_ini_settings = $ini_settings; - $skipif_ini_settings = preg_replace( '@-d \"auto_prepend_file=.*?\" @', '', $skipif_ini_settings ); - $skipif_ini_settings = preg_replace( '@-d \"auto_append_file=.*?\" @', '', $skipif_ini_settings ); - $skipif_ini_settings = preg_replace( '@-d \"xdebug\.log=.*?\" @', '', $skipif_ini_settings ); - $skipif_ini_settings .= " -d track_errors=0 -d xdebug.mode=off"; - $output = system_with_timeout("$extra $php $pass_options $extra_options -q $skipif_ini_settings $no_file_cache -d display_errors=0 \"$test_skipif\"", $env); - - junit_finish_timer($shortname); - - if (!$cfg'keep''skip') { - @unlink($test_skipif); - } - - if (!strncasecmp('skip', ltrim($output), 4)) { - - if (preg_match('/^\s*skip\s*(.+)\s*/i', $output, $m)) { - show_result('SKIP', $tested, $tested_file, "reason: $m1", $temp_filenames); - } else { - show_result('SKIP', $tested, $tested_file, '', $temp_filenames); - } - - if (!$cfg'keep''skip') { - @unlink($test_skipif); - } - - $message = !empty($m1) ? $m1 : ''; - junit_mark_test_as('SKIP', $shortname, $tested, null, $message); - return 'SKIPPED'; - } - - if (!strncasecmp('info', ltrim($output), 4)) { - if (preg_match('/^\s*info\s*(.+)\s*/i', $output, $m)) { - $info = " (info: $m1)"; - } - } - - if (!strncasecmp('warn', ltrim($output), 4)) { - if (preg_match('/^\s*warn\s*(.+)\s*/i', $output, $m)) { - $warn = true; /* only if there is a reason */ - $info = " (warn: $m1)"; - } - } - - if (!strncasecmp('xfail', ltrim($output), 5)) { - // Pretend we have an XFAIL section - $section_text'XFAIL' = trim(substr(ltrim($output), 5)); - } - } - } - - if (!extension_loaded("zlib") - && (array_key_exists("GZIP_POST", $section_text) - || array_key_exists("DEFLATE_POST", $section_text))) { - $message = "ext/zlib required"; - show_result('SKIP', $tested, $tested_file, "reason: $message", $temp_filenames); - junit_mark_test_as('SKIP', $shortname, $tested, null, $message); - return 'SKIPPED'; - } - - if (isset($section_text'REDIRECTTEST')) { - $test_files = array(); - - $IN_REDIRECT = eval($section_text'REDIRECTTEST'); - $IN_REDIRECT'via' = "via $shortname\n\t"; - $IN_REDIRECT'dir' = realpath(dirname($file)); - $IN_REDIRECT'prefix' = trim($section_text'TEST'); - - if (!empty($IN_REDIRECT'TESTS')) { - - if (is_array($org_file)) { - $test_files = $org_file1; - } else { - $GLOBALS'test_files' = $test_files; - find_files($IN_REDIRECT'TESTS'); - - foreach ($GLOBALS'test_files' as $f) { - $test_files = array($f, $file); - } - } - $test_cnt += @count($test_files) - 1; - $test_idx--; - - show_redirect_start($IN_REDIRECT'TESTS', $tested, $tested_file); - - // set up environment - $redirenv = array_merge($environment, $IN_REDIRECT'ENV'); - $redirenv'REDIR_TEST_DIR' = realpath($IN_REDIRECT'TESTS') . DIRECTORY_SEPARATOR; - - usort($test_files, "test_sort"); - run_all_tests($test_files, $redirenv, $tested); - - show_redirect_ends($IN_REDIRECT'TESTS', $tested, $tested_file); - - // a redirected test never fails - $IN_REDIRECT = false; - - junit_mark_test_as('PASS', $shortname, $tested); - return 'REDIR'; - - } else { - - $bork_info = "Redirect info must contain exactly one TEST string to be used as redirect directory."; - show_result("BORK", $bork_info, '', $temp_filenames); - $PHP_FAILED_TESTS'BORKED' = array( - 'name' => $file, - 'test_name' => '', - 'output' => '', - 'diff' => '', - 'info' => "$bork_info $file", - ); - } - } - - if (is_array($org_file) || isset($section_text'REDIRECTTEST')) { - - if (is_array($org_file)) { - $file = $org_file0; - } - - $bork_info = "Redirected test did not contain redirection info"; - show_result("BORK", $bork_info, '', $temp_filenames); - $PHP_FAILED_TESTS'BORKED' = array( - 'name' => $file, - 'test_name' => '', - 'output' => '', - 'diff' => '', - 'info' => "$bork_info $file", - ); - - junit_mark_test_as('BORK', $shortname, $tested, null, $bork_info); - - return 'BORKED'; - } - - // We've satisfied the preconditions - run the test! - if (isset($section_text'FILE')) { - show_file_block('php', $section_text'FILE', 'TEST'); - save_text($test_file, $section_text'FILE', $temp_file); - } else { - $test_file = $temp_file = ""; - } - - if (array_key_exists('GET', $section_text)) { - $query_string = trim($section_text'GET'); - } else { - $query_string = ''; - } - - $env'REDIRECT_STATUS' = '1'; - if (empty($env'QUERY_STRING')) { - $env'QUERY_STRING' = $query_string; - } - if (empty($env'PATH_TRANSLATED')) { - $env'PATH_TRANSLATED' = $test_file; - } - if (empty($env'SCRIPT_FILENAME')) { - $env'SCRIPT_FILENAME' = $test_file; - } - - if (array_key_exists('COOKIE', $section_text)) { - $env'HTTP_COOKIE' = trim($section_text'COOKIE'); - } else { - $env'HTTP_COOKIE' = ''; - } - - $args = isset($section_text'ARGS') ? ' -- ' . $section_text'ARGS' : ''; - - if (array_key_exists('POST_RAW', $section_text) && !empty($section_text'POST_RAW')) { - - $post = trim($section_text'POST_RAW'); - $raw_lines = explode("\n", $post); - - $request = ''; - $started = false; - - foreach ($raw_lines as $line) { - - if (empty($env'CONTENT_TYPE') && preg_match('/^Content-Type:(.*)/i', $line, $res)) { - $env'CONTENT_TYPE' = trim(str_replace("\r", '', $res1)); - continue; - } - - if ($started) { - $request .= "\n"; - } - - $started = true; - $request .= $line; - } - - $env'CONTENT_LENGTH' = strlen($request); - $env'REQUEST_METHOD' = 'POST'; - - if (empty($request)) { - junit_mark_test_as('BORK', $shortname, $tested, null, 'empty $request'); - return 'BORKED'; - } - - save_text($tmp_post, $request); - $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\""; - - } elseif (array_key_exists('PUT', $section_text) && !empty($section_text'PUT')) { - - $post = trim($section_text'PUT'); - $raw_lines = explode("\n", $post); - - $request = ''; - $started = false; - - foreach ($raw_lines as $line) { - - if (empty($env'CONTENT_TYPE') && preg_match('/^Content-Type:(.*)/i', $line, $res)) { - $env'CONTENT_TYPE' = trim(str_replace("\r", '', $res1)); - continue; - } - - if ($started) { - $request .= "\n"; - } - - $started = true; - $request .= $line; - } - - $env'CONTENT_LENGTH' = strlen($request); - $env'REQUEST_METHOD' = 'PUT'; - - if (empty($request)) { - junit_mark_test_as('BORK', $shortname, $tested, null, 'empty $request'); - return 'BORKED'; - } - - save_text($tmp_post, $request); - $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\""; - - } else if (array_key_exists('POST', $section_text) && !empty($section_text'POST')) { - - $post = trim($section_text'POST'); - $content_length = strlen($post); - save_text($tmp_post, $post); - - $env'REQUEST_METHOD' = 'POST'; - if (empty($env'CONTENT_TYPE')) { - $env'CONTENT_TYPE' = 'application/x-www-form-urlencoded'; - } - - if (empty($env'CONTENT_LENGTH')) { - $env'CONTENT_LENGTH' = $content_length; - } - - $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\""; - - } else if (array_key_exists('GZIP_POST', $section_text) && !empty($section_text'GZIP_POST')) { - - $post = trim($section_text'GZIP_POST'); - $post = gzencode($post, 9, FORCE_GZIP); - $env'HTTP_CONTENT_ENCODING' = 'gzip'; - - save_text($tmp_post, $post); - $content_length = strlen($post); - - $env'REQUEST_METHOD' = 'POST'; - $env'CONTENT_TYPE' = 'application/x-www-form-urlencoded'; - $env'CONTENT_LENGTH' = $content_length; - - $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\""; - - } else if (array_key_exists('DEFLATE_POST', $section_text) && !empty($section_text'DEFLATE_POST')) { - $post = trim($section_text'DEFLATE_POST'); - $post = gzcompress($post, 9); - $env'HTTP_CONTENT_ENCODING' = 'deflate'; - save_text($tmp_post, $post); - $content_length = strlen($post); - - $env'REQUEST_METHOD' = 'POST'; - $env'CONTENT_TYPE' = 'application/x-www-form-urlencoded'; - $env'CONTENT_LENGTH' = $content_length; - - $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\""; - - } else { - - $env'REQUEST_METHOD' = 'GET'; - $env'CONTENT_TYPE' = ''; - $env'CONTENT_LENGTH' = ''; - - $cmd = "$php $pass_options $ini_settings -f \"$test_file\" $args$cmdRedirect"; - } - - if ($valgrind) { - $env'USE_ZEND_ALLOC' = '0'; - $env'ZEND_DONT_UNLOAD_MODULES' = 1; - - $cmd = $valgrind->wrapCommand($cmd, $memcheck_filename, strpos($test_file, "pcre") !== false); - } else { - $env'USE_ZEND_ALLOC' = '1'; - $env'ZEND_DONT_UNLOAD_MODULES' = 0; - } - if (!array_key_exists('XDEBUG_MODE', $env)) { - $env'XDEBUG_MODE' = ""; - } - - - if ($DETAILED) echo " -CONTENT_LENGTH = " . $env'CONTENT_LENGTH' . " -CONTENT_TYPE = " . $env'CONTENT_TYPE' . " -PATH_TRANSLATED = " . $env'PATH_TRANSLATED' . " -QUERY_STRING = " . $env'QUERY_STRING' . " -REDIRECT_STATUS = " . $env'REDIRECT_STATUS' . " -REQUEST_METHOD = " . $env'REQUEST_METHOD' . " -SCRIPT_FILENAME = " . $env'SCRIPT_FILENAME' . " -HTTP_COOKIE = " . $env'HTTP_COOKIE' . " -COMMAND $cmd -"; - - junit_start_timer($shortname); - $hrtime = hrtime(); - $startTime = $hrtime0 * 1000000000 + $hrtime1; - - $out = system_with_timeout($cmd, $env, $section_text'STDIN' ?? null, $captureStdIn, $captureStdOut, $captureStdErr); - - junit_finish_timer($shortname); - $hrtime = hrtime(); - $time = $hrtime0 * 1000000000 + $hrtime1 - $startTime; - if ($time >= $slow_min_ms * 1000000) { - $PHP_FAILED_TESTS'SLOW' = array( - 'name' => $file, - 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT'via' : '') . $tested . " $tested_file", - 'output' => '', - 'diff' => '', - 'info' => $time / 1000000000, - ); - } - - if (array_key_exists('AFTER', $section_text)) { - - if (trim($section_text'AFTER')) { - show_file_block('after', $section_text'AFTER'); - save_text($test_after, trim($section_text'AFTER'), $temp_after); - - $after_params = array(); - settings2array($ini_overwrites, $after_params); - settings2params($after_params); - $extra = substr(PHP_OS, 0, 3) !== "WIN" ? - "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; - $out .= system_with_timeout("$extra $php $pass_options $extra_options -q $after_params $no_file_cache \"$test_after\"", $env); - - if (!$cfg'keep''after') { - @unlink($test_after); - } - } - } - - if (array_key_exists('CLEAN', $section_text) && (!$no_clean || $cfg'keep''clean')) { - - if (trim($section_text'CLEAN')) { - show_file_block('clean', $section_text'CLEAN'); - save_text($test_clean, trim($section_text'CLEAN'), $temp_clean); - - if (!$no_clean) { - $clean_params = array(); - settings2array($ini_overwrites, $clean_params); - settings2params($clean_params); - $extra = substr(PHP_OS, 0, 3) !== "WIN" ? - "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; - system_with_timeout("$extra $php $pass_options $extra_options -q $clean_params $no_file_cache \"$test_clean\"", $env); - } - - if (!$cfg'keep''clean') { - @unlink($test_clean); - } - } - } - - @unlink($tmp_post); - - $leaked = false; - $passed = false; - - if ($valgrind) { // leak check - $leaked = filesize($memcheck_filename) > 0; - - if (!$leaked) { - @unlink($memcheck_filename); - } - } - - // Does the output match what is expected? - $output = preg_replace("/\r\n/", "\n", trim($out)); - - /* when using CGI, strip the headers from the output */ - $headers = array(); - - if (!empty($uses_cgi) && preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) { - $output = trim($match2); - $rh = preg_split("/\n\r+/", $match1); - - foreach ($rh as $line) { - if (strpos($line, ':') !== false) { - $line = explode(':', $line, 2); - $headerstrim($line0) = trim($line1); - } - } - } - - $failed_headers = false; - - if (isset($section_text'EXPECTHEADERS')) { - $want = array(); - $wanted_headers = array(); - $lines = preg_split("/\n\r+/", $section_text'EXPECTHEADERS'); - - foreach ($lines as $line) { - if (strpos($line, ':') !== false) { - $line = explode(':', $line, 2); - $wanttrim($line0) = trim($line1); - $wanted_headers = trim($line0) . ': ' . trim($line1); - } - } - - $output_headers = array(); - - foreach ($want as $k => $v) { - - if (isset($headers$k)) { - $output_headers = $k . ': ' . $headers$k; - } - - if (!isset($headers$k) || $headers$k != $v) { - $failed_headers = true; - } - } - - ksort($wanted_headers); - $wanted_headers = implode("\n", $wanted_headers); - ksort($output_headers); - $output_headers = implode("\n", $output_headers); - } - - show_file_block('out', $output); - - if (isset($section_text'EXPECTF') || isset($section_text'EXPECTREGEX')) { - - if (isset($section_text'EXPECTF')) { - $wanted = trim($section_text'EXPECTF'); - } else { - $wanted = trim($section_text'EXPECTREGEX'); - } - - show_file_block('exp', $wanted); - $wanted_re = preg_replace('/\r\n/', "\n", $wanted); - - if (isset($section_text'EXPECTF')) { - - // do preg_quote, but miss out any %r delimited sections - $temp = ""; - $r = "%r"; - $startOffset = 0; - $length = strlen($wanted_re); - while ($startOffset < $length) { - $start = strpos($wanted_re, $r, $startOffset); - if ($start !== false) { - // we have found a start tag - $end = strpos($wanted_re, $r, $start + 2); - if ($end === false) { - // unbalanced tag, ignore it. - $end = $start = $length; - } - } else { - // no more %r sections - $start = $end = $length; - } - // quote a non re portion of the string - $temp .= preg_quote(substr($wanted_re, $startOffset, $start - $startOffset), '/'); - // add the re unquoted. - if ($end > $start) { - $temp .= '(' . substr($wanted_re, $start + 2, $end - $start - 2) . ')'; - } - $startOffset = $end + 2; - } - $wanted_re = $temp; - - // Stick to basics - $wanted_re = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $wanted_re); - $wanted_re = str_replace('%s', '^\r\n+', $wanted_re); - $wanted_re = str_replace('%S', '^\r\n*', $wanted_re); - $wanted_re = str_replace('%a', '.+', $wanted_re); - $wanted_re = str_replace('%A', '.*', $wanted_re); - $wanted_re = str_replace('%w', '\s*', $wanted_re); - $wanted_re = str_replace('%i', '+-?\d+', $wanted_re); - $wanted_re = str_replace('%d', '\d+', $wanted_re); - $wanted_re = str_replace('%x', '0-9a-fA-F+', $wanted_re); - $wanted_re = str_replace('%f', '+-?\.?\d+\.?\d*(?:Ee+-?\d+)?', $wanted_re); - $wanted_re = str_replace('%c', '.', $wanted_re); - // %f allows two points "-.0.0" but that is the best *simple* expression - } -/* DEBUG YOUR REGEX HERE - var_dump($wanted_re); - print(str_repeat('=', 80) . "\n"); - var_dump($output); - */ - if (preg_match("/^$wanted_re\$/s", $output)) { - $passed = true; - if (!$cfg'keep''php') { - @unlink($test_file); - } - - if (!$leaked && !$failed_headers) { - if (isset($section_text'XFAIL')) { - $warn = true; - $info = " (warn: XFAIL section but test passes)"; - } else { - show_result("PASS", $tested, $tested_file, '', $temp_filenames); - junit_mark_test_as('PASS', $shortname, $tested); - return 'PASSED'; - } - } - } - - } else { - - $wanted = trim($section_text'EXPECT'); - $wanted = preg_replace('/\r\n/', "\n", $wanted); - show_file_block('exp', $wanted); - - // compare and leave on success - if (!strcmp($output, $wanted)) { - $passed = true; - - if (!$cfg'keep''php') { - @unlink($test_file); - } - - if (!$leaked && !$failed_headers) { - if (isset($section_text'XFAIL')) { - $warn = true; - $info = " (warn: XFAIL section but test passes)"; - } else { - show_result("PASS", $tested, $tested_file, '', $temp_filenames); - junit_mark_test_as('PASS', $shortname, $tested); - return 'PASSED'; - } - } - } - - $wanted_re = null; - } - - // Test failed so we need to report details. - if ($failed_headers) { - $passed = false; - $wanted = $wanted_headers . "\n--HEADERS--\n" . $wanted; - $output = $output_headers . "\n--HEADERS--\n" . $output; - - if (isset($wanted_re)) { - $wanted_re = preg_quote($wanted_headers . "\n--HEADERS--\n", '/') . $wanted_re; - } - } - - if ($leaked) { - $restype = 'LEAK'; - } - - if ($warn) { - $restype = 'WARN'; - } - - if (!$passed) { - if (isset($section_text'XFAIL')) { - $restype = 'XFAIL'; - $info = ' XFAIL REASON: ' . rtrim($section_text'XFAIL'); - } else { - $restype = 'FAIL'; - } - } - - if (!$passed || $leaked) { - - // write .exp - if (strpos($log_format, 'E') !== false && file_put_contents($exp_filename, $wanted) === false) { - error("Cannot create expected test output - $exp_filename"); - } - - // write .out - if (strpos($log_format, 'O') !== false && file_put_contents($output_filename, $output) === false) { - error("Cannot create test output - $output_filename"); - } - - // write .diff - $diff = generate_diff($wanted, $wanted_re, $output); - if (is_array($IN_REDIRECT)) { - $diff = "# original source file: $shortname\n" . $diff; - } - show_file_block('diff', $diff); - if (strpos($log_format, 'D') !== false && file_put_contents($diff_filename, $diff) === false) { - error("Cannot create test diff - $diff_filename"); - } - - // write .sh - if (strpos($log_format, 'S') !== false && file_put_contents($sh_filename, "#!/bin/sh - -{$cmd} -") === false) { - error("Cannot create test shell script - $sh_filename"); - } - chmod($sh_filename, 0755); - - // write .log - if (strpos($log_format, 'L') !== false && file_put_contents($log_filename, " ----- EXPECTED OUTPUT -$wanted ----- ACTUAL OUTPUT -$output ----- FAILED -") === false) { - error("Cannot create test log - $log_filename"); - error_report($file, $log_filename, $tested); - } - } - - if ($valgrind && $leaked && $cfg"show""mem") { - show_file_block('mem', file_get_contents($memcheck_filename)); - } - - show_result(implode('&', $restype), $tested, $tested_file, $info, $temp_filenames); - - foreach ($restype as $type) { - $PHP_FAILED_TESTS$type . 'ED' = array( - 'name' => $file, - 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT'via' : '') . $tested . " $tested_file", - 'output' => $output_filename, - 'diff' => $diff_filename, - 'info' => $info, - ); - } - - $diff = empty($diff) ? '' : preg_replace('/\e/', '<esc>', $diff); - - junit_mark_test_as($restype, str_replace(TEST_PHP_SRCDIR . '/', '', $tested_file), $tested, null, $info, $diff); - - return $restype0 . 'ED'; -} - -function comp_line($l1, $l2, $is_reg) -{ - if ($is_reg) { - return preg_match('/^' . $l1 . '$/s', $l2); - } else { - return !strcmp($l1, $l2); - } -} - -function count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $idx2, $cnt1, $cnt2, $steps) -{ - $equal = 0; - - while ($idx1 < $cnt1 && $idx2 < $cnt2 && comp_line($ar1$idx1, $ar2$idx2, $is_reg)) { - $idx1++; - $idx2++; - $equal++; - $steps--; - } - if (--$steps > 0) { - $eq1 = 0; - $st = $steps / 2; - - for ($ofs1 = $idx1 + 1; $ofs1 < $cnt1 && $st-- > 0; $ofs1++) { - $eq = @count_array_diff($ar1, $ar2, $is_reg, $w, $ofs1, $idx2, $cnt1, $cnt2, $st); - - if ($eq > $eq1) { - $eq1 = $eq; - } - } - - $eq2 = 0; - $st = $steps; - - for ($ofs2 = $idx2 + 1; $ofs2 < $cnt2 && $st-- > 0; $ofs2++) { - $eq = @count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $ofs2, $cnt1, $cnt2, $st); - if ($eq > $eq2) { - $eq2 = $eq; - } - } - - if ($eq1 > $eq2) { - $equal += $eq1; - } else if ($eq2 > 0) { - $equal += $eq2; - } - } - - return $equal; -} - -function generate_array_diff($ar1, $ar2, $is_reg, $w) -{ - $idx1 = 0; - $cnt1 = @count($ar1); - $idx2 = 0; - $cnt2 = @count($ar2); - $diff = array(); - $old1 = array(); - $old2 = array(); - - while ($idx1 < $cnt1 && $idx2 < $cnt2) { - - if (comp_line($ar1$idx1, $ar2$idx2, $is_reg)) { - $idx1++; - $idx2++; - continue; - } else { - - $c1 = @count_array_diff($ar1, $ar2, $is_reg, $w, $idx1 + 1, $idx2, $cnt1, $cnt2, 10); - $c2 = @count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $idx2 + 1, $cnt1, $cnt2, 10); - - if ($c1 > $c2) { - $old1$idx1 = sprintf("%03d- ", $idx1 + 1) . $w$idx1++; - } else if ($c2 > 0) { - $old2$idx2 = sprintf("%03d+ ", $idx2 + 1) . $ar2$idx2++; - } else { - $old1$idx1 = sprintf("%03d- ", $idx1 + 1) . $w$idx1++; - $old2$idx2 = sprintf("%03d+ ", $idx2 + 1) . $ar2$idx2++; - } - } - } - - reset($old1); - $k1 = key($old1); - $l1 = -2; - reset($old2); - $k2 = key($old2); - $l2 = -2; - - while ($k1 !== null || $k2 !== null) { - - if ($k1 == $l1 + 1 || $k2 === null) { - $l1 = $k1; - $diff = current($old1); - $k1 = next($old1) ? key($old1) : null; - } else if ($k2 == $l2 + 1 || $k1 === null) { - $l2 = $k2; - $diff = current($old2); - $k2 = next($old2) ? key($old2) : null; - } else if ($k1 < $k2) { - $l1 = $k1; - $diff = current($old1); - $k1 = next($old1) ? key($old1) : null; - } else { - $l2 = $k2; - $diff = current($old2); - $k2 = next($old2) ? key($old2) : null; - } - } - - while ($idx1 < $cnt1) { - $diff = sprintf("%03d- ", $idx1 + 1) . $w$idx1++; - } - - while ($idx2 < $cnt2) { - $diff = sprintf("%03d+ ", $idx2 + 1) . $ar2$idx2++; - } - - return $diff; -} - -function generate_diff($wanted, $wanted_re, $output) -{ - $w = explode("\n", $wanted); - $o = explode("\n", $output); - $r = is_null($wanted_re) ? $w : explode("\n", $wanted_re); - $diff = generate_array_diff($r, $o, !is_null($wanted_re), $w); - - return implode("\r\n", $diff); -} - -function error($message) -{ - echo "ERROR: {$message}\n"; - exit(1); -} - -function settings2array($settings, &$ini_settings) -{ - foreach ($settings as $setting) { - - if (strpos($setting, '=') !== false) { - $setting = explode("=", $setting, 2); - $name = trim($setting0); - $value = trim($setting1); - - if ($name == 'extension' || $name == 'zend_extension') { - - if (!isset($ini_settings$name)) { - $ini_settings$name = array(); - } - - $ini_settings$name = $value; - - } else { - $ini_settings$name = $value; - } - } - } -} - -function settings2params(&$ini_settings) -{ - $settings = ''; - - foreach($ini_settings as $name => $value) { - - if (is_array($value)) { - foreach($value as $val) { - $val = addslashes($val); - $settings .= " -d \"$name=$val\""; - } - } else { - if (substr(PHP_OS, 0, 3) == "WIN" && !empty($value) && is_string($value) && $value0 == '"') { - $len = strlen($value); - - if ($value$len - 1 == '"') { - $value0 = "'"; - $value$len - 1 = "'"; - } - } else { - $value = addslashes($value); - } - - $settings .= " -d \"$name=$value\""; - } - } - - $ini_settings = $settings; -} - -function compute_summary() -{ - global $n_total, $test_results, $ignored_by_ext, $sum_results, $percent_results; - - $n_total = count($test_results); - $n_total += $ignored_by_ext; - $sum_results = array( - 'PASSED' => 0, - 'WARNED' => 0, - 'SKIPPED' => 0, - 'FAILED' => 0, - 'BORKED' => 0, - 'LEAKED' => 0, - 'XFAILED' => 0 - ); - - foreach ($test_results as $v) { - $sum_results$v++; - } - - $sum_results'SKIPPED' += $ignored_by_ext; - $percent_results = array(); - - foreach ($sum_results as $v => $n) { - $percent_results$v = (100.0 * $n) / $n_total; - } -} - -function get_summary($show_ext_summary, $show_html) -{ - global $exts_skipped, $exts_tested, $n_total, $sum_results, $percent_results, $end_time, $start_time, $failed_test_summary, $PHP_FAILED_TESTS, $valgrind; - - $x_total = $n_total - $sum_results'SKIPPED' - $sum_results'BORKED'; - - if ($x_total) { - $x_warned = (100.0 * $sum_results'WARNED') / $x_total; - $x_failed = (100.0 * $sum_results'FAILED') / $x_total; - $x_xfailed = (100.0 * $sum_results'XFAILED') / $x_total; - $x_leaked = (100.0 * $sum_results'LEAKED') / $x_total; - $x_passed = (100.0 * $sum_results'PASSED') / $x_total; - } else { - $x_warned = $x_failed = $x_passed = $x_leaked = $x_xfailed = 0; - } - - $summary = ''; - - if ($show_html) { - $summary .= "<pre>\n"; - } - - if ($show_ext_summary) { - $summary .= ' -===================================================================== -TEST RESULT SUMMARY ---------------------------------------------------------------------- -Exts skipped : ' . sprintf('%4d', $exts_skipped) . ' -Exts tested : ' . sprintf('%4d', $exts_tested) . ' ---------------------------------------------------------------------- -'; - } - - $summary .= ' -Number of tests : ' . sprintf('%4d', $n_total) . ' ' . sprintf('%8d', $x_total); - - if ($sum_results'BORKED') { - $summary .= ' -Tests borked : ' . sprintf('%4d (%5.1f%%)', $sum_results'BORKED', $percent_results'BORKED') . ' --------'; - } - - $summary .= ' -Tests skipped : ' . sprintf('%4d (%5.1f%%)', $sum_results'SKIPPED', $percent_results'SKIPPED') . ' -------- -Tests warned : ' . sprintf('%4d (%5.1f%%)', $sum_results'WARNED', $percent_results'WARNED') . ' ' . sprintf('(%5.1f%%)', $x_warned) . ' -Tests failed : ' . sprintf('%4d (%5.1f%%)', $sum_results'FAILED', $percent_results'FAILED') . ' ' . sprintf('(%5.1f%%)', $x_failed) . ' -Expected fail : ' . sprintf('%4d (%5.1f%%)', $sum_results'XFAILED', $percent_results'XFAILED') . ' ' . sprintf('(%5.1f%%)', $x_xfailed); - - if ($valgrind) { - $summary .= ' -Tests leaked : ' . sprintf('%4d (%5.1f%%)', $sum_results'LEAKED', $percent_results'LEAKED') . ' ' . sprintf('(%5.1f%%)', $x_leaked); - } - - $summary .= ' -Tests passed : ' . sprintf('%4d (%5.1f%%)', $sum_results'PASSED', $percent_results'PASSED') . ' ' . sprintf('(%5.1f%%)', $x_passed) . ' ---------------------------------------------------------------------- -Time taken : ' . sprintf('%4d seconds', $end_time - $start_time) . ' -===================================================================== -'; - $failed_test_summary = ''; - - if (count($PHP_FAILED_TESTS'SLOW')) { - usort($PHP_FAILED_TESTS'SLOW', function ($a, $b) { - return $a'info' < $b'info' ? 1 : -1; - }); - - $failed_test_summary .= ' -===================================================================== -SLOW TEST SUMMARY ---------------------------------------------------------------------- -'; - foreach ($PHP_FAILED_TESTS'SLOW' as $failed_test_data) { - $failed_test_summary .= sprintf('(%.3f s) ', $failed_test_data'info') . $failed_test_data'test_name' . "\n"; - } - $failed_test_summary .= "=====================================================================\n"; - } - - if (count($PHP_FAILED_TESTS'XFAILED')) { - $failed_test_summary .= ' -===================================================================== -EXPECTED FAILED TEST SUMMARY ---------------------------------------------------------------------- -'; - foreach ($PHP_FAILED_TESTS'XFAILED' as $failed_test_data) { - $failed_test_summary .= $failed_test_data'test_name' . $failed_test_data'info' . "\n"; - } - $failed_test_summary .= "=====================================================================\n"; - } - - if (count($PHP_FAILED_TESTS'BORKED')) { - $failed_test_summary .= ' -===================================================================== -BORKED TEST SUMMARY ---------------------------------------------------------------------- -'; - foreach ($PHP_FAILED_TESTS'BORKED' as $failed_test_data) { - $failed_test_summary .= $failed_test_data'info' . "\n"; - } - - $failed_test_summary .= "=====================================================================\n"; - } - - if (count($PHP_FAILED_TESTS'FAILED')) { - $failed_test_summary .= ' -===================================================================== -FAILED TEST SUMMARY ---------------------------------------------------------------------- -'; - foreach ($PHP_FAILED_TESTS'FAILED' as $failed_test_data) { - $failed_test_summary .= $failed_test_data'test_name' . $failed_test_data'info' . "\n"; - } - $failed_test_summary .= "=====================================================================\n"; - } - if (count($PHP_FAILED_TESTS'WARNED')) { - $failed_test_summary .= ' -===================================================================== -WARNED TEST SUMMARY ---------------------------------------------------------------------- -'; - foreach ($PHP_FAILED_TESTS'WARNED' as $failed_test_data) { - $failed_test_summary .= $failed_test_data'test_name' . $failed_test_data'info' . "\n"; - } - - $failed_test_summary .= "=====================================================================\n"; - } - - if (count($PHP_FAILED_TESTS'LEAKED')) { - $failed_test_summary .= ' -===================================================================== -LEAKED TEST SUMMARY ---------------------------------------------------------------------- -'; - foreach ($PHP_FAILED_TESTS'LEAKED' as $failed_test_data) { - $failed_test_summary .= $failed_test_data'test_name' . $failed_test_data'info' . "\n"; - } - - $failed_test_summary .= "=====================================================================\n"; - } - - if ($failed_test_summary && !getenv('NO_PHPTEST_SUMMARY')) { - $summary .= $failed_test_summary; - } - - if ($show_html) { - $summary .= "</pre>"; - } - - return $summary; -} - -function show_start($start_time) -{ - global $html_output, $html_file; - - if ($html_output) { - fwrite($html_file, "<h2>Time Start: " . date('Y-m-d H:i:s', $start_time) . "</h2>\n"); - fwrite($html_file, "<table>\n"); - } - - echo "TIME START " . date('Y-m-d H:i:s', $start_time) . "\n=====================================================================\n"; -} - -function show_end($end_time) -{ - global $html_output, $html_file; - - if ($html_output) { - fwrite($html_file, "</table>\n"); - fwrite($html_file, "<h2>Time End: " . date('Y-m-d H:i:s', $end_time) . "</h2>\n"); - } - - echo "=====================================================================\nTIME END " . date('Y-m-d H:i:s', $end_time) . "\n"; -} - -function show_summary() -{ - global $html_output, $html_file; - - if ($html_output) { - fwrite($html_file, "<hr/>\n" . get_summary(true, true)); - } - - echo get_summary(true, false); -} - -function show_redirect_start($tests, $tested, $tested_file) -{ - global $html_output, $html_file, $line_length, $SHOW_ONLY_GROUPS; - - if ($html_output) { - fwrite($html_file, "<tr><td colspan='3'>---> $tests ($tested $tested_file) begin</td></tr>\n"); - } - - if (!$SHOW_ONLY_GROUPS || in_array('REDIRECT', $SHOW_ONLY_GROUPS)) { - echo "REDIRECT $tests ($tested $tested_file) begin\n"; - } else { - // Write over the last line to avoid random trailing chars on next echo - echo str_repeat(" ", $line_length), "\r"; - } -} - -function show_redirect_ends($tests, $tested, $tested_file) -{ - global $html_output, $html_file, $line_length, $SHOW_ONLY_GROUPS; - - if ($html_output) { - fwrite($html_file, "<tr><td colspan='3'>---> $tests ($tested $tested_file) done</td></tr>\n"); - } - - if (!$SHOW_ONLY_GROUPS || in_array('REDIRECT', $SHOW_ONLY_GROUPS)) { - echo "REDIRECT $tests ($tested $tested_file) done\n"; - } else { - // Write over the last line to avoid random trailing chars on next echo - echo str_repeat(" ", $line_length), "\r"; - } -} - -function show_test($test_idx, $shortname) -{ - global $test_cnt; - global $line_length; - - $str = "TEST $test_idx/$test_cnt $shortname\r"; - $line_length = strlen($str); - echo $str; - flush(); -} - -function show_result($result, $tested, $tested_file, $extra = '', $temp_filenames = null) -{ - global $html_output, $html_file, $temp_target, $temp_urlbase, $line_length, $SHOW_ONLY_GROUPS; - - if (!$SHOW_ONLY_GROUPS || in_array($result, $SHOW_ONLY_GROUPS)) { - switch ( $result ) { - case 'PASS': - $colour = "\e1;32m{$result}\e0m"; break; - case 'SKIP': - $colour = "\e0;37m{$result}"; break; - case 'FAIL': - $colour = "\e1;31m{$result}\e0m"; break; - default: - $colour = "\e1;33m{$result}\e0m"; break; - } - - echo "$colour $tested $tested_file $extra\e0m\n"; - } else if (!$SHOW_ONLY_GROUPS) { - // Write over the last line to avoid random trailing chars on next echo - echo str_repeat(" ", $line_length), "\r"; - } - - if ($html_output) { - - if (isset($temp_filenames'file') && file_exists($temp_filenames'file')) { - $url = str_replace($temp_target, $temp_urlbase, $temp_filenames'file'); - $tested = "<a href='$url'>$tested</a>"; - } - - if (isset($temp_filenames'skip') && file_exists($temp_filenames'skip')) { - - if (empty($extra)) { - $extra = "skipif"; - } - - $url = str_replace($temp_target, $temp_urlbase, $temp_filenames'skip'); - $extra = "<a href='$url'>$extra</a>"; - - } else if (empty($extra)) { - $extra = " "; - } - - if (isset($temp_filenames'diff') && file_exists($temp_filenames'diff')) { - $url = str_replace($temp_target, $temp_urlbase, $temp_filenames'diff'); - $diff = "<a href='$url'>diff</a>"; - } else { - $diff = " "; - } - - if (isset($temp_filenames'mem') && file_exists($temp_filenames'mem')) { - $url = str_replace($temp_target, $temp_urlbase, $temp_filenames'mem'); - $mem = "<a href='$url'>leaks</a>"; - } else { - $mem = " "; - } - - fwrite( - $html_file, - "<tr>" . - "<td>$result</td>" . - "<td>$tested</td>" . - "<td>$extra</td>" . - "<td>$diff</td>" . - "<td>$mem</td>" . - "</tr>\n" - ); - } -} - -function junit_init() -{ - // Check whether a junit log is wanted. - $JUNIT = getenv('TEST_PHP_JUNIT'); - if (empty($JUNIT)) { - $JUNIT = false; - } elseif (!$fp = fopen($JUNIT, 'w')) { - error("Failed to open $JUNIT for writing."); - } else { - $JUNIT = array( - 'fp' => $fp, - 'name' => 'PHP', - 'test_total' => 0, - 'test_pass' => 0, - 'test_fail' => 0, - 'test_error' => 0, - 'test_skip' => 0, - 'test_warn' => 0, - 'execution_time' => 0, - 'suites' => array(), - 'files' => array() - ); - } - - $GLOBALS'JUNIT' = $JUNIT; -} - -function junit_save_xml() -{ - global $JUNIT; - if (!junit_enabled()) return; - - $xml = '<' . '?' . 'xml version="1.0" encoding="UTF-8"' . '?' . '>' . PHP_EOL; - $xml .= sprintf( - '<testsuites name="%s" tests="%s" failures="%d" errors="%d" skip="%d" time="%s">' . PHP_EOL, - $JUNIT'name', - $JUNIT'test_total', - $JUNIT'test_fail', - $JUNIT'test_error', - $JUNIT'test_skip', - $JUNIT'execution_time' - ); - $xml .= junit_get_suite_xml(); - $xml .= '</testsuites>'; - fwrite($JUNIT'fp', $xml); -} - -function junit_get_suite_xml($suite_name = '') -{ - global $JUNIT; - - $result = ""; - - foreach ($JUNIT'suites' as $suite_name => $suite) { - $result .= sprintf( - '<testsuite name="%s" tests="%s" failures="%d" errors="%d" skip="%d" time="%s">' . PHP_EOL, - $suite'name', - $suite'test_total', - $suite'test_fail', - $suite'test_error', - $suite'test_skip', - $suite'execution_time' - ); - - if (!empty($suite_name)) { - foreach ($suite'files' as $file) { - $result .= $JUNIT'files'$file'xml'; - } - } - - $result .= '</testsuite>' . PHP_EOL; - } - - return $result; -} - -function junit_enabled() -{ - global $JUNIT; - return !empty($JUNIT); -} - -/** - * @param array|string $type - * @param string $file_name - * @param string $test_name - * @param int|string $time - * @param string $message - * @param string $details - * @return void - */ -function junit_mark_test_as($type, $file_name, $test_name, $time = null, $message = '', $details = '') -{ - global $JUNIT; - if (!junit_enabled()) return; - - $suite = junit_get_suitename_for($file_name); - - junit_suite_record($suite, 'test_total'); - - $time = $time ?? junit_get_timer($file_name); - junit_suite_record($suite, 'execution_time', $time); - - $escaped_details = htmlspecialchars($details, ENT_QUOTES, 'UTF-8'); - $escaped_details = preg_replace_callback('/\0-\x08\x0B\x0C\x0E-\x1F/', function ($c) { - return sprintf('0x%02x', ord($c0)); - }, $escaped_details); - $escaped_message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8'); - - $escaped_test_name = htmlspecialchars($test_name, ENT_QUOTES); - $JUNIT'files'$file_name'xml' = "<testcase classname='" . $suite . "." . basename($file_name) . "' name='$escaped_test_name' time='$time'>\n"; - - if (is_array($type)) { - $output_type = $type0 . 'ED'; - $temp = array_intersect(array('XFAIL', 'FAIL', 'WARN'), $type); - $type = reset($temp); - } else { - $output_type = $type . 'ED'; - } - - if ('PASS' == $type || 'XFAIL' == $type) { - junit_suite_record($suite, 'test_pass'); - } elseif ('BORK' == $type) { - junit_suite_record($suite, 'test_error'); - $JUNIT'files'$file_name'xml' .= "<error type='$output_type' message='$escaped_message'/>\n"; - } elseif ('SKIP' == $type) { - junit_suite_record($suite, 'test_skip'); - $JUNIT'files'$file_name'xml' .= "<skipped>$escaped_message</skipped>\n"; - } elseif ('WARN' == $type) { - junit_suite_record($suite, 'test_warn'); - $JUNIT'files'$file_name'xml' .= "<warning>$escaped_message</warning>\n"; - } elseif ('FAIL' == $type) { - junit_suite_record($suite, 'test_fail'); - $JUNIT'files'$file_name'xml' .= "<failure type='$output_type' message='$escaped_message'>$escaped_details</failure>\n"; - } else { - junit_suite_record($suite, 'test_error'); - $JUNIT'files'$file_name'xml' .= "<error type='$output_type' message='$escaped_message'>$escaped_details</error>\n"; - } - - $JUNIT'files'$file_name'xml' .= "</testcase>\n"; - -} - -function junit_suite_record($suite, $param, $value = 1) -{ - global $JUNIT; - - $JUNIT$param += $value; - $JUNIT'suites'$suite$param += $value; -} - -function junit_get_timer($file_name) -{ - global $JUNIT; - if (!junit_enabled()) return 0; - - if (isset($JUNIT'files'$file_name'total')) { - return number_format($JUNIT'files'$file_name'total', 4); - } - - return 0; -} - -function junit_start_timer($file_name) -{ - global $JUNIT; - if (!junit_enabled()) return; - - if (!isset($JUNIT'files'$file_name'start')) { - $JUNIT'files'$file_name'start' = microtime(true); - - $suite = junit_get_suitename_for($file_name); - junit_init_suite($suite); - $JUNIT'suites'$suite'files'$file_name = $file_name; - } -} - -function junit_get_suitename_for($file_name) -{ - return junit_path_to_classname(dirname($file_name)); -} - -function junit_path_to_classname($file_name) -{ - global $JUNIT; - - $ret = $JUNIT'name'; - $_tmp = array(); - - // lookup whether we're in the PHP source checkout - $max = 5; - if (is_file($file_name)) { - $dir = dirname(realpath($file_name)); - } else { - $dir = realpath($file_name); - } - do { - array_unshift($_tmp, basename($dir)); - $chk = $dir . DIRECTORY_SEPARATOR . "main" . DIRECTORY_SEPARATOR . "php_version.h"; - $dir = dirname($dir); - } while (!file_exists($chk) && --$max > 0); - if (file_exists($chk)) { - if ($max) { - array_shift($_tmp); - } - foreach ($_tmp as $p) { - $ret .= "." . preg_replace(",^a-z0-9+,i", ".", $p); - } - return $ret; - } - - return $JUNIT'name' . '.' . str_replace(array(DIRECTORY_SEPARATOR, '-'), '.', $file_name); -} - -function junit_init_suite($suite_name) -{ - global $JUNIT; - if (!junit_enabled()) return; - - if (!empty($JUNIT'suites'$suite_name)) { - return; - } - - $JUNIT'suites'$suite_name = array( - 'name' => $suite_name, - 'test_total' => 0, - 'test_pass' => 0, - 'test_fail' => 0, - 'test_error' => 0, - 'test_skip' => 0, - 'test_warn' => 0, - 'suites' => array(), - 'files' => array(), - 'execution_time' => 0, - ); -} - -function junit_finish_timer($file_name) -{ - global $JUNIT; - if (!junit_enabled()) return; - - if (!isset($JUNIT'files'$file_name'start')) { - error("Timer for $file_name was not started!"); - } - - if (!isset($JUNIT'files'$file_name'total')) { - $JUNIT'files'$file_name'total' = 0; - } - - $start = $JUNIT'files'$file_name'start'; - $JUNIT'files'$file_name'total' += microtime(true) - $start; - unset($JUNIT'files'$file_name'start'); -} - -class RuntestsValgrind -{ - protected $version = ''; - protected $header = ''; - protected $version_3_3_0 = false; - protected $version_3_8_0 = false; - - public function getVersion() - { - return $this->version; - } - - public function getHeader() - { - return $this->header; - } - - public function __construct(array $environment) - { - $header = system_with_timeout('valgrind --version', $environment); - if (!$header) { - error("Valgrind returned no version info, cannot proceed.\nPlease check if Valgrind is installed."); - } - $count = 0; - $version = preg_replace("/valgrind-(\d+)\.(\d+)\.(\d+)(.\w_-+)?(\s+)/", '$1.$2.$3', $header, 1, $count); - if ($count != 1) { - error("Valgrind returned invalid version info (\"{$header}\"), cannot proceed."); - } - $this->version = $version; - $this->header = trim($header); - $this->version_3_3_0 = version_compare($version, '3.3.0', '>='); - $this->version_3_8_0 = version_compare($version, '3.8.0', '>='); - } - - public function wrapCommand($cmd, $memcheck_filename, $check_all) - { - $vcmd = 'valgrind -q --tool=memcheck --trace-children=yes'; - if ($check_all) { - $vcmd .= ' --smc-check=all'; - } - - /* --vex-iropt-register-updates=allregs-at-mem-access is necessary for phpdbg watchpoint tests */ - if ($this->version_3_8_0) { - /* valgrind 3.3.0+ doesn't have --log-file-exactly option */ - return "$vcmd --vex-iropt-register-updates=allregs-at-mem-access --log-file=$memcheck_filename $cmd"; - } elseif ($this->version_3_3_0) { - return "$vcmd --vex-iropt-precise-memory-exns=yes --log-file=$memcheck_filename $cmd"; - } else { - return "$vcmd --vex-iropt-precise-memory-exns=yes --log-file-exactly=$memcheck_filename $cmd"; - } - } -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/base/base.c
Deleted
@@ -1,1440 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "TSRM.h" -#include "php_globals.h" -#include "zend_closures.h" -#include "zend_exceptions.h" -#include "zend_interfaces.h" - -#if PHP_VERSION_ID >= 80100 -# include "base_private.h" -# include "Zend/zend_fibers.h" -# include "Zend/zend_observer.h" -#endif - -#include "php_xdebug.h" -#include "php_xdebug_arginfo.h" - -#include "base.h" -#include "filter.h" -#include "develop/develop.h" -#include "develop/stack.h" -#include "gcstats/gc_stats.h" -#include "lib/lib_private.h" -#include "lib/log.h" -#include "lib/var_export_line.h" -#include "lib/var.h" -#include "profiler/profiler.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -#if PHP_VERSION_ID >= 80100 -void (*xdebug_old_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message); -void (*xdebug_new_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message); -static void xdebug_error_cb(int orig_type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message); -#elif PHP_VERSION_ID >= 80000 -void (*xdebug_old_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message); -void (*xdebug_new_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message); -static void xdebug_error_cb(int orig_type, const char *error_filename, const uint32_t error_lineno, zend_string *message); -#else -void (*xdebug_old_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0); -void (*xdebug_new_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0); -static void xdebug_error_cb(int orig_type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0); -#endif - -/* execution redirection functions */ -zend_op_array* (*old_compile_file)(zend_file_handle* file_handle, int type); -static void (*xdebug_old_execute_ex)(zend_execute_data *execute_data); -static void (*xdebug_old_execute_internal)(zend_execute_data *current_execute_data, zval *return_value); - -/* error_cb and execption hook overrides */ -void xdebug_base_use_original_error_cb(void); -void xdebug_base_use_xdebug_error_cb(void); -void xdebug_base_use_xdebug_throw_exception_hook(void); - -/* Forward declarations for function overides */ -PHP_FUNCTION(xdebug_set_time_limit); -PHP_FUNCTION(xdebug_error_reporting); -PHP_FUNCTION(xdebug_pcntl_exec); -PHP_FUNCTION(xdebug_pcntl_fork); - - -/* {{{ zend_op_array xdebug_compile_file (file_handle, type) - * This function provides a hook for the execution of bananas */ -static zend_op_array *xdebug_compile_file(zend_file_handle *file_handle, int type) -{ - zend_op_array *op_array; - - op_array = old_compile_file(file_handle, type); - - if (!op_array) { - return NULL; - } - - xdebug_coverage_compile_file(op_array); - xdebug_debugger_compile_file(op_array); - - return op_array; -} -/* }}} */ - -/* I don't like this API, but the function_stack_entry does not keep this as a - * pointer, and hence we need two APIs for freeing :-S */ -void xdebug_func_dtor_by_ref(xdebug_func *elem) -{ - if (elem->function) { - xdfree(elem->function); - } - if (elem->object_class) { - zend_string_release(elem->object_class); - } - if (elem->scope_class) { - zend_string_release(elem->scope_class); - } -} - -void xdebug_func_dtor(xdebug_func *elem) -{ - xdebug_func_dtor_by_ref(elem); - xdfree(elem); -} - -static void function_stack_entry_dtor(void *elem) -{ - unsigned int i; - function_stack_entry *e = elem; - - xdebug_func_dtor_by_ref(&e->function); - - if (e->filename) { - zend_string_release(e->filename); - } - - if (e->var) { - for (i = 0; i < e->varc; i++) { - if (e->vari.name) { - zend_string_release(e->vari.name); - } - zval_ptr_dtor(&(e->vari.data)); - } - xdfree(e->var); - } - - if (e->include_filename) { - zend_string_release(e->include_filename); - } - - if (e->declared_vars) { - xdebug_llist_destroy(e->declared_vars, NULL); - e->declared_vars = NULL; - } - - if (e->profile.call_list) { - xdebug_llist_destroy(e->profile.call_list, NULL); - e->profile.call_list = NULL; - } -} - -int xdebug_include_or_eval_handler(XDEBUG_OPCODE_HANDLER_ARGS) -{ - const zend_op *opline = execute_data->opline; - zval *inc_filename; - zval tmp_inc_filename; - int is_var; - - if (opline->extended_value != ZEND_EVAL) { - return xdebug_call_original_opcode_handler_if_set(opline->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); - } - - inc_filename = xdebug_get_zval(execute_data, opline->op1_type, &opline->op1, &is_var); - - /* If there is no inc_filename, we're just bailing out instead */ - if (!inc_filename) { - return xdebug_call_original_opcode_handler_if_set(opline->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); - } - - if (Z_TYPE_P(inc_filename) != IS_STRING) { - tmp_inc_filename = *inc_filename; - zval_copy_ctor(&tmp_inc_filename); - convert_to_string(&tmp_inc_filename); - inc_filename = &tmp_inc_filename; - } - - /* Now let's store this info */ - if (XG_BASE(last_eval_statement)) { - zend_string_release(XG_BASE(last_eval_statement)); - } - XG_BASE(last_eval_statement) = zend_string_init(Z_STRVAL_P(inc_filename), Z_STRLEN_P(inc_filename), 0); - - if (inc_filename == &tmp_inc_filename) { - zval_dtor(&tmp_inc_filename); - } - - return xdebug_call_original_opcode_handler_if_set(opline->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); -} - -static int find_line_number_for_current_execute_point(zend_execute_data *edata) -{ - zend_execute_data *ptr = edata; - - while (ptr && (!ptr->func || !ZEND_USER_CODE(ptr->func->type))) { - ptr = ptr->prev_execute_data; - } - - if (ptr && ptr->opline) { - return ptr->opline->lineno; - } - - return 0; -} - - -void xdebug_build_fname(xdebug_func *tmp, zend_execute_data *edata) -{ - memset(tmp, 0, sizeof(xdebug_func)); - - if (edata && edata->func && edata->func == (zend_function*) &zend_pass_function) { - tmp->type = XFUNC_ZEND_PASS; - tmp->function = xdstrdup("{zend_pass}"); - } else if (edata && edata->func) { - tmp->type = XFUNC_NORMAL; - if ((Z_TYPE(edata->This)) == IS_OBJECT) { - tmp->type = XFUNC_MEMBER; - if (edata->func->common.scope && strstr(edata->func->common.scope->name->val, "@anonymous") != NULL) { - char *tmp_object_class = xdebug_sprintf( - "{anonymous-class:%s:%d-%d}", - edata->func->common.scope->info.user.filename->val, - edata->func->common.scope->info.user.line_start, - edata->func->common.scope->info.user.line_end - ); - tmp->object_class = zend_string_init(tmp_object_class, strlen(tmp_object_class), 0); - xdfree(tmp_object_class); - } else { - if (edata->func->common.scope) { - tmp->scope_class = zend_string_copy(edata->func->common.scope->name); - } - tmp->object_class = zend_string_copy(edata->This.value.obj->ce->name); - } - } else { - if (edata->func->common.scope) { - tmp->type = XFUNC_STATIC_MEMBER; - tmp->object_class = zend_string_copy(edata->func->common.scope->name); - } - } - if (edata->func->common.function_name) { - if (edata->func->common.fn_flags & ZEND_ACC_CLOSURE) { - tmp->function = xdebug_wrap_closure_location_around_function_name(&edata->func->op_array, STR_NAME_VAL(edata->func->common.function_name)); - } else if (strncmp(edata->func->common.function_name->val, "call_user_func", 14) == 0) { - zend_string *fname = NULL; - int lineno = 0; - - if (edata->prev_execute_data && edata->prev_execute_data->func && edata->prev_execute_data->func->type == ZEND_USER_FUNCTION) { - fname = edata->prev_execute_data->func->op_array.filename; - } - - if (!fname) { - function_stack_entry *tmp_fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - - if (tmp_fse->filename) { - fname = tmp_fse->filename; - } - } - - if (!fname) { - /* It wasn't a special call_user_func after all */ - goto normal_after_all; - } - - lineno = find_line_number_for_current_execute_point(edata); - - tmp->function = xdebug_sprintf( - "%s:{%s:%d}", - edata->func->common.function_name->val, - ZSTR_VAL(fname), - lineno - ); - } else { -normal_after_all: - tmp->function = xdstrdup(edata->func->common.function_name->val); - } - } else if ( - edata && - edata->func && - edata->func->type == ZEND_EVAL_CODE && - edata->prev_execute_data && - edata->prev_execute_data->func && - edata->prev_execute_data->func->common.function_name && - ( - (strncmp(edata->prev_execute_data->func->common.function_name->val, "assert", 6) == 0) || - (strncmp(edata->prev_execute_data->func->common.function_name->val, "create_function", 15) == 0) - ) - ) { - tmp->type = XFUNC_NORMAL; - tmp->function = xdstrdup("{internal eval}"); - } else if ( - edata && - edata->prev_execute_data && - edata->prev_execute_data->func && - edata->prev_execute_data->func->type == ZEND_USER_FUNCTION && - edata->prev_execute_data->opline && - edata->prev_execute_data->opline->opcode == ZEND_INCLUDE_OR_EVAL - ) { - switch (edata->prev_execute_data->opline->extended_value) { - case ZEND_EVAL: - tmp->type = XFUNC_EVAL; - break; - case ZEND_INCLUDE: - tmp->type = XFUNC_INCLUDE; - break; - case ZEND_REQUIRE: - tmp->type = XFUNC_REQUIRE; - break; - case ZEND_INCLUDE_ONCE: - tmp->type = XFUNC_INCLUDE_ONCE; - break; - case ZEND_REQUIRE_ONCE: - tmp->type = XFUNC_REQUIRE_ONCE; - break; - default: - tmp->type = XFUNC_UNKNOWN; - break; - } - } else if ( - edata && - edata->prev_execute_data - ) { - xdebug_build_fname(tmp, edata->prev_execute_data); - } else { - tmp->type = XFUNC_UNKNOWN; - } - } -} - -// TODO: Remove -#define XINI_DEV(v) (XG(settings.develop.v)) - -#define NO_VARIADIC INT_MAX -#define DEBUG 0 - -static void collect_params_internal(function_stack_entry *fse, zend_execute_data *zdata, zend_op_array *op_array) -{ - int i; - int is_variadic = !!(zdata->func->common.fn_flags & ZEND_ACC_VARIADIC); - int is_trampoline = !!(zdata->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE); - int variadic_at_pos = NO_VARIADIC; - int names_expected = 0; - int arguments_sent = 0; - int arguments_storage = 0; - - arguments_sent = ZEND_CALL_NUM_ARGS(zdata); - if (arguments_sent > USHRT_MAX) { - return; - } - - names_expected = zdata->func->internal_function.num_args; - if (names_expected > arguments_sent) { - names_expected = arguments_sent; - } -#if DEBUG - fprintf(stderr, "\nF: %s\n - CALL_NUM_ARGS: %d, op_array->num_args: %d, is_variadic: %d, trampoline: %d\n", fse->function.function, ZEND_CALL_NUM_ARGS(zdata), op_array->num_args, is_variadic, is_trampoline); -#endif - - /* If this function is variadic, we have an extra name field in arg_info, and also an extra - * argument sent to the function. */ - if (is_variadic && !is_trampoline) { - names_expected++; - } - - /* Pick the highest of "expected arguments" and "arguments given" (also - * taking into account the extra one for variadics */ - if (names_expected > arguments_sent) { - arguments_storage = names_expected; - } else { - arguments_storage = arguments_sent; - } - - fse->varc = arguments_storage; - fse->var = xdmalloc(fse->varc * sizeof(xdebug_var_name)); - -#if DEBUG - fprintf(stderr, " - names_expected: %d, arguments_sent: %d, arguments_storage: %d, fse->varc: %d\n", names_expected, arguments_sent, arguments_storage, fse->varc); -#endif - - /* Initialise everything in storage */ - for (i = 0; i < fse->varc; i++) { - fse->vari.name = NULL; - ZVAL_UNDEF(&fse->vari.data); - fse->vari.is_variadic = 0; - } - - /* Collect Names */ - for (i = 0; i < names_expected; i++) { - if (op_array->arg_infoi.name) { - fse->vari.name = zend_string_init( - zdata->func->internal_function.arg_infoi.name, - strlen(zdata->func->internal_function.arg_infoi.name), - 0 - ); - - /* If an argument is a variadic, then we mark that on this 'name', - * and also remember which position the variadic started */ - if (ZEND_ARG_IS_VARIADIC(&op_array->arg_infoi) && variadic_at_pos == NO_VARIADIC) { - fse->vari.is_variadic = 1; - variadic_at_pos = i; - } - } - } - - /* Collect Arguments */ - for (i = 0; i < arguments_sent; i++) { - /* The index in ZEND_CALL_ARG is 1-based */ -#if DEBUG - fprintf(stderr, "Copying argument %d: ", i); - fprintf(stderr, "ARG "); -#endif - ZVAL_COPY(&(fse->vari.data), ZEND_CALL_ARG(zdata, i + 1)); -#if DEBUG - fprintf(stderr, "OK\n"); -#endif - } - -#if PHP_VERSION_ID >= 80000 - if (ZEND_CALL_INFO(zdata) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { - zend_string *name; - zval *param; - int i = fse->varc; - - fse->varc += zend_hash_num_elements(zdata->extra_named_params); - fse->var = xdrealloc(fse->var, fse->varc * sizeof(xdebug_var_name)); - - ZEND_HASH_FOREACH_STR_KEY_VAL(zdata->extra_named_params, name, param) { - fse->vari.name = zend_string_copy(name); - ZVAL_COPY(&(fse->vari.data), param); - fse->vari.is_variadic = 0; - i++; - } ZEND_HASH_FOREACH_END(); - } -#endif - -#if DEBUG - for (i = 0; i < fse->varc; i++) { - fprintf(stderr, "%2d %-20s %c %s\n", i, fse->vari.name ? ZSTR_VAL(fse->vari.name) : "---", fse->vari.is_variadic ? 'V' : ' ', xdebug_get_zval_value_line(&fse->vari.data, 0, NULL)->d); - } -#endif -} - -static void collect_params(function_stack_entry *fse, zend_execute_data *zdata, zend_op_array *op_array) -{ - int i; - int is_variadic = !!(zdata->func->common.fn_flags & ZEND_ACC_VARIADIC); - int is_trampoline = !!(zdata->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE); - int variadic_at_pos = NO_VARIADIC; - int names_expected = 0; - int arguments_sent = 0; - int arguments_storage = 0; - - arguments_sent = ZEND_CALL_NUM_ARGS(zdata); - - /* The op_array contains the number of * (named) arguments. */ - names_expected = op_array->num_args; - -#if DEBUG - fprintf(stderr, "\nF: %s\n - CALL_NUM_ARGS: %d, op_array->num_args: %d, is_variadic: %d, trampoline: %d\n", fse->function.function, ZEND_CALL_NUM_ARGS(zdata), op_array->num_args, is_variadic, is_trampoline); -#endif - - /* If this function is variadic, we have an extra name field in arg_info, and also an extra - * argument sent to the function. */ - if (is_variadic && !is_trampoline) { - names_expected++; - arguments_sent++; - } - - /* Pick the highest of "expected arguments" and "arguments given" (also - * taking into account the extra one for variadics */ - if (names_expected > arguments_sent) { - arguments_storage = names_expected; - } else { - arguments_storage = arguments_sent; - } - - fse->varc = arguments_storage; - fse->var = xdmalloc(fse->varc * sizeof(xdebug_var_name)); - -#if DEBUG - fprintf(stderr, " - names_expected: %d, arguments_sent: %d, arguments_storage: %d, fse->varc: %d\n", names_expected, arguments_sent, arguments_storage, fse->varc); -#endif - - /* Initialise everything in storage */ - for (i = 0; i < fse->varc; i++) { - fse->vari.name = NULL; - ZVAL_UNDEF(&fse->vari.data); - fse->vari.is_variadic = 0; - } - - /* Collect Names */ - for (i = 0; i < names_expected; i++) { - if (op_array->arg_infoi.name) { - fse->vari.name = zend_string_copy(op_array->arg_infoi.name); - } - - /* If an argument is a variadic, then we mark that on this 'name', - * and also remember which position the variadic started */ - if (ZEND_ARG_IS_VARIADIC(&op_array->arg_infoi) && variadic_at_pos == NO_VARIADIC) { - fse->vari.is_variadic = 1; - variadic_at_pos = i; - } - } - - /* Collect Arguments */ - for (i = 0; i < fse->varc; i++) { - /* The index in ZEND_CALL_ARG is 1-based */ -#if DEBUG - fprintf(stderr, "Copying argument %d: ", i); -#endif - if (i < names_expected || is_trampoline) { -#if DEBUG - fprintf(stderr, "ARG "); -#endif - ZVAL_COPY(&(fse->vari.data), ZEND_CALL_ARG(zdata, i + 1)); - } else { -#if DEBUG - fprintf(stderr, "VAR_NUM "); -#endif - ZVAL_COPY(&(fse->vari.data), ZEND_CALL_VAR_NUM(zdata, zdata->func->op_array.last_var + zdata->func->op_array.T + i - names_expected)); - } -#if DEBUG - fprintf(stderr, "OK\n"); -#endif - } - -#if PHP_VERSION_ID >= 80000 - if (ZEND_CALL_INFO(zdata) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { - zend_string *name; - zval *param; - int i = fse->varc; - - fse->varc += zend_hash_num_elements(zdata->extra_named_params); - fse->var = xdrealloc(fse->var, fse->varc * sizeof(xdebug_var_name)); - - ZEND_HASH_FOREACH_STR_KEY_VAL(zdata->extra_named_params, name, param) { - fse->vari.name = zend_string_copy(name); - ZVAL_COPY(&(fse->vari.data), param); - fse->vari.is_variadic = 0; - i++; - } ZEND_HASH_FOREACH_END(); - } -#endif - -#if DEBUG - for (i = 0; i < fse->varc; i++) { - fprintf(stderr, "%2d %-20s %c %s\n", i, fse->vari.name ? ZSTR_VAL(fse->vari.name) : "---", fse->vari.is_variadic ? 'V' : ' ', xdebug_get_zval_value_line(&fse->vari.data, 0, NULL)->d); - } -#endif -} - -function_stack_entry *xdebug_add_stack_frame(zend_execute_data *zdata, zend_op_array *op_array, int type) -{ - zend_execute_data *edata; - zend_op **opline_ptr = NULL; - function_stack_entry *tmp; - zend_op *cur_opcode; - - if (type == XDEBUG_USER_DEFINED) { - edata = EG(current_execute_data)->prev_execute_data; - if (edata) { - opline_ptr = (zend_op**) &edata->opline; - } - } else { - edata = EG(current_execute_data); - opline_ptr = (zend_op**) &EG(current_execute_data)->opline; - } - zdata = EG(current_execute_data); - - tmp = (function_stack_entry*) xdebug_vector_push(XG_BASE(stack)); - tmp->level = XDEBUG_VECTOR_COUNT(XG_BASE(stack)); - tmp->user_defined = type; - tmp->op_array = op_array; - - XG_BASE(function_count)++; - tmp->function_nr = XG_BASE(function_count); - { - zend_execute_data *ptr = edata; - while (ptr && (!ptr->func || !ZEND_USER_CODE(ptr->func->type))) { - ptr = ptr->prev_execute_data; - } - if (ptr) { - tmp->filename = zend_string_copy(ptr->func->op_array.filename); - } - } - - if (!tmp->filename) { - /* Includes/main script etc */ - tmp->filename = (type == XDEBUG_USER_DEFINED && op_array && op_array->filename) ? zend_string_copy(op_array->filename) : NULL; - } - /* Call user function locations */ - if (!tmp->filename && XG_BASE(stack)) { - function_stack_entry *tail_fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - if (tail_fse->filename) { - tmp->filename = zend_string_copy(tail_fse->filename); - } - } - - if (!tmp->filename) { - tmp->filename = zend_string_init("Unknown", sizeof("Unknown") - 1, 0); - } - tmp->lineno = 0; - - tmp->prev_memory = XG_BASE(prev_memory); - tmp->memory = zend_memory_usage(0); - XG_BASE(prev_memory) = tmp->memory; - - /* Only get the time when it is actually going to be used. Profiling is not - * included, because it has its own points when it reads the current time. - * */ - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) || XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - tmp->nanotime = xdebug_get_nanotime(); - } else { - tmp->nanotime = 0; - } - - xdebug_build_fname(&(tmp->function), zdata); - if (!tmp->function.type) { - tmp->function.function = xdstrdup("{main}"); - tmp->function.object_class = NULL; - tmp->function.scope_class = NULL; - tmp->function.type = XFUNC_MAIN; - - } else if (tmp->function.type & XFUNC_INCLUDES) { - tmp->lineno = 0; - if (opline_ptr) { - cur_opcode = *opline_ptr; - if (cur_opcode) { - tmp->lineno = cur_opcode->lineno; - } - } - - if (tmp->function.type == XFUNC_EVAL && XG_BASE(last_eval_statement)) { - tmp->include_filename = zend_string_copy(XG_BASE(last_eval_statement)); - } else { - tmp->include_filename = zend_string_copy(zend_get_executed_filename_ex()); - } - } else { - tmp->lineno = find_line_number_for_current_execute_point(edata); - tmp->is_variadic = !!(zdata->func->common.fn_flags & ZEND_ACC_VARIADIC); - - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) || XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - if (ZEND_USER_CODE(zdata->func->type)) { - collect_params(tmp, zdata, op_array); - } else { - collect_params_internal(tmp, zdata, op_array); - } - } - } - - /* Now we have location and name, we can run the filter (for stack and tracing)*/ - xdebug_filter_run(tmp); - - /* Count code coverage line for call */ - xdebug_coverage_count_line_if_branch_check_active(op_array, tmp->filename, tmp->lineno); - - return tmp; -} - -static void xdebug_execute_ex(zend_execute_data *execute_data) -{ - zend_op_array *op_array = &(execute_data->func->op_array); - zend_execute_data *edata = execute_data->prev_execute_data; - function_stack_entry *fse; - int function_nr = 0; - char *code_coverage_function_name = NULL; - zend_string *code_coverage_filename = NULL; - int code_coverage_init = 0; - - /* For PHP 7, we need to reset the opline to the start, so that all opcode - * handlers are being hit. But not for generators, as that would make an - * endless loop. TODO: Fix RECV handling with generators. */ - if (!(EX(func)->op_array.fn_flags & ZEND_ACC_GENERATOR)) { - EX(opline) = EX(func)->op_array.opcodes; - } - - if (xdebug_debugger_bailout_if_no_exec_requested()) { - return; - } - - /* If we're evaluating for the debugger's eval capability, just bail out */ - if (op_array && op_array->filename && strcmp("xdebug://debug-eval", STR_NAME_VAL(op_array->filename)) == 0) { - xdebug_old_execute_ex(execute_data); - return; - } - - /* if we're in a ZEND_EXT_STMT, we ignore this function call as it's likely - that it's just being called to check for breakpoints with conditions */ - if (edata && edata->func && ZEND_USER_CODE(edata->func->type) && edata->opline && edata->opline->opcode == ZEND_EXT_STMT) { - xdebug_old_execute_ex(execute_data); - return; - } - - /* If the stack vector hasn't been initialised yet, we should abort immediately */ - if (!XG_BASE(stack)) { - xdebug_old_execute_ex(execute_data); - return; - } - - if (XG_BASE(in_execution) && XDEBUG_VECTOR_COUNT(XG_BASE(stack)) == 0) { - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - xdebug_debugger_set_program_name(op_array->filename); - xdebug_debug_init_if_requested_at_startup(); - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { - xdebug_gcstats_init_if_requested(op_array); - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - xdebug_profiler_init_if_requested(op_array); - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { - xdebug_tracing_init_if_requested(op_array); - } - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP) && (signed long) XDEBUG_VECTOR_COUNT(XG_BASE(stack)) >= XINI_BASE(max_nesting_level) && (XINI_BASE(max_nesting_level) != -1)) { - zend_throw_exception_ex(zend_ce_error, 0, "Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '" ZEND_LONG_FMT "' frames", XINI_BASE(max_nesting_level)); - } - - fse = xdebug_add_stack_frame(edata, op_array, XDEBUG_USER_DEFINED); - fse->function.internal = 0; - - /* A hack to make __call work with profiles. The function *is* user defined after all. */ - if (fse && xdebug_vector_element_is_valid(XG_BASE(stack), fse - 1) && fse->function.function && (strcmp(fse->function.function, "__call") == 0)) { - (fse - 1)->user_defined = XDEBUG_USER_DEFINED; - } - - function_nr = XG_BASE(function_count); - - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - xdebug_monitor_handler(fse); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { - xdebug_tracing_execute_ex(function_nr, fse); - } - - fse->execute_data = EG(current_execute_data)->prev_execute_data; - if (ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_HAS_SYMBOL_TABLE) { - fse->symbol_table = EG(current_execute_data)->symbol_table; - } - - if (XG_BASE(stack) && (XINI_DEV(show_local_vars) || xdebug_is_debug_connection_active())) { - /* Because include/require is treated as a stack level, we have to add used - * variables in include/required files to all the stack levels above, until - * we hit a function or the top level stack. This is so that the variables - * show up correctly where they should be. We always call - * xdebug_lib_register_compiled_variables on the current stack level, - * otherwise vars in include files do not show up in the locals list. */ - function_stack_entry *loop_fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - int i; - - for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, loop_fse--) { - xdebug_lib_register_compiled_variables(loop_fse, op_array); - if (XDEBUG_IS_NORMAL_FUNCTION(&loop_fse->function)) { - break; - } - } - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { - code_coverage_init = xdebug_coverage_execute_ex(fse, op_array, &code_coverage_filename, &code_coverage_function_name); - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - /* If we're in an eval, we need to create an ID for it. */ - if (fse->function.type == XFUNC_EVAL) { - xdebug_debugger_register_eval(fse); - } - - /* Check for entry breakpoints */ - xdebug_debugger_handle_breakpoints(fse, XDEBUG_BREAKPOINT_TYPE_CALL); - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - xdebug_profiler_execute_ex(fse, op_array); - } - - xdebug_old_execute_ex(execute_data); - - /* Re-acquire the tail as nested calls through xdebug_old_execute_ex() - * might have reallocated the vector */ - fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - xdebug_profiler_execute_ex_end(fse); - } - - if (code_coverage_init) { - xdebug_coverage_execute_ex_end(fse, op_array, code_coverage_filename, code_coverage_function_name); - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { - xdebug_tracing_execute_ex_end(function_nr, fse, execute_data); - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - /* Check for return breakpoints */ - xdebug_debugger_handle_breakpoints(fse, XDEBUG_BREAKPOINT_TYPE_RETURN); - } - - fse->symbol_table = NULL; - fse->execute_data = NULL; - - if (XG_BASE(stack)) { - xdebug_vector_pop(XG_BASE(stack)); - } -} - -static int check_soap_call(function_stack_entry *fse, zend_execute_data *execute_data) -{ - if ( - fse->function.object_class && - Z_OBJ(EX(This)) && - Z_TYPE(EX(This)) == IS_OBJECT && - (zend_hash_str_find_ptr(&module_registry, "soap", sizeof("soap") - 1) != NULL) - ) { - zend_class_entry *soap_server_ce, *soap_client_ce; - - soap_server_ce = zend_hash_str_find_ptr(CG(class_table), "soapserver", 10); - soap_client_ce = zend_hash_str_find_ptr(CG(class_table), "soapclient", 10); - - if (!soap_server_ce || !soap_client_ce) { - return 0; - } - - if ( - (instanceof_function(Z_OBJCE(EX(This)), soap_server_ce)) || - (instanceof_function(Z_OBJCE(EX(This)), soap_client_ce)) - ) { - return 1; - } - } - return 0; -} - -static void xdebug_execute_internal(zend_execute_data *current_execute_data, zval *return_value) -{ - zend_execute_data *edata = EG(current_execute_data); - function_stack_entry *fse; - int function_nr = 0; - int function_call_traced = 0; - int restore_error_handler_situation = 0; -#if PHP_VERSION_ID >= 80100 - void (*tmp_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message) = NULL; -#elif PHP_VERSION_ID >= 80000 - void (*tmp_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message) = NULL; -#else - void (*tmp_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 4, 0) = NULL; -#endif - - /* If the stack vector hasn't been initialised yet, we should abort immediately */ - if (!XG_BASE(stack)) { - if (xdebug_old_execute_internal) { - xdebug_old_execute_internal(current_execute_data, return_value); - } else { - execute_internal(current_execute_data, return_value); - } - return; - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP) && (signed long) XDEBUG_VECTOR_COUNT(XG_BASE(stack)) >= XINI_BASE(max_nesting_level) && (XINI_BASE(max_nesting_level) != -1)) { - zend_throw_exception_ex(zend_ce_error, 0, "Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '" ZEND_LONG_FMT "' frames", XINI_BASE(max_nesting_level)); - } - - fse = xdebug_add_stack_frame(edata, &edata->func->op_array, XDEBUG_BUILT_IN); - fse->function.internal = 1; - - function_nr = XG_BASE(function_count); - - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - xdebug_monitor_handler(fse); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { - function_call_traced = xdebug_tracing_execute_internal(function_nr, fse); - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - /* Check for entry breakpoints */ - xdebug_debugger_handle_breakpoints(fse, XDEBUG_BREAKPOINT_TYPE_CALL); - } - - /* Check for SOAP */ - if (check_soap_call(fse, current_execute_data)) { - restore_error_handler_situation = 1; - tmp_error_cb = zend_error_cb; - xdebug_base_use_original_error_cb(); - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - xdebug_profiler_execute_internal(fse); - } - - if (xdebug_old_execute_internal) { - xdebug_old_execute_internal(current_execute_data, return_value); - } else { - execute_internal(current_execute_data, return_value); - } - - /* Re-acquire the tail as nested calls through - * xdebug_old_execute_internal() might have reallocated the vector */ - fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - xdebug_profiler_execute_internal_end(fse); - } - - /* Restore SOAP situation if needed */ - if (restore_error_handler_situation) { - zend_error_cb = tmp_error_cb; - } - - /* We only call the function_exit handler and return value handler if the - * function call was also traced. Otherwise we end up with return trace - * lines without a corresponding function call line. */ - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) && function_call_traced) { - xdebug_tracing_execute_internal_end(function_nr, fse, return_value); - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - /* Check for return breakpoints */ - xdebug_debugger_handle_breakpoints(fse, XDEBUG_BREAKPOINT_TYPE_RETURN); - } - - if (XG_BASE(stack)) { - xdebug_vector_pop(XG_BASE(stack)); - } -} - -static void xdebug_base_overloaded_functions_setup(void) -{ - zend_function *orig; - - /* Override set_time_limit with our own function to prevent timing out while debugging */ - orig = zend_hash_str_find_ptr(EG(function_table), "set_time_limit", sizeof("set_time_limit") - 1); - if (orig) { - XG_BASE(orig_set_time_limit_func) = orig->internal_function.handler; - orig->internal_function.handler = zif_xdebug_set_time_limit; - } else { - XG_BASE(orig_set_time_limit_func) = NULL; - } - - /* Override error_reporting with our own function, to be able to give right answer during DBGp's - * 'eval' commands */ - orig = zend_hash_str_find_ptr(EG(function_table), "error_reporting", sizeof("error_reporting") - 1); - if (orig) { - XG_BASE(orig_error_reporting_func) = orig->internal_function.handler; - orig->internal_function.handler = zif_xdebug_error_reporting; - } else { - XG_BASE(orig_error_reporting_func) = NULL; - } - - /* Override pcntl_exec with our own function to be able to write profiling summary */ - orig = zend_hash_str_find_ptr(EG(function_table), "pcntl_exec", sizeof("pcntl_exec") - 1); - if (orig) { - XG_BASE(orig_pcntl_exec_func) = orig->internal_function.handler; - orig->internal_function.handler = zif_xdebug_pcntl_exec; - } else { - XG_BASE(orig_pcntl_exec_func) = NULL; - } - - /* Override pcntl_fork with our own function to be able - * to start the debugger for the forked process */ - orig = zend_hash_str_find_ptr(EG(function_table), "pcntl_fork", sizeof("pcntl_fork") - 1); - if (orig) { - XG_BASE(orig_pcntl_fork_func) = orig->internal_function.handler; - orig->internal_function.handler = zif_xdebug_pcntl_fork; - } else { - XG_BASE(orig_pcntl_fork_func) = NULL; - } -} - -static void xdebug_base_overloaded_functions_restore(void) -{ - zend_function *orig; - - if (XG_BASE(orig_set_time_limit_func)) { - orig = zend_hash_str_find_ptr(EG(function_table), "set_time_limit", sizeof("set_time_limit") - 1); - if (orig) { - orig->internal_function.handler = XG_BASE(orig_set_time_limit_func); - } - } - - if (XG_BASE(orig_error_reporting_func)) { - orig = zend_hash_str_find_ptr(EG(function_table), "error_reporting", sizeof("error_reporting") - 1); - if (orig) { - orig->internal_function.handler = XG_BASE(orig_error_reporting_func); - } - } - - if (XG_BASE(orig_pcntl_exec_func)) { - orig = zend_hash_str_find_ptr(EG(function_table), "pcntl_exec", sizeof("pcntl_exec") - 1); - if (orig) { - orig->internal_function.handler = XG_BASE(orig_pcntl_exec_func); - } - } - - if (XG_BASE(orig_pcntl_fork_func)) { - orig = zend_hash_str_find_ptr(EG(function_table), "pcntl_fork", sizeof("pcntl_fork") - 1); - if (orig) { - orig->internal_function.handler = XG_BASE(orig_pcntl_fork_func); - } - } -} - -static int xdebug_closure_serialize_deny_wrapper(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data) -{ - zend_class_entry *ce = Z_OBJCE_P(object); - - if (!XG_BASE(in_var_serialisation)) { - zend_throw_exception_ex(NULL, 0, "Serialization of '%s' is not allowed", STR_NAME_VAL(ce->name)); - } - return FAILURE; -} - -#if PHP_VERSION_ID >= 80100 -static struct xdebug_fiber_entry* xdebug_fiber_entry_ctor(xdebug_vector *stack) -{ - struct xdebug_fiber_entry *tmp = xdmalloc(sizeof(struct xdebug_fiber_entry)); - - tmp->stack = stack; - - return tmp; -} - -static void xdebug_fiber_entry_dtor(struct xdebug_fiber_entry *entry) -{ - xdebug_vector_destroy(entry->stack); - xdfree(entry); -} - -static xdebug_str *create_key_for_fiber(zend_fiber_context *fiber) -{ - xdebug_str *tmp = xdebug_str_new(); - - xdebug_str_add_fmt(tmp, "{fiber:%0" PRIXPTR "}", ((uintptr_t) fiber)); - - return tmp; -} - -static void add_fiber_main(zend_fiber_context *fiber) -{ - xdebug_str *key = create_key_for_fiber(fiber); - function_stack_entry *tmp = (function_stack_entry*) xdebug_vector_push(XG_BASE(stack)); - - tmp->level = XDEBUG_VECTOR_COUNT(XG_BASE(stack)); - tmp->user_defined = XDEBUG_BUILT_IN; - tmp->function.type = XFUNC_FIBER; - tmp->function.object_class = NULL; - tmp->function.scope_class = NULL; - tmp->function.function = xdstrdup(key->d); - tmp->filename = zend_string_copy(zend_get_executed_filename_ex()); - tmp->lineno = zend_get_executed_lineno(); - - tmp->prev_memory = XG_BASE(prev_memory); - tmp->memory = zend_memory_usage(0); - XG_BASE(prev_memory) = tmp->memory; - - tmp->nanotime = xdebug_get_nanotime(); - - xdebug_str_free(key); -} - -static xdebug_vector* create_stack_for_fiber(zend_fiber_context *fiber) -{ - xdebug_vector *tmp_stack = xdebug_vector_alloc(sizeof(function_stack_entry), function_stack_entry_dtor); - xdebug_str *key = create_key_for_fiber(fiber); - struct xdebug_fiber_entry *entry = xdebug_fiber_entry_ctor(tmp_stack); - - xdebug_hash_add(XG_BASE(fiber_stacks), key->d, key->l, entry); - - xdebug_str_free(key); - - return tmp_stack; -} - -static void remove_stack_for_fiber(zend_fiber_context *fiber) -{ - xdebug_str *key = create_key_for_fiber(fiber); - - xdebug_hash_delete(XG_BASE(fiber_stacks), key->d, key->l); - - xdebug_str_free(key); -} - -static xdebug_vector *find_stack_for_fiber(zend_fiber_context *fiber) -{ - struct xdebug_fiber_entry *entry = NULL; - xdebug_str *key = create_key_for_fiber(fiber); - - xdebug_hash_find(XG_BASE(fiber_stacks), key->d, key->l, (void*) &entry); - - xdebug_str_free(key); - - return entry->stack; -} - -static void xdebug_fiber_switch_observer(zend_fiber_context *from, zend_fiber_context *to) -{ - xdebug_vector *current_stack; - - if (from->status == ZEND_FIBER_STATUS_DEAD) { - remove_stack_for_fiber(from); - } - if (to->status == ZEND_FIBER_STATUS_INIT) { - current_stack = create_stack_for_fiber(to); - } else { - current_stack = find_stack_for_fiber(to); - } - XG_BASE(stack) = current_stack; - - if (to->status == ZEND_FIBER_STATUS_INIT) { - add_fiber_main(to); - } -} -#endif - -void xdebug_base_minit(INIT_FUNC_ARGS) -{ - /* Record Zend and Xdebug error callbacks, the actual setting is done in - * base on RINIT */ - xdebug_old_error_cb = zend_error_cb; - xdebug_new_error_cb = xdebug_error_cb; - - /* Redirect compile and execute functions to our own. For PHP 7.3 and - * later, we hook these in xdebug_post_startup instead */ -#if PHP_VERSION_ID < 70300 - old_compile_file = zend_compile_file; - zend_compile_file = xdebug_compile_file; -#endif - - xdebug_old_execute_ex = zend_execute_ex; - zend_execute_ex = xdebug_execute_ex; - - xdebug_old_execute_internal = zend_execute_internal; - zend_execute_internal = xdebug_execute_internal; - - XG_BASE(error_reporting_override) = 0; - XG_BASE(error_reporting_overridden) = 0; - XG_BASE(output_is_tty) = OUTPUT_NOT_CHECKED; - -#if PHP_VERSION_ID >= 80100 - zend_observer_fiber_switch_register(xdebug_fiber_switch_observer); -#endif -} - -void xdebug_base_mshutdown() -{ - /* Reset compile, execute and error callbacks */ - zend_compile_file = old_compile_file; - zend_execute_ex = xdebug_old_execute_ex; - zend_execute_internal = xdebug_old_execute_internal; - zend_error_cb = xdebug_old_error_cb; -} - -void xdebug_base_post_startup() -{ - old_compile_file = zend_compile_file; - zend_compile_file = xdebug_compile_file; -} - -void xdebug_base_rinit() -{ - /* Hack: We check for a soap header here, if that's existing, we don't use - * Xdebug's error handler to keep soap fault from fucking up. */ - if ( - (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP) || XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) - && - (zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_SERVER), "HTTP_SOAPACTION", sizeof("HTTP_SOAPACTION") - 1) == NULL) - ) { - xdebug_base_use_xdebug_error_cb(); - xdebug_base_use_xdebug_throw_exception_hook(); - } - -#if PHP_VERSION_ID >= 80100 - XG_BASE(fiber_stacks) = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_fiber_entry_dtor); - XG_BASE(stack) = create_stack_for_fiber(EG(main_fiber_context)); -#else - XG_BASE(stack) = xdebug_vector_alloc(sizeof(function_stack_entry), function_stack_entry_dtor); -#endif - XG_BASE(in_debug_info) = 0; - XG_BASE(prev_memory) = 0; - XG_BASE(function_count) = -1; - XG_BASE(last_eval_statement) = NULL; - XG_BASE(last_exception_trace) = NULL; - - /* Initialize start time */ - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) || XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - XG_BASE(start_nanotime) = xdebug_get_nanotime(); - } else { - XG_BASE(start_nanotime) = 0; - } - - XG_BASE(in_var_serialisation) = 0; - zend_ce_closure->serialize = xdebug_closure_serialize_deny_wrapper; - - /* Signal that we're in a request now */ - XG_BASE(in_execution) = 1; - - /* filters */ - XG_BASE(filter_type_code_coverage) = XDEBUG_FILTER_NONE; - XG_BASE(filter_type_stack) = XDEBUG_FILTER_NONE; - XG_BASE(filter_type_tracing) = XDEBUG_FILTER_NONE; - XG_BASE(filters_code_coverage) = xdebug_llist_alloc(xdebug_llist_string_dtor); - XG_BASE(filters_stack) = xdebug_llist_alloc(xdebug_llist_string_dtor); - XG_BASE(filters_tracing) = xdebug_llist_alloc(xdebug_llist_string_dtor); - - xdebug_base_overloaded_functions_setup(); -} - -void xdebug_base_post_deactivate() -{ -#if PHP_VERSION_ID >= 80100 - xdebug_hash_destroy(XG_BASE(fiber_stacks)); - XG_BASE(fiber_stacks) = NULL; -#else - xdebug_vector_destroy(XG_BASE(stack)); -#endif - XG_BASE(stack) = NULL; - - XG_BASE(in_debug_info) = 0; - - if (XG_BASE(last_eval_statement)) { - zend_string_release(XG_BASE(last_eval_statement)); - XG_BASE(last_eval_statement) = NULL; - } - if (XG_BASE(last_exception_trace)) { - xdfree(XG_BASE(last_exception_trace)); - XG_BASE(last_exception_trace) = NULL; - } - - /* filters */ - xdebug_llist_destroy(XG_BASE(filters_code_coverage), NULL); - xdebug_llist_destroy(XG_BASE(filters_stack), NULL); - xdebug_llist_destroy(XG_BASE(filters_tracing), NULL); - XG_BASE(filters_tracing) = NULL; - XG_BASE(filters_code_coverage) = NULL; - - xdebug_base_overloaded_functions_restore(); -} - -void xdebug_base_rshutdown() -{ - /* Signal that we're no longer in a request */ - XG_BASE(in_execution) = 0; -} - -/* Error callback for formatting stack traces */ -#if PHP_VERSION_ID >= 80100 -static void xdebug_error_cb(int orig_type, zend_string *error_filename, const unsigned int error_lineno, zend_string *message) -{ - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - int type = orig_type & E_ALL; - char *error_type_str = xdebug_error_type(type); - - xdebug_debugger_error_cb(error_filename, error_lineno, type, error_type_str, ZSTR_VAL(message)); - - xdfree(error_type_str); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - xdebug_develop_error_cb(orig_type, error_filename, error_lineno, message); - } else { - xdebug_old_error_cb(orig_type, error_filename, error_lineno, message); - } -} -#elif PHP_VERSION_ID >= 80000 -static void xdebug_error_cb(int orig_type, const char *error_filename, const unsigned int error_lineno, zend_string *message) -{ - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - int type = orig_type & E_ALL; - char *error_type_str = xdebug_error_type(type); - zend_string *tmp_error_filename = zend_string_init(error_filename, strlen(error_filename), 0); - - xdebug_debugger_error_cb(tmp_error_filename, error_lineno, type, error_type_str, ZSTR_VAL(message)); - - zend_string_release(tmp_error_filename); - xdfree(error_type_str); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - xdebug_develop_error_cb(orig_type, error_filename, error_lineno, message); - } else { - xdebug_old_error_cb(orig_type, error_filename, error_lineno, message); - } -} -#else -static void xdebug_error_cb(int orig_type, const char *error_filename, const unsigned int error_lineno, const char *format, va_list args) -{ - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - int type = orig_type & E_ALL; - char *error_type_str = xdebug_error_type(type); - zend_string *tmp_error_filename = zend_string_init(error_filename, strlen(error_filename), 0); - char *buffer; - va_list new_args; - - va_copy(new_args, args); - vspprintf(&buffer, PG(log_errors_max_len), format, new_args); - va_end(new_args); - - xdebug_debugger_error_cb(tmp_error_filename, error_lineno, type, error_type_str, buffer); - - efree(buffer); - zend_string_release(tmp_error_filename); - xdfree(error_type_str); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - xdebug_develop_error_cb(orig_type, error_filename, error_lineno, format, args); - } else { - xdebug_old_error_cb(orig_type, error_filename, error_lineno, format, args); - } -} -#endif - -void xdebug_base_use_original_error_cb(void) -{ - zend_error_cb = xdebug_old_error_cb; -} - -void xdebug_base_use_xdebug_error_cb(void) -{ - zend_error_cb = xdebug_new_error_cb; -} - -#if PHP_VERSION_ID >= 80000 -static void xdebug_throw_exception_hook(zend_object *exception) -{ -#else -static void xdebug_throw_exception_hook(zval *exception) -{ -#endif - zval *code, *message, *file, *line; - zend_class_entry *exception_ce; - char *code_str = NULL; - zval dummy; - - if (!XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP) && !XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - return; - } - - if (!exception) { - return; - } - -#if PHP_VERSION_ID >= 80000 - if (zend_is_unwind_exit(exception)) { - return; - } -#endif -#if PHP_VERSION_ID >= 80100 - if (zend_is_graceful_exit(exception)) { - return; - } -#endif - -#if PHP_VERSION_ID >= 80000 - exception_ce = exception->ce; -#else - exception_ce = Z_OBJCE_P(exception); -#endif - - code = zend_read_property(exception_ce, exception, "code", sizeof("code")-1, 0, &dummy); - message = zend_read_property(exception_ce, exception, "message", sizeof("message")-1, 0, &dummy); - file = zend_read_property(exception_ce, exception, "file", sizeof("file")-1, 0, &dummy); - line = zend_read_property(exception_ce, exception, "line", sizeof("line")-1, 0, &dummy); - - if (Z_TYPE_P(code) == IS_LONG) { - if (Z_LVAL_P(code) != 0) { - code_str = xdebug_sprintf("%lu", Z_LVAL_P(code)); - } - } else if (Z_TYPE_P(code) != IS_STRING) { - code_str = xdstrdup(""); - } - - if (Z_TYPE_P(message) != IS_STRING) { - message = NULL; - } - - convert_to_string_ex(file); - convert_to_long_ex(line); - - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - xdebug_develop_throw_exception_hook(exception, file, line, code, code_str, message); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - xdebug_debugger_throw_exception_hook(exception, file, line, code, code_str, message); - } - - /* Free code_str if necessary */ - if (code_str) { - xdfree(code_str); - } -} - -void xdebug_base_use_xdebug_throw_exception_hook(void) -{ - zend_throw_exception_hook = xdebug_throw_exception_hook; -} - -/* {{{ proto void xdebug_set_time_limit(void) - Dummy function to prevent time limit from being set within the script */ -PHP_FUNCTION(xdebug_set_time_limit) -{ - if (!xdebug_is_debug_connection_active()) { - XG_BASE(orig_set_time_limit_func)(INTERNAL_FUNCTION_PARAM_PASSTHRU); - } - - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto int xdebug_error_reporting(void) - Dummy function to return original error reporting level when 'eval' has turned it into 0 */ -PHP_FUNCTION(xdebug_error_reporting) -{ - if (ZEND_NUM_ARGS() == 0 && XG_BASE(error_reporting_overridden) && xdebug_is_debug_connection_active()) { - RETURN_LONG(XG_BASE(error_reporting_override)); - } - XG_BASE(orig_error_reporting_func)(INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto void xdebug_pcntl_exec(void) - Dummy function to stop profiling when we run pcntl_exec */ -PHP_FUNCTION(xdebug_pcntl_exec) -{ - /* We need to stop the profiler and trace files here */ - xdebug_profiler_pcntl_exec_handler(); - - XG_BASE(orig_pcntl_exec_func)(INTERNAL_FUNCTION_PARAM_PASSTHRU); -} -/* }}} */ - -/* {{{ proto int xdebug_pcntl_fork(void) - Dummy function to set a new connection when forking a process */ -PHP_FUNCTION(xdebug_pcntl_fork) -{ - XG_BASE(orig_pcntl_fork_func)(INTERNAL_FUNCTION_PARAM_PASSTHRU); - - xdebug_debugger_restart_if_pid_changed(); -} -/* }}} */
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/base/base_globals.h
Deleted
@@ -1,85 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __XDEBUG_BASE_GLOBALS_H__ -#define __XDEBUG_BASE_GLOBALS_H__ - -#include "lib/hash.h" -#include "lib/llist.h" -#include "lib/vector.h" - - -#if PHP_WIN32 -typedef void (WINAPI *WIN_PRECISE_TIME_FUNC)(LPFILETIME); -#endif - -typedef struct _xdebug_nanotime_context { - uint64_t start_abs; - uint64_t last_abs; -#if PHP_WIN32 | HAVE_XDEBUG_CLOCK_GETTIME | HAVE_XDEBUG_CLOCK_GETTIME_NSEC_NP - uint64_t start_rel; - uint64_t last_rel; - int use_rel_time; -#endif -#if PHP_WIN32 - WIN_PRECISE_TIME_FUNC win_precise_time_func; - uint64_t win_freq; -#endif -} xdebug_nanotime_context; - - -typedef struct _xdebug_base_globals_t { - xdebug_vector *stack; -#if PHP_VERSION_ID >= 80100 - xdebug_hash *fiber_stacks; -#endif - xdebug_nanotime_context nanotime_context; - uint64_t start_nanotime; - unsigned int prev_memory; - zif_handler orig_set_time_limit_func; - zif_handler orig_error_reporting_func; - zif_handler orig_pcntl_exec_func; - zif_handler orig_pcntl_fork_func; - int output_is_tty; - zend_bool in_debug_info; - zend_long error_reporting_override; - zend_bool error_reporting_overridden; - unsigned int function_count; - zend_string *last_eval_statement; - char *last_exception_trace; - - /* in-execution checking */ - zend_bool in_execution; - zend_bool in_var_serialisation; - - /* filters */ - zend_long filter_type_code_coverage; - zend_long filter_type_stack; - zend_long filter_type_tracing; - xdebug_llist *filters_code_coverage; - xdebug_llist *filters_stack; - xdebug_llist *filters_tracing; - - /* PHP versions */ - const char *php_version_compile_time; - const char *php_version_run_time; -} xdebug_base_globals_t; - -typedef struct _xdebug_base_settings_t { - zend_long max_nesting_level; -} xdebug_base_settings_t; - -#endif // __XDEBUG_BASE_GLOBALS_H__
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/base/filter.h
Deleted
@@ -1,42 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ -#ifndef XDEBUG_FILTER_H -#define XDEBUG_FILTER_H - -#include "php.h" -#include "php_xdebug.h" - -int xdebug_is_stack_frame_filtered(int filter_type, function_stack_entry *fse); -int xdebug_is_top_stack_frame_filtered(int filter_type); -void xdebug_filter_register_constants(INIT_FUNC_ARGS); -void xdebug_filter_run(function_stack_entry *fse); -void xdebug_filter_run_code_coverage(zend_op_array *op_array); -void xdebug_filter_run_internal(function_stack_entry *fse, int group, unsigned char *filtered_flag, int type, xdebug_llist *filters); - -#define XDEBUG_FILTER_NONE 0x000 -#define XDEBUG_FILTER_CODE_COVERAGE 0x100 -#define XDEBUG_FILTER_STACK 0x200 -#define XDEBUG_FILTER_TRACING 0x300 - -#define XDEBUG_PATH_INCLUDE 0x01 -#define XDEBUG_PATH_EXCLUDE 0x02 -#define XDEBUG_NAMESPACE_INCLUDE 0x11 -#define XDEBUG_NAMESPACE_EXCLUDE 0x12 - -PHP_FUNCTION(xdebug_set_filter); - -#endif -
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/coverage/branch_info.c
Deleted
@@ -1,479 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright (c) 1997-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to the 2-Clause BSD license which is | - | available through the LICENSE file, or online at | - | http://opensource.org/licenses/bsd-license.php | - +----------------------------------------------------------------------+ - */ -#include <stdlib.h> -#include <math.h> - -#include "php_xdebug.h" -#include "code_coverage_private.h" - -#include "lib/hash.h" -#include "lib/log.h" -#include "lib/str.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -xdebug_branch_info *xdebug_branch_info_create(unsigned int size) -{ - xdebug_branch_info *tmp; - - tmp = calloc(1, sizeof(xdebug_branch_info)); - tmp->size = size; - tmp->branches = calloc(size, sizeof(xdebug_branch)); - tmp->entry_points = xdebug_set_create(size); - tmp->starts = xdebug_set_create(size); - tmp->ends = xdebug_set_create(size); - - tmp->path_info.paths_count = 0; - tmp->path_info.paths_size = 0; - tmp->path_info.paths = NULL; - - return tmp; -} - -void xdebug_branch_info_free(xdebug_branch_info *branch_info) -{ - unsigned int i; - - for (i = 0; i < branch_info->path_info.paths_count; i++) { - free(branch_info->path_info.pathsi->elements); - free(branch_info->path_info.pathsi); - } - free(branch_info->path_info.paths); - xdebug_hash_destroy(branch_info->path_info.path_hash); - free(branch_info->branches); - xdebug_set_free(branch_info->entry_points); - xdebug_set_free(branch_info->starts); - xdebug_set_free(branch_info->ends); - free(branch_info); -} - -void xdebug_branch_info_update(xdebug_branch_info *branch_info, unsigned int pos, unsigned int lineno, unsigned int outidx, unsigned int jump_pos) -{ - xdebug_set_add(branch_info->ends, pos); - if (outidx < XDEBUG_BRANCH_MAX_OUTS) { - branch_info->branchespos.outsoutidx = jump_pos; - if (outidx + 1 > branch_info->branchespos.outs_count) { - branch_info->branchespos.outs_count = outidx + 1; - } - } - branch_info->branchespos.start_lineno = lineno; -} - -static void only_leave_first_catch(zend_op_array *opa, xdebug_branch_info *branch_info, int position) -{ - unsigned int exit_jmp; -#if PHP_VERSION_ID >= 70300 && ZEND_USE_ABS_JMP_ADDR - zend_op *base_address = &(opa->opcodes0); -#endif - - if (opa->opcodesposition.opcode == ZEND_FETCH_CLASS) { - position++; - } - - if (opa->opcodesposition.opcode != ZEND_CATCH) { - return; - } - - xdebug_set_remove(branch_info->entry_points, position); - -#if PHP_VERSION_ID >= 70300 - if (opa->opcodesposition.extended_value & ZEND_LAST_CATCH) { - return; - } - exit_jmp = XDEBUG_ZNODE_JMP_LINE(opa->opcodesposition.op2, position, base_address); -#else - if (opa->opcodesposition.result.num) { - return; - } - exit_jmp = position + ((signed int) opa->opcodesposition.extended_value / sizeof(zend_op)); -#endif - - if (opa->opcodesexit_jmp.opcode == ZEND_FETCH_CLASS) { - exit_jmp++; - } - if (opa->opcodesexit_jmp.opcode == ZEND_CATCH) { - only_leave_first_catch(opa, branch_info, exit_jmp); - } -} - -void xdebug_branch_post_process(zend_op_array *opa, xdebug_branch_info *branch_info) -{ - unsigned int i; - int in_branch = 0, last_start = -1; -#if PHP_VERSION_ID >= 70300 && ZEND_USE_ABS_JMP_ADDR - zend_op *base_address = &(opa->opcodes0); -#endif - - /* Figure out which CATCHes are chained, and hence which ones should be - * considered entry points */ - for (i = 0; i < branch_info->entry_points->size; i++) { - if (xdebug_set_in(branch_info->entry_points, i) && opa->opcodesi.opcode == ZEND_CATCH) { -#if PHP_VERSION_ID >= 70300 -# if ZEND_USE_ABS_JMP_ADDR - if (opa->opcodesi.op2.jmp_addr != NULL) { -# else - if (opa->opcodesi.op2.jmp_offset != 0) { -# endif - only_leave_first_catch(opa, branch_info, XDEBUG_ZNODE_JMP_LINE(opa->opcodesi.op2, i, base_address)); - } -#else - only_leave_first_catch(opa, branch_info, i + ((signed int) opa->opcodesi.extended_value / sizeof(zend_op))); -#endif - } - } - - for (i = 0; i < branch_info->starts->size; i++) { - if (xdebug_set_in(branch_info->starts, i)) { - if (in_branch) { - branch_info->brancheslast_start.outs_count = 1; - branch_info->brancheslast_start.outs0 = i; - branch_info->brancheslast_start.end_op = i-1; - branch_info->brancheslast_start.end_lineno = branch_info->branchesi.start_lineno; - } - last_start = i; - in_branch = 1; - } - if (xdebug_set_in(branch_info->ends, i)) { - size_t j; - - for (j = 0; j < branch_info->branchesi.outs_count; j++) { - branch_info->brancheslast_start.outsj = branch_info->branchesi.outsj; - } - branch_info->brancheslast_start.outs_count = branch_info->branchesi.outs_count; - branch_info->brancheslast_start.end_op = i; - branch_info->brancheslast_start.end_lineno = branch_info->branchesi.start_lineno; - in_branch = 0; - } - } -} - -static void xdebug_path_add(xdebug_path *path, unsigned int nr) -{ - if (!path) { - return; - } - if (path->elements_count == path->elements_size) { - path->elements_size += 32; - path->elements = realloc(path->elements, sizeof(unsigned int) * path->elements_size); - } - path->elementspath->elements_count = nr; - path->elements_count++; -} - -static void xdebug_path_info_add_path(xdebug_path_info *path_info, xdebug_path *path) -{ - if (path_info->paths_count == path_info->paths_size) { - path_info->paths_size += 32; - path_info->paths = realloc(path_info->paths, sizeof(xdebug_path*) * path_info->paths_size); - } - path_info->pathspath_info->paths_count = path; - path_info->paths_count++; -} - -static void xdebug_path_info_make_sure_level_exists(xdebug_path_info *path_info, unsigned int level) -{ - unsigned int i = 0, orig_size; - - orig_size = path_info->paths_size; - - if (level >= path_info->paths_size) { - path_info->paths_size = level + 32; - path_info->paths = realloc(path_info->paths, sizeof(xdebug_path*) * path_info->paths_size); - - for (i = orig_size; i < XG_COV(branches).size; i++) { - XG_COV(branches).last_branch_nri = -1; - } - - for (i = orig_size; i < path_info->paths_size; i++) { - path_info->pathsi = NULL; - } - } -} - -void xdebug_path_info_add_path_for_level(xdebug_path_info *path_info, xdebug_path *path, unsigned int level) -{ - xdebug_path_info_make_sure_level_exists(path_info, level); - path_info->pathslevel = path; -} - -xdebug_path *xdebug_path_info_get_path_for_level(xdebug_path_info *path_info, unsigned int level) -{ - xdebug_path_info_make_sure_level_exists(path_info, level); - return path_info->pathslevel; -} - -xdebug_path *xdebug_path_new(xdebug_path *old_path) -{ - xdebug_path *tmp; - tmp = calloc(1, sizeof(xdebug_path)); - - if (old_path) { - unsigned i; - - for (i = 0; i < old_path->elements_count; i++) { - xdebug_path_add(tmp, old_path->elementsi); - } - } - return tmp; -} - -void xdebug_path_free(xdebug_path *path) -{ - if (path->elements) { - free(path->elements); - } - free(path); -} - -static unsigned int xdebug_branch_find_last_element(xdebug_path *path) -{ - return path->elementspath->elements_count-1; -} - -static int xdebug_path_exists(xdebug_path *path, unsigned int elem1, unsigned int elem2) -{ - unsigned int i; - - for (i = 0; i < path->elements_count - 1; i++) { - if (path->elementsi == elem1 && path->elementsi + 1 == elem2) { - return 1; - } - } - return 0; -} - -static void xdebug_branch_find_path(unsigned int nr, xdebug_branch_info *branch_info, xdebug_path *prev_path) -{ - unsigned int last; - xdebug_path *new_path; - int found = 0; - size_t i = 0; - - if (branch_info->path_info.paths_count > 4095) { - return; - } - - new_path = xdebug_path_new(prev_path); - xdebug_path_add(new_path, nr); - - last = xdebug_branch_find_last_element(new_path); - - for (i = 0; i < branch_info->branchesnr.outs_count; i++) { - int out = branch_info->branchesnr.outsi; - if (out != 0 && out != XDEBUG_JMP_EXIT && !xdebug_path_exists(new_path, last, out)) { - xdebug_branch_find_path(out, branch_info, new_path); - found = 1; - } - } - - if (found) { - xdebug_path_free(new_path); - return; - } - - xdebug_path_info_add_path(&(branch_info->path_info), new_path); -} - -xdebug_path_info *xdebug_path_info_ctor(void) -{ - xdebug_path_info *tmp; - - tmp = xdmalloc(sizeof(xdebug_path_info)); - tmp->paths_count = 0; - tmp->paths_size = 0; - tmp->paths = NULL; - tmp->path_hash = NULL; - - return tmp; -} - -void xdebug_path_info_dtor(xdebug_path_info *path_info) -{ - unsigned int i; - - for (i = 0; i < path_info->paths_count; i++) { - xdebug_path_free(path_info->pathsi); - } - xdfree(path_info->paths); - path_info->paths = NULL; - if (path_info->path_hash) { - xdebug_hash_destroy(path_info->path_hash); - path_info->path_hash = NULL; - } - - xdfree(path_info); -} - -void xdebug_create_key_for_path(xdebug_path *path, xdebug_str *str) -{ - unsigned int i; - char temp_nr16; - - for (i = 0; i < path->elements_count; i++) { - snprintf(temp_nr, 15, "%u:", path->elementsi); - xdebug_str_add(str, temp_nr, 0); - } -} - -void xdebug_branch_find_paths(xdebug_branch_info *branch_info) -{ - unsigned int i; - - for (i = 0; i < branch_info->entry_points->size; i++) { - if (xdebug_set_in(branch_info->entry_points, i)) { - xdebug_branch_find_path(i, branch_info, NULL); - } - } - - branch_info->path_info.path_hash = xdebug_hash_alloc(128, NULL); - - for (i = 0; i < branch_info->path_info.paths_count; i++) { - xdebug_str str = XDEBUG_STR_INITIALIZER; - xdebug_create_key_for_path(branch_info->path_info.pathsi, &str); - xdebug_hash_add(branch_info->path_info.path_hash, str.d, str.l, branch_info->path_info.pathsi); - xdfree(str.d); - } -} - -void xdebug_branch_info_mark_reached(zend_string *filename, char *function_name, zend_op_array *op_array, long opcode_nr) -{ - xdebug_coverage_file *file; - xdebug_coverage_function *function; - xdebug_branch_info *branch_info; - - if (XG_COV(previous_mark_filename) && zend_string_equals(XG_COV(previous_mark_filename), filename)) { - file = XG_COV(previous_mark_file); - } else { - if (!xdebug_hash_find(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &file)) { - return; - } - if (XG_COV(previous_mark_filename)) { - zend_string_release(XG_COV(previous_mark_filename)); - } - XG_COV(previous_mark_filename) = zend_string_copy(file->name); - XG_COV(previous_mark_file) = file; - } - - /* If there is no branch info, we don't have to do more */ - if (!file->has_branch_info) { - return; - } - - /* Check if the function already exists in the hash */ - if (!xdebug_hash_find(file->functions, function_name, strlen(function_name), (void *) &function)) { - return; - } - - branch_info = function->branch_info; - - if (opcode_nr != 0 && xdebug_set_in(branch_info->entry_points, opcode_nr)) { - xdebug_code_coverage_end_of_function(op_array, filename, function_name); - xdebug_code_coverage_start_of_function(op_array, function_name); - } - - if (xdebug_set_in(branch_info->starts, opcode_nr)) { - char *key; - void *dummy; - function_stack_entry *tail_fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - - /* Mark out for previous branch, if one is set */ - if (XG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)) != -1) { - size_t i = 0; - - for (i = 0; i < branch_info->branchesXG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)).outs_count; i++) { - if (branch_info->branchesXG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)).outsi == opcode_nr) { - branch_info->branchesXG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)).outs_hiti = 1; - } - } - } - - key = xdebug_sprintf("%d:%d:%d", opcode_nr, XG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)), tail_fse->function_nr); - - if (!xdebug_hash_find(XG_COV(visited_branches), key, strlen(key), (void*) &dummy)) { - xdebug_path_add(XG_COV(paths_stack)->pathsXDEBUG_VECTOR_COUNT(XG_BASE(stack)), opcode_nr); - xdebug_hash_add(XG_COV(visited_branches), key, strlen(key), NULL); - } - xdfree(key); - - branch_info->branchesopcode_nr.hit = 1; - - XG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)) = opcode_nr; - } -} - -void xdebug_branch_info_mark_end_of_function_reached(zend_string *filename, char *function_name, char *key, int key_len) -{ - xdebug_coverage_file *file; - xdebug_coverage_function *function; - xdebug_branch_info *branch_info; - xdebug_path *path; - - if (XG_COV(previous_mark_filename) && zend_string_equals(XG_COV(previous_mark_filename), filename) == 0) { - file = XG_COV(previous_mark_file); - } else { - if (!xdebug_hash_find(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &file)) { - return; - } - zend_string_release(XG_COV(previous_mark_filename)); - XG_COV(previous_mark_filename) = zend_string_copy(file->name); - XG_COV(previous_mark_file) = file; - } - - /* If there is no branch info, we don't have to do more */ - if (!file->has_branch_info) { - return; - } - - /* Check if the function already exists in the hash */ - if (!xdebug_hash_find(file->functions, function_name, strlen(function_name), (void *) &function)) { - return; - } - - branch_info = function->branch_info; - - if (!xdebug_hash_find(branch_info->path_info.path_hash, key, key_len, (void *) &path)) { - return; - } - path->hit = 1; -} - -void xdebug_branch_info_add_branches_and_paths(zend_string *filename, char *function_name, xdebug_branch_info *branch_info) -{ - xdebug_coverage_file *file; - xdebug_coverage_function *function; - - if (XG_COV(previous_filename) && zend_string_equals(XG_COV(previous_filename), filename) == 0) { - file = XG_COV(previous_file); - } else { - /* Check if the file already exists in the hash */ - if (!xdebug_hash_find(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &file)) { - /* The file does not exist, so we add it to the hash */ - file = xdebug_coverage_file_ctor(filename); - - xdebug_hash_add(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), file); - } - zend_string_release(XG_COV(previous_filename)); - XG_COV(previous_filename) = zend_string_copy(file->name); - XG_COV(previous_file) = file; - } - - /* Check if the function already exists in the hash */ - if (!xdebug_hash_find(file->functions, function_name, strlen(function_name), (void *) &function)) { - /* The file does not exist, so we add it to the hash */ - function = xdebug_coverage_function_ctor(function_name); - - xdebug_hash_add(file->functions, function_name, strlen(function_name), function); - } - - if (branch_info) { - file->has_branch_info = 1; - } - function->branch_info = branch_info; -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/coverage/code_coverage.c
Deleted
@@ -1,1224 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "php_xdebug.h" -#include "zend_extensions.h" - -#include "branch_info.h" -#include "code_coverage_private.h" - -#include "base/base.h" -#include "base/filter.h" -#include "lib/compat.h" -#include "lib/set.h" -#include "lib/var.h" -#include "tracing/tracing.h" - -/* True globals */ -int zend_xdebug_filter_offset = -1; -int zend_xdebug_cc_run_offset = -1; - -extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); - -static void xdebug_coverage_line_dtor(void *data) -{ - xdebug_coverage_line *line = (xdebug_coverage_line *) data; - - xdfree(line); -} - -xdebug_coverage_file *xdebug_coverage_file_ctor(zend_string *filename) -{ - xdebug_coverage_file *file; - - file = xdmalloc(sizeof(xdebug_coverage_file)); - file->name = zend_string_copy(filename); - file->lines = xdebug_hash_alloc(128, xdebug_coverage_line_dtor); - file->functions = xdebug_hash_alloc(128, xdebug_coverage_function_dtor); - file->has_branch_info = 0; - - return file; -} - -static void xdebug_coverage_file_dtor(void *data) -{ - xdebug_coverage_file *file = (xdebug_coverage_file *) data; - - xdebug_hash_destroy(file->lines); - xdebug_hash_destroy(file->functions); - zend_string_release(file->name); - xdfree(file); -} - -xdebug_coverage_function *xdebug_coverage_function_ctor(char *function_name) -{ - xdebug_coverage_function *function; - - function = xdmalloc(sizeof(xdebug_coverage_function)); - function->name = xdstrdup(function_name); - function->branch_info = NULL; - - return function; -} - -void xdebug_coverage_function_dtor(void *data) -{ - xdebug_coverage_function *function = (xdebug_coverage_function *) data; - - if (function->branch_info) { - xdebug_branch_info_free(function->branch_info); - } - xdfree(function->name); - xdfree(function); -} - -static void xdebug_func_format(char *buffer, size_t buffer_size, xdebug_func *func) -{ - if (func->type == XFUNC_NORMAL) { - int len = strlen(func->function); - - if (len + 1 > buffer_size) { - goto error; - } - memcpy(buffer, func->function, len); - bufferlen = '\0'; - return; - } - - if (func->type == XFUNC_MEMBER) { - int func_len = strlen(func->function); - int len = ZSTR_LEN(func->object_class) + 2 + func_len; - - if (len + 1 > buffer_size) { - goto error; - } - memcpy(buffer, ZSTR_VAL(func->object_class), ZSTR_LEN(func->object_class)); - memcpy(buffer + ZSTR_LEN(func->object_class), "->", 2); - memcpy(buffer + ZSTR_LEN(func->object_class) + 2, func->function, func_len); - bufferlen = '\0'; - return; - } - -error: - memcpy(buffer, "?", 1); - buffer1 = '\0'; -} - -static void xdebug_build_fname_from_oparray(xdebug_func *tmp, zend_op_array *opa) -{ - int wrapped = 0; - - memset(tmp, 0, sizeof(xdebug_func)); - - if (opa->function_name) { - if (opa->fn_flags & ZEND_ACC_CLOSURE) { - tmp->function = xdebug_wrap_closure_location_around_function_name(opa, STR_NAME_VAL(opa->function_name)); - wrapped = 1; -#if PHP_VERSION_ID >= 70400 - } else if ( - opa->fn_flags & ZEND_ACC_TRAIT_CLONE - || (opa->scope && opa->scope->ce_flags & ZEND_ACC_TRAIT) - ) { - tmp->function = xdebug_wrap_location_around_function_name("trait-method", opa, STR_NAME_VAL(opa->function_name)); - wrapped = 1; -#endif - } else { - tmp->function = xdstrdup(STR_NAME_VAL(opa->function_name)); - } - } else { - tmp->function = xdstrdup("{main}"); - tmp->type = XFUNC_MAIN; - } - - if (opa->scope && !wrapped) { - tmp->type = XFUNC_MEMBER; - tmp->object_class = zend_string_copy(opa->scope->name); - } else { - tmp->type = XFUNC_NORMAL; - } -} - -static void xdebug_print_opcode_info(zend_execute_data *execute_data, const zend_op *cur_opcode) -{ - zend_op_array *op_array = &execute_data->func->op_array; - xdebug_func func_info; - char function_name1024; - long opnr = execute_data->opline - execute_data->func->op_array.opcodes; - - xdebug_build_fname_from_oparray(&func_info, op_array); - xdebug_func_format(function_name, sizeof(function_name), &func_info); - if (func_info.object_class) { - zend_string_release(func_info.object_class); - } - if (func_info.scope_class) { - zend_string_release(func_info.scope_class); - } - if (func_info.function) { - xdfree(func_info.function); - } - - xdebug_branch_info_mark_reached(op_array->filename, function_name, op_array, opnr); -} - -static int xdebug_check_branch_entry_handler(XDEBUG_OPCODE_HANDLER_ARGS) -{ - zend_op_array *op_array = &execute_data->func->op_array; - const zend_op *cur_opcode = execute_data->opline; - - if (!op_array->reservedXG_COV(code_coverage_filter_offset) && XG_COV(code_coverage_active)) { - xdebug_print_opcode_info(execute_data, cur_opcode); - } - - return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); -} - -static void xdebug_count_line(zend_string *filename, int lineno, int executable, int deadcode) -{ - xdebug_coverage_file *file; - xdebug_coverage_line *line; - - if (XG_COV(previous_filename) && zend_string_equals(XG_COV(previous_filename), filename)) { - file = XG_COV(previous_file); - } else { - /* Check if the file already exists in the hash */ - if (!xdebug_hash_find(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &file)) { - /* The file does not exist, so we add it to the hash */ - file = xdebug_coverage_file_ctor(filename); - - xdebug_hash_add(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), file); - } - if (XG_COV(previous_filename)) { - zend_string_release(XG_COV(previous_filename)); - } - XG_COV(previous_filename) = zend_string_copy(file->name); - XG_COV(previous_file) = file; - } - - /* Check if the line already exists in the hash */ - if (!xdebug_hash_index_find(file->lines, lineno, (void *) &line)) { - line = xdmalloc(sizeof(xdebug_coverage_line)); - line->lineno = lineno; - line->count = 0; - line->executable = 0; - - xdebug_hash_index_add(file->lines, lineno, line); - } - - if (executable) { - if (line->executable != 1 && deadcode) { - line->executable = 2; - } else { - line->executable = 1; - } - } else { - line->count++; - } -} - -static int xdebug_common_override_handler(XDEBUG_OPCODE_HANDLER_ARGS) -{ - zend_op_array *op_array = &execute_data->func->op_array; - const zend_op *cur_opcode = execute_data->opline; - - if (!op_array->reservedXG_COV(code_coverage_filter_offset) && XG_COV(code_coverage_active)) { - int lineno; - - lineno = cur_opcode->lineno; - - xdebug_print_opcode_info(execute_data, cur_opcode); - xdebug_count_line(op_array->filename, lineno, 0, 0); - } - - return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); -} - -static int xdebug_coverage_include_or_eval_handler(XDEBUG_OPCODE_HANDLER_ARGS) -{ - zend_op_array *op_array = &execute_data->func->op_array; - const zend_op *opline = execute_data->opline; - - xdebug_coverage_record_if_active(execute_data, op_array); - - return xdebug_call_original_opcode_handler_if_set(opline->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); -} - -static void prefill_from_opcode(zend_string *filename, zend_op opcode, int deadcode) -{ - if ( - opcode.opcode != ZEND_NOP && - opcode.opcode != ZEND_EXT_NOP && - opcode.opcode != ZEND_RECV && - opcode.opcode != ZEND_RECV_INIT -#if PHP_VERSION_ID < 70400 - && opcode.opcode != ZEND_VERIFY_ABSTRACT_CLASS - && opcode.opcode != ZEND_ADD_INTERFACE -#endif - && opcode.opcode != ZEND_OP_DATA - && opcode.opcode != ZEND_TICKS - && opcode.opcode != ZEND_FAST_CALL - && opcode.opcode != ZEND_RECV_VARIADIC - ) { - xdebug_count_line(filename, opcode.lineno, 1, deadcode); - } -} - -#define XDEBUG_ZNODE_ELEM(node,var) node.var - -static int xdebug_find_jumps(zend_op_array *opa, unsigned int position, size_t *jump_count, int *jumps) -{ -#if ZEND_USE_ABS_JMP_ADDR - zend_op *base_address = &(opa->opcodes0); -#endif - - zend_op opcode = opa->opcodesposition; - if (opcode.opcode == ZEND_JMP) { - jumps0 = XDEBUG_ZNODE_JMP_LINE(opcode.op1, position, base_address); - *jump_count = 1; - return 1; - - } else if ( - opcode.opcode == ZEND_JMPZ || - opcode.opcode == ZEND_JMPNZ || - opcode.opcode == ZEND_JMPZ_EX || - opcode.opcode == ZEND_JMPNZ_EX - ) { - jumps0 = position + 1; - jumps1 = XDEBUG_ZNODE_JMP_LINE(opcode.op2, position, base_address); - *jump_count = 2; - return 1; - - } else if (opcode.opcode == ZEND_JMPZNZ) { - jumps0 = XDEBUG_ZNODE_JMP_LINE(opcode.op2, position, base_address); - jumps1 = position + ((int32_t) opcode.extended_value / (int32_t) sizeof(zend_op)); - *jump_count = 2; - return 1; - - } else if (opcode.opcode == ZEND_FE_FETCH_R || opcode.opcode == ZEND_FE_FETCH_RW) { - jumps0 = position + 1; - jumps1 = position + (opcode.extended_value / sizeof(zend_op)); - *jump_count = 2; - return 1; - - } else if (opcode.opcode == ZEND_FE_RESET_R || opcode.opcode == ZEND_FE_RESET_RW) { - jumps0 = position + 1; - jumps1 = XDEBUG_ZNODE_JMP_LINE(opcode.op2, position, base_address); - *jump_count = 2; - return 1; - - } else if (opcode.opcode == ZEND_CATCH) { - *jump_count = 2; - jumps0 = position + 1; -#if PHP_VERSION_ID >= 70300 - if (!(opcode.extended_value & ZEND_LAST_CATCH)) { - jumps1 = XDEBUG_ZNODE_JMP_LINE(opcode.op2, position, base_address); -#else - if (!opcode.result.num) { - jumps1 = position + (opcode.extended_value / sizeof(zend_op)); -#endif - if (jumps1 == jumps0) { - jumps1 = XDEBUG_JMP_NOT_SET; - *jump_count = 1; - } - } else { - jumps1 = XDEBUG_JMP_EXIT; - } - return 1; - - } else if (opcode.opcode == ZEND_GOTO) { - jumps0 = XDEBUG_ZNODE_JMP_LINE(opcode.op1, position, base_address); - *jump_count = 1; - return 1; - - } else if (opcode.opcode == ZEND_FAST_CALL) { - jumps0 = XDEBUG_ZNODE_JMP_LINE(opcode.op1, position, base_address); - jumps1 = position + 1; - *jump_count = 2; - return 1; - - } else if (opcode.opcode == ZEND_FAST_RET) { - jumps0 = XDEBUG_JMP_EXIT; - *jump_count = 1; - return 1; - - } else if ( - opcode.opcode == ZEND_GENERATOR_RETURN || - opcode.opcode == ZEND_EXIT || - opcode.opcode == ZEND_THROW || -#if PHP_VERSION_ID >= 80000 - opcode.opcode == ZEND_MATCH_ERROR || -#endif - opcode.opcode == ZEND_RETURN - ) { - jumps0 = XDEBUG_JMP_EXIT; - *jump_count = 1; - return 1; - } else if ( -# if PHP_VERSION_ID >= 80000 - opcode.opcode == ZEND_MATCH || -# endif - opcode.opcode == ZEND_SWITCH_LONG || - opcode.opcode == ZEND_SWITCH_STRING - ) { - zval *array_value; - HashTable *myht; - zval *val; - -# if PHP_VERSION_ID >= 70300 - array_value = RT_CONSTANT(&opa->opcodesposition, opcode.op2); -# else - array_value = RT_CONSTANT_EX(opa->literals, opcode.op2); -# endif - myht = Z_ARRVAL_P(array_value); - - /* All 'case' statements */ - ZEND_HASH_FOREACH_VAL_IND(myht, val) { - if (*jump_count < XDEBUG_BRANCH_MAX_OUTS - 2) { - jumps*jump_count = position + (val->value.lval / sizeof(zend_op)); - (*jump_count)++; - } - } ZEND_HASH_FOREACH_END(); - - /* The 'default' case */ - jumps*jump_count = position + (opcode.extended_value / sizeof(zend_op)); - (*jump_count)++; - -# if PHP_VERSION_ID >= 80000 - if (opcode.opcode != ZEND_MATCH) { -# endif - /* The 'next' opcode */ - jumps*jump_count = position + 1; - (*jump_count)++; -# if PHP_VERSION_ID >= 80000 - } -# endif - - return 1; - } - - return 0; -} - -static void xdebug_analyse_branch(zend_op_array *opa, unsigned int position, xdebug_set *set, xdebug_branch_info *branch_info) -{ - /* fprintf(stderr, "Branch analysis from position: %d\n", position); */ - - if (branch_info) { - xdebug_set_add(branch_info->starts, position); - branch_info->branchesposition.start_lineno = opa->opcodesposition.lineno; - } - - /* First we see if the branch has been visited, if so we bail out. */ - if (xdebug_set_in(set, position)) { - return; - } - - /* fprintf(stderr, "XDEBUG Adding %d\n", position); */ - /* Loop over the opcodes until the end of the array, or until a jump point has been found */ - xdebug_set_add(set, position); - while (position < opa->last) { - size_t jump_count = 0; - int jumpsXDEBUG_BRANCH_MAX_OUTS; - size_t i; - - /* See if we have a jump instruction */ - if (xdebug_find_jumps(opa, position, &jump_count, jumps)) { - for (i = 0; i < jump_count; i++) { - if (jumpsi == XDEBUG_JMP_EXIT || jumpsi != XDEBUG_JMP_NOT_SET) { - if (branch_info) { - xdebug_branch_info_update(branch_info, position, opa->opcodesposition.lineno, i, jumpsi); - } - if (jumpsi != XDEBUG_JMP_EXIT) { - xdebug_analyse_branch(opa, jumpsi, set, branch_info); - } - } - } - break; - } - - /* See if we have a throw instruction */ - if (opa->opcodesposition.opcode == ZEND_THROW) { - /* fprintf(stderr, "Throw found at %d\n", position); */ - if (branch_info) { - xdebug_set_add(branch_info->ends, position); - branch_info->branchesposition.start_lineno = opa->opcodesposition.lineno; - } - break; - } - - /* See if we have an exit instruction */ - if (opa->opcodesposition.opcode == ZEND_EXIT) { - /* fprintf(stderr, "X* Return found\n"); */ - if (branch_info) { - xdebug_set_add(branch_info->ends, position); - branch_info->branchesposition.start_lineno = opa->opcodesposition.lineno; - } - break; - } - /* See if we have a return instruction */ - if ( - opa->opcodesposition.opcode == ZEND_RETURN - || opa->opcodesposition.opcode == ZEND_RETURN_BY_REF - ) { - /*(fprintf(stderr, "XDEBUG Return found\n");)*/ - if (branch_info) { - xdebug_set_add(branch_info->ends, position); - branch_info->branchesposition.start_lineno = opa->opcodesposition.lineno; - } - break; - } - - position++; - /*(fprintf(stderr, "XDEBUG Adding %d\n", position);)*/ - xdebug_set_add(set, position); - } -} - -static void xdebug_analyse_oparray(zend_op_array *opa, xdebug_set *set, xdebug_branch_info *branch_info) -{ - unsigned int position = 0; - - while (position < opa->last) { - if (position == 0) { - xdebug_analyse_branch(opa, position, set, branch_info); - if (branch_info) { - xdebug_set_add(branch_info->entry_points, position); - } - } else if (opa->opcodesposition.opcode == ZEND_CATCH) { - xdebug_analyse_branch(opa, position, set, branch_info); - if (branch_info) { - xdebug_set_add(branch_info->entry_points, position); - } - } - position++; - } - if (branch_info) { - xdebug_set_add(branch_info->ends, opa->last-1); - branch_info->branchesopa->last-1.start_lineno = opa->opcodesopa->last-1.lineno; - } -} - -static void prefill_from_oparray(zend_string *filename, zend_op_array *op_array) -{ - unsigned int i; - xdebug_set *set = NULL; - xdebug_branch_info *branch_info = NULL; - - op_array->reservedXG_COV(dead_code_analysis_tracker_offset) = (void*) XG_COV(dead_code_last_start_id); - - /* Check for abstract methods and simply return from this function in those - * cases. */ - if (op_array->fn_flags & ZEND_ACC_ABSTRACT) { - return; - } - - /* Check whether this function should be filtered out */ - { -/* - function_stack_entry tmp_fse; - tmp_fse.filename = STR_NAME_VAL(op_array->filename); - xdebug_build_fname_from_oparray(&tmp_fse.function, op_array); - printf(" - PREFIL FILTERED FOR %s (%s::%s): %s\n", - tmp_fse.filename, tmp_fse.function.class, tmp_fse.function.function, - op_array->reservedXG_COV(code_coverage_filter_offset) ? "YES" : "NO"); -*/ - if (op_array->reservedXG_COV(code_coverage_filter_offset)) { - return; - } - } - - /* Run dead code analysis if requested */ - if (XG_COV(code_coverage_dead_code_analysis) && (op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO)) { - set = xdebug_set_create(op_array->last); - if (XG_COV(code_coverage_branch_check)) { - branch_info = xdebug_branch_info_create(op_array->last); - } - - xdebug_analyse_oparray(op_array, set, branch_info); - } - - /* The normal loop then finally */ - for (i = 0; i < op_array->last; i++) { - zend_op opcode = op_array->opcodesi; - prefill_from_opcode(filename, opcode, set ? !xdebug_set_in(set, i) : 0); - } - - if (set) { - xdebug_set_free(set); - } - if (branch_info) { - char function_name1024; - xdebug_func func_info; - - xdebug_build_fname_from_oparray(&func_info, op_array); - xdebug_func_format(function_name, sizeof(function_name), &func_info); - - if (func_info.object_class) { - zend_string_release(func_info.object_class); - } - if (func_info.scope_class) { - zend_string_release(func_info.scope_class); - } - if (func_info.function) { - xdfree(func_info.function); - } - - xdebug_branch_post_process(op_array, branch_info); - xdebug_branch_find_paths(branch_info); - xdebug_branch_info_add_branches_and_paths(filename, (char*) function_name, branch_info); - } - -#if PHP_VERSION_ID >= 80100 - if (!op_array->num_dynamic_func_defs) { - return; - } - - for (i = 0; i < op_array->num_dynamic_func_defs; i++) { - prefill_from_oparray(filename, op_array->dynamic_func_defsi); - } -#endif -} - -static int prefill_from_function_table(zend_op_array *opa) -{ - if (opa->type == ZEND_USER_FUNCTION) { - if ((long) opa->reservedXG_COV(dead_code_analysis_tracker_offset) < XG_COV(dead_code_last_start_id)) { - prefill_from_oparray(opa->filename, opa); - } - } - - return ZEND_HASH_APPLY_KEEP; -} - -/* Set correct int format to use */ -#if SIZEOF_ZEND_LONG == 4 -# define XDEBUG_PTR_KEY_LEN 8 -# define XDEBUG_PTR_KEY_FMT "%08X" -#else -# define XDEBUG_PTR_KEY_LEN 16 -# define XDEBUG_PTR_KEY_FMT "%016lX" -#endif - -static int prefill_from_class_table(zend_class_entry *ce) -{ - if (ce->type == ZEND_USER_CLASS) { - zend_op_array *val; - - ZEND_HASH_FOREACH_PTR(&ce->function_table, val) { - prefill_from_function_table(val); - } ZEND_HASH_FOREACH_END(); - } - - return ZEND_HASH_APPLY_KEEP; -} - -static void xdebug_prefill_code_coverage(zend_op_array *op_array) -{ - zend_op_array *function_op_array; - zend_class_entry *class_entry; - - if ((long) op_array->reservedXG_COV(dead_code_analysis_tracker_offset) < XG_COV(dead_code_last_start_id)) { - prefill_from_oparray(op_array->filename, op_array); - } - - ZEND_HASH_REVERSE_FOREACH_PTR(CG(function_table), function_op_array) { - if (_idx == XG_COV(prefill_function_count)) { - break; - } - prefill_from_function_table(function_op_array); - } ZEND_HASH_FOREACH_END(); - XG_COV(prefill_function_count) = CG(function_table)->nNumUsed; - - ZEND_HASH_REVERSE_FOREACH_PTR(CG(class_table), class_entry) { - if (_idx == XG_COV(prefill_class_count)) { - break; - } - prefill_from_class_table(class_entry); - } ZEND_HASH_FOREACH_END(); - XG_COV(prefill_class_count) = CG(class_table)->nNumUsed; -} - -void xdebug_code_coverage_start_of_function(zend_op_array *op_array, char *function_name) -{ - xdebug_path *path = xdebug_path_new(NULL); - - xdebug_prefill_code_coverage(op_array); - xdebug_path_info_add_path_for_level(XG_COV(paths_stack), path, XDEBUG_VECTOR_COUNT(XG_BASE(stack))); - - if (XG_COV(branches).size == 0 || XDEBUG_VECTOR_COUNT(XG_BASE(stack)) >= XG_COV(branches).size) { - XG_COV(branches).size = XDEBUG_VECTOR_COUNT(XG_BASE(stack)) + 32; - XG_COV(branches).last_branch_nr = realloc(XG_COV(branches).last_branch_nr, sizeof(int) * XG_COV(branches.size)); - } - - XG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)) = -1; -} - -void xdebug_code_coverage_end_of_function(zend_op_array *op_array, zend_string *filename, char *function_name) -{ - xdebug_str str = XDEBUG_STR_INITIALIZER; - xdebug_path *path = xdebug_path_info_get_path_for_level(XG_COV(paths_stack), XDEBUG_VECTOR_COUNT(XG_BASE(stack))); - - if (!path || !path->elements) { - return; - } - - xdebug_create_key_for_path(path, &str); - - xdebug_branch_info_mark_end_of_function_reached(filename, function_name, str.d, str.l); - - xdfree(str.d); - - if (path) { - xdebug_path_free(path); - } -} - -PHP_FUNCTION(xdebug_start_code_coverage) -{ - zend_long options = 0; - - if (!XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { - php_error(E_WARNING, "Code coverage needs to be enabled in php.ini by setting 'xdebug.mode' to 'coverage'"); - RETURN_FALSE; - } - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &options) == FAILURE) { - return; - } - - XG_COV(code_coverage_unused) = (options & XDEBUG_CC_OPTION_UNUSED); - XG_COV(code_coverage_dead_code_analysis) = (options & XDEBUG_CC_OPTION_DEAD_CODE); - XG_COV(code_coverage_branch_check) = (options & XDEBUG_CC_OPTION_BRANCH_CHECK); - - XG_COV(code_coverage_active) = 1; - RETURN_TRUE; -} - -PHP_FUNCTION(xdebug_stop_code_coverage) -{ - zend_bool cleanup = 1; - - if (!XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { - RETURN_FALSE; - } - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &cleanup) == FAILURE) { - return; - } - if (!XG_COV(code_coverage_active)) { - RETURN_FALSE; - } - - if (cleanup) { - if (XG_COV(previous_filename)) { - zend_string_release(XG_COV(previous_filename)); - } - XG_COV(previous_filename) = NULL; - XG_COV(previous_file) = NULL; - if (XG_COV(previous_mark_filename)) { - zend_string_release(XG_COV(previous_mark_filename)); - } - XG_COV(previous_mark_filename) = NULL; - XG_COV(previous_mark_file) = NULL; - xdebug_hash_destroy(XG_COV(code_coverage_info)); - XG_COV(code_coverage_info) = xdebug_hash_alloc(32, xdebug_coverage_file_dtor); - XG_COV(dead_code_last_start_id)++; - xdebug_path_info_dtor(XG_COV(paths_stack)); - XG_COV(paths_stack) = xdebug_path_info_ctor(); - } - - XG_COV(code_coverage_active) = 0; - - RETURN_TRUE; -} - -#if PHP_VERSION_ID >= 80000 -static int xdebug_lineno_cmp(Bucket *f, Bucket *s) -{ -#else -static int xdebug_lineno_cmp(const void *a, const void *b) -{ - Bucket *f = (Bucket *) a; - Bucket *s = (Bucket *) b; -#endif - if (f->h < s->h) { - return -1; - } else if (f->h > s->h) { - return 1; - } else { - return 0; - } -} - - -static void add_line(void *ret, xdebug_hash_element *e) -{ - xdebug_coverage_line *line = (xdebug_coverage_line*) e->ptr; - zval *retval = (zval*) ret; - - if (line->executable && (line->count == 0)) { - add_index_long(retval, line->lineno, -line->executable); - } else { - add_index_long(retval, line->lineno, 1); - } -} - -static void add_branches(zval *retval, xdebug_branch_info *branch_info) -{ - zval *branches, *branch, *out, *out_hit; - unsigned int i; - - XDEBUG_MAKE_STD_ZVAL(branches); - array_init(branches); - - for (i = 0; i < branch_info->starts->size; i++) { - if (xdebug_set_in(branch_info->starts, i)) { - size_t j = 0; - - XDEBUG_MAKE_STD_ZVAL(branch); - array_init(branch); - add_assoc_long(branch, "op_start", i); - add_assoc_long(branch, "op_end", branch_info->branchesi.end_op); - add_assoc_long(branch, "line_start", branch_info->branchesi.start_lineno); - add_assoc_long(branch, "line_end", branch_info->branchesi.end_lineno); - - add_assoc_long(branch, "hit", branch_info->branchesi.hit); - - XDEBUG_MAKE_STD_ZVAL(out); - array_init(out); - for (j = 0; j < branch_info->branchesi.outs_count; j++) { - if (branch_info->branchesi.outsj) { - add_index_long(out, j, branch_info->branchesi.outsj); - } - } - add_assoc_zval(branch, "out", out); - - XDEBUG_MAKE_STD_ZVAL(out_hit); - array_init(out_hit); - for (j = 0; j < branch_info->branchesi.outs_count; j++) { - if (branch_info->branchesi.outsj) { - add_index_long(out_hit, j, branch_info->branchesi.outs_hitj); - } - } - add_assoc_zval(branch, "out_hit", out_hit); - - add_index_zval(branches, i, branch); - efree(out_hit); - efree(out); - efree(branch); - } - } - - add_assoc_zval_ex(retval, "branches", HASH_KEY_SIZEOF("branches"), branches); - - efree(branches); -} - -static void add_paths(zval *retval, xdebug_branch_info *branch_info) -{ - zval *paths, *path, *path_container; - unsigned int i, j; - - XDEBUG_MAKE_STD_ZVAL(paths); - array_init(paths); - - for (i = 0; i < branch_info->path_info.paths_count; i++) { - XDEBUG_MAKE_STD_ZVAL(path); - array_init(path); - - XDEBUG_MAKE_STD_ZVAL(path_container); - array_init(path_container); - - for (j = 0; j < branch_info->path_info.pathsi->elements_count; j++) { - add_next_index_long(path, branch_info->path_info.pathsi->elementsj); - } - - add_assoc_zval(path_container, "path", path); - add_assoc_long(path_container, "hit", branch_info->path_info.pathsi->hit); - - add_next_index_zval(paths, path_container); - - efree(path_container); - efree(path); - } - - add_assoc_zval_ex(retval, "paths", HASH_KEY_SIZEOF("paths"), paths); - - efree(paths); -} - -static void add_cc_function(void *ret, xdebug_hash_element *e) -{ - xdebug_coverage_function *function = (xdebug_coverage_function*) e->ptr; - zval *retval = (zval*) ret; - zval *function_info; - - XDEBUG_MAKE_STD_ZVAL(function_info); - array_init(function_info); - - if (function->branch_info) { - add_branches(function_info, function->branch_info); - add_paths(function_info, function->branch_info); - } - - add_assoc_zval_ex(retval, function->name, HASH_KEY_STRLEN(function->name), function_info); - - efree(function_info); -} - -static void add_file(void *ret, xdebug_hash_element *e) -{ - xdebug_coverage_file *file = (xdebug_coverage_file*) e->ptr; - zval *retval = (zval*) ret; - zval *lines, *functions, *file_info; - HashTable *target_hash; - - /* Add all the lines */ - XDEBUG_MAKE_STD_ZVAL(lines); - array_init(lines); - - xdebug_hash_apply(file->lines, (void *) lines, add_line); - - /* Sort on linenumber */ - target_hash = HASH_OF(lines); - zend_hash_sort(target_hash, xdebug_lineno_cmp, 0); - - /* Add the branch and path info */ - if (XG_COV(code_coverage_branch_check)) { - XDEBUG_MAKE_STD_ZVAL(file_info); - array_init(file_info); - - XDEBUG_MAKE_STD_ZVAL(functions); - array_init(functions); - - xdebug_hash_apply(file->functions, (void *) functions, add_cc_function); - - add_assoc_zval_ex(file_info, "lines", HASH_KEY_SIZEOF("lines"), lines); - add_assoc_zval_ex(file_info, "functions", HASH_KEY_SIZEOF("functions"), functions); - - add_assoc_zval_ex(retval, ZSTR_VAL(file->name), ZSTR_LEN(file->name), file_info); - efree(functions); - efree(file_info); - } else { - add_assoc_zval_ex(retval, ZSTR_VAL(file->name), ZSTR_LEN(file->name), lines); - } - - efree(lines); -} - -PHP_FUNCTION(xdebug_get_code_coverage) -{ - array_init(return_value); - - if (!XG_COV(code_coverage_info)) { - return; - } - - xdebug_hash_apply(XG_COV(code_coverage_info), (void *) return_value, add_file); -} - -PHP_FUNCTION(xdebug_get_function_count) -{ - RETURN_LONG(XG_BASE(function_count)); -} - -PHP_FUNCTION(xdebug_code_coverage_started) -{ - RETURN_BOOL(XG_COV(code_coverage_active)); -} - -void xdebug_init_coverage_globals(xdebug_coverage_globals_t *xg) -{ - xg->previous_filename = NULL; - xg->previous_file = NULL; - xg->previous_mark_filename = NULL; - xg->previous_mark_file = NULL; - xg->paths_stack = NULL; - xg->branches.size = 0; - xg->branches.last_branch_nr = NULL; - xg->code_coverage_active = 0; - - /* Get reserved offset */ - xg->dead_code_analysis_tracker_offset = zend_xdebug_cc_run_offset; - xg->dead_code_last_start_id = 1; - xg->code_coverage_filter_offset = zend_xdebug_filter_offset; -} - -void xdebug_coverage_count_line_if_active(zend_op_array *op_array, zend_string *file, int lineno) -{ - if (XG_COV(code_coverage_active) && !op_array->reservedXG_COV(code_coverage_filter_offset)) { - xdebug_count_line(file, lineno, 0, 0); - } -} - -void xdebug_coverage_count_line_if_branch_check_active(zend_op_array *op_array, zend_string *file, int lineno) -{ - if (XG_COV(code_coverage_active) && XG_COV(code_coverage_branch_check)) { - xdebug_coverage_count_line_if_active(op_array, file, lineno); - } -} - -void xdebug_coverage_record_if_active(zend_execute_data *execute_data, zend_op_array *op_array) -{ - if (!op_array->reservedXG_COV(code_coverage_filter_offset) && XG_COV(code_coverage_active)) { - xdebug_print_opcode_info(execute_data, execute_data->opline); - } -} - -void xdebug_coverage_compile_file(zend_op_array *op_array) -{ - if (XG_COV(code_coverage_active) && XG_COV(code_coverage_unused) && (op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO)) { - xdebug_prefill_code_coverage(op_array); - } -} - -int xdebug_coverage_execute_ex(function_stack_entry *fse, zend_op_array *op_array, zend_string **tmp_filename, char **tmp_function_name) -{ - xdebug_func func_info; - - if (!fse->filtered_code_coverage && XG_COV(code_coverage_active) && XG_COV(code_coverage_unused)) { - char buffer1024; - - *tmp_filename = zend_string_copy(op_array->filename); - xdebug_build_fname_from_oparray(&func_info, op_array); - xdebug_func_format(buffer, sizeof(buffer), &func_info); - *tmp_function_name = xdstrdup(buffer); - xdebug_code_coverage_start_of_function(op_array, *tmp_function_name); - - if (func_info.object_class) { - zend_string_release(func_info.object_class); - } - if (func_info.scope_class) { - zend_string_release(func_info.scope_class); - } - if (func_info.function) { - xdfree(func_info.function); - } - return 1; - } - - return 0; -} - -void xdebug_coverage_execute_ex_end(function_stack_entry *fse, zend_op_array *op_array, zend_string *tmp_filename, char *tmp_function_name) -{ - /* Check which path has been used */ - if (!fse->filtered_code_coverage && XG_COV(code_coverage_active) && XG_COV(code_coverage_unused)) { - xdebug_code_coverage_end_of_function(op_array, tmp_filename, tmp_function_name); - } - xdfree(tmp_function_name); - zend_string_release(tmp_filename); -} - -void xdebug_coverage_init_oparray(zend_op_array *op_array) -{ - function_stack_entry tmp_fse; - - if (XG_BASE(filter_type_code_coverage) == XDEBUG_FILTER_NONE) { - op_array->reservedXG_COV(dead_code_analysis_tracker_offset) = 0; - return; - } - - tmp_fse.filename = op_array->filename; - xdebug_build_fname_from_oparray(&tmp_fse.function, op_array); - xdebug_filter_run_internal(&tmp_fse, XDEBUG_FILTER_CODE_COVERAGE, &tmp_fse.filtered_code_coverage, XG_BASE(filter_type_code_coverage), XG_BASE(filters_code_coverage)); - xdebug_func_dtor_by_ref(&tmp_fse.function); - - op_array->reservedXG_COV(code_coverage_filter_offset) = (void*) (size_t) tmp_fse.filtered_code_coverage; -} - -static int xdebug_switch_handler(XDEBUG_OPCODE_HANDLER_ARGS) -{ - const zend_op *cur_opcode = execute_data->opline; - - if (!XG_COV(code_coverage_active)) { - return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); - } - - execute_data->opline++; - return ZEND_USER_OPCODE_CONTINUE; -} - - -void xdebug_coverage_minit(INIT_FUNC_ARGS) -{ - int i; - - /* Get reserved offsets */ -#if PHP_VERSION_ID >= 80000 - zend_xdebug_cc_run_offset = zend_get_resource_handle(XDEBUG_NAME); - zend_xdebug_filter_offset = zend_get_resource_handle(XDEBUG_NAME); -#else - zend_extension dummy_ext; - zend_xdebug_cc_run_offset = zend_get_resource_handle(&dummy_ext); - zend_xdebug_filter_offset = zend_get_resource_handle(&dummy_ext); -#endif - - xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN, xdebug_common_override_handler); - xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_DIM, xdebug_common_override_handler); - xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_OBJ, xdebug_common_override_handler); -#if PHP_VERSION_ID >= 70400 - xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_STATIC_PROP, xdebug_common_override_handler); -#else - xdebug_set_opcode_handler(ZEND_FETCH_STATIC_PROP_W, xdebug_common_override_handler); -#endif - xdebug_register_with_opcode_multi_handler(ZEND_QM_ASSIGN, xdebug_common_override_handler); - xdebug_register_with_opcode_multi_handler(ZEND_INCLUDE_OR_EVAL, xdebug_coverage_include_or_eval_handler); - - /* Overload opcodes for code coverage */ - xdebug_set_opcode_handler(ZEND_JMP, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_JMPZ, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_JMPZ_EX, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_JMPNZ, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_IS_IDENTICAL, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_IS_NOT_IDENTICAL, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_IS_EQUAL, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_IS_NOT_EQUAL, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_IS_SMALLER, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_IS_SMALLER_OR_EQUAL, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_BOOL_NOT, xdebug_common_override_handler); - - xdebug_set_opcode_handler(ZEND_ADD, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_SUB, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_MUL, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_DIV, xdebug_common_override_handler); - - xdebug_set_opcode_handler(ZEND_ADD_ARRAY_ELEMENT, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_RETURN, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_RETURN_BY_REF, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_EXT_STMT, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_SEND_VAR, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_SEND_VAR_NO_REF, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_SEND_VAR_NO_REF_EX, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_SEND_REF, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_SEND_VAL, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_SEND_VAL_EX, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_SEND_VAR_EX, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_NEW, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_EXT_FCALL_BEGIN, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_INIT_METHOD_CALL, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_INIT_STATIC_METHOD_CALL, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_INIT_FCALL, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_INIT_NS_FCALL_BY_NAME, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_CATCH, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_BOOL, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_INIT_ARRAY, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_DIM_R, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_DIM_W, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_OBJ_R, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_OBJ_W, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_OBJ_FUNC_ARG, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_DIM_FUNC_ARG, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_STATIC_PROP_FUNC_ARG, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_DIM_UNSET, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_OBJ_UNSET, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_CLASS, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_CONSTANT, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FETCH_CLASS_CONSTANT, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_CONCAT, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FAST_CONCAT, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_ISSET_ISEMPTY_DIM_OBJ, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_ISSET_ISEMPTY_PROP_OBJ, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_CASE, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_DECLARE_LAMBDA_FUNCTION, xdebug_common_override_handler); -#if PHP_VERSION_ID < 70400 - xdebug_set_opcode_handler(ZEND_ADD_TRAIT, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_BIND_TRAITS, xdebug_common_override_handler); -#endif - xdebug_set_opcode_handler(ZEND_INSTANCEOF, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_FAST_RET, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_ROPE_ADD, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_ROPE_END, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_COALESCE, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_TYPE_CHECK, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_GENERATOR_CREATE, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_BIND_STATIC, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_BIND_LEXICAL, xdebug_common_override_handler); -#if PHP_VERSION_ID >= 70400 - xdebug_set_opcode_handler(ZEND_DECLARE_CLASS, xdebug_common_override_handler); - xdebug_set_opcode_handler(ZEND_DECLARE_CLASS_DELAYED, xdebug_common_override_handler); -#endif - xdebug_set_opcode_handler(ZEND_SWITCH_STRING, xdebug_switch_handler); - xdebug_set_opcode_handler(ZEND_SWITCH_LONG, xdebug_switch_handler); - - /* Override all the other opcodes so that we can mark when we hit a branch - * start one */ - for (i = 0; i < 256; i++) { - if (i == ZEND_HANDLE_EXCEPTION) { - continue; - } - if (!xdebug_isset_opcode_handler(i)) { - xdebug_set_opcode_handler(i, xdebug_check_branch_entry_handler); - } - } -} - -void xdebug_coverage_register_constants(INIT_FUNC_ARGS) -{ - REGISTER_LONG_CONSTANT("XDEBUG_CC_UNUSED", XDEBUG_CC_OPTION_UNUSED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("XDEBUG_CC_DEAD_CODE", XDEBUG_CC_OPTION_DEAD_CODE, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("XDEBUG_CC_BRANCH_CHECK", XDEBUG_CC_OPTION_BRANCH_CHECK, CONST_CS | CONST_PERSISTENT); -} - -void xdebug_coverage_rinit(void) -{ - XG_COV(code_coverage_active) = 0; - XG_COV(code_coverage_info) = xdebug_hash_alloc(32, xdebug_coverage_file_dtor); - XG_COV(dead_code_analysis_tracker_offset) = zend_xdebug_cc_run_offset; - XG_COV(dead_code_last_start_id) = 1; - XG_COV(code_coverage_filter_offset) = zend_xdebug_filter_offset; - XG_COV(previous_filename) = NULL; - XG_COV(previous_file) = NULL; - XG_COV(prefill_function_count) = 0; - XG_COV(prefill_class_count) = 0; - - /* Initialize visited classes and branches hash */ - XG_COV(visited_branches) = xdebug_hash_alloc(2048, NULL); - - XG_COV(paths_stack) = xdebug_path_info_ctor(); - XG_COV(branches).size = 0; - XG_COV(branches).last_branch_nr = NULL; -} - -void xdebug_coverage_post_deactivate(void) -{ - XG_COV(code_coverage_active) = 0; - - xdebug_hash_destroy(XG_COV(code_coverage_info)); - XG_COV(code_coverage_info) = NULL; - - xdebug_hash_destroy(XG_COV(visited_branches)); - XG_COV(visited_branches) = NULL; - - /* Clean up path coverage array */ - if (XG_COV(paths_stack)) { - xdebug_path_info_dtor(XG_COV(paths_stack)); - XG_COV(paths_stack) = NULL; - } - if (XG_COV(branches).last_branch_nr) { - free(XG_COV(branches).last_branch_nr); - XG_COV(branches).last_branch_nr = NULL; - XG_COV(branches).size = 0; - } - - if (XG_COV(previous_filename)) { - zend_string_release(XG_COV(previous_filename)); - XG_COV(previous_filename) = NULL; - } - if (XG_COV(previous_mark_filename)) { - zend_string_release(XG_COV(previous_mark_filename)); - XG_COV(previous_mark_filename) = NULL; - } -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/coverage/code_coverage_private.h
Deleted
@@ -1,58 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __XDEBUG_CODE_COVERAGE_PRIVATE_H__ -#define __XDEBUG_CODE_COVERAGE_PRIVATE_H__ - -#include "php.h" - -#include "branch_info.h" -#include "code_coverage.h" - -#include "lib/compat.h" -#include "lib/hash.h" -#include "lib/mm.h" - -typedef struct xdebug_coverage_line { - int lineno; - int count; - int executable; -} xdebug_coverage_line; - -typedef struct xdebug_coverage_function { - char *name; - xdebug_branch_info *branch_info; -} xdebug_coverage_function; - -#define XG_COV(v) (XG(globals.coverage.v)) -#define XINI_COV(v) (XG(settings.coverage.v)) - -xdebug_coverage_file *xdebug_coverage_file_ctor(zend_string *filename); - -xdebug_coverage_function *xdebug_coverage_function_ctor(char *function_name); -void xdebug_coverage_function_dtor(void *data); -void xdebug_code_coverage_start_of_function(zend_op_array *op_array, char *function_name); -void xdebug_code_coverage_end_of_function(zend_op_array *op_array, zend_string *file_name, char *function_name); - -PHP_FUNCTION(xdebug_start_code_coverage); -PHP_FUNCTION(xdebug_stop_code_coverage); -PHP_FUNCTION(xdebug_get_code_coverage); -PHP_FUNCTION(xdebug_code_coverage_started); - -PHP_FUNCTION(xdebug_get_function_count); - -#endif -
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/debugger/com.c
Deleted
@@ -1,693 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2022 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ -#include "php_xdebug.h" -#include <string.h> -#include <sys/types.h> -#include <errno.h> -#include <stdio.h> -#include <fcntl.h> -#ifndef PHP_WIN32 -# if HAVE_POLL_H -# include <poll.h> -# elif HAVE_SYS_POLL_H -# include <sys/poll.h> -# endif -# include <unistd.h> -# include <sys/socket.h> -# include <sys/un.h> -# include <netinet/tcp.h> -# if HAVE_NETINET_IN_H -# include <netinet/in.h> -# endif -# include <netdb.h> -#else -# include <process.h> -# include <direct.h> -# include "win32/time.h" -# undef UNICODE -# include <winsock2.h> -# include <ws2tcpip.h> -# include <mstcpip.h> -# pragma comment (lib, "Ws2_32.lib") -# define PATH_MAX MAX_PATH -# define poll WSAPoll -#endif - -#include "com.h" - -#include "debugger_private.h" -#include "handler_dbgp.h" -#include "lib/crc32.h" -#include "lib/log.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -#if !WIN32 && !WINNT -static int xdebug_create_socket_unix(const char *path) -{ - struct sockaddr_un sa; - int sockfd; - - if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == SOCK_ERR) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "UNIX", "Creating socket for 'unix://%s', socket: %s.", path, strerror(errno)); - return SOCK_ERR; - } - - sa.sun_family = AF_UNIX; - strncpy(sa.sun_path, path, sizeof(sa.sun_path) - 1); - if (connect(sockfd, (struct sockaddr*)&sa, sizeof(sa)) < 0) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "UNIX", "Creating socket for 'unix://%s', connect: %s.", path, strerror(errno)); - SCLOSE(sockfd); - return (errno == EACCES) ? SOCK_ACCESS_ERR : SOCK_ERR; - } - - /* Prevent the socket from being inherited by exec'd children */ - if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) < 0) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "UNIX", "Creating socket for 'unix://%s', fcntl(FD_CLOEXEC): %s.", path, strerror(errno)); - } - - return sockfd; -} -#endif - -#if !WIN32 && !WINNT - -/* For OSX and FreeBSD */ -# if !defined(SOL_TCP) && defined(IPPROTO_TCP) -# define SOL_TCP IPPROTO_TCP -# endif -# if !defined(TCP_KEEPIDLE) && defined(TCP_KEEPALIVE) -# define TCP_KEEPIDLE TCP_KEEPALIVE -# endif - -void set_keepalive_options(int fd) -{ - int optval = 1; - int optlen = sizeof(optval); - int ret; - - ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen); - if (ret) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "KEEPALIVE", "Could not set SO_KEEPALIVE: %s.", strerror(errno)); - return; - } - -# if defined(TCP_KEEPIDLE) - optval = 600; - ret = setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &optval, optlen); - if (ret) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "KEEPALIVE", "Could not set TCP_KEEPIDLE to %d: %s.", optval, strerror(errno)); - return; - } -# endif - -# if defined(TCP_KEEPCNT) - optval = 20; - ret = setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &optval, optlen); - if (ret) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "KEEPALIVE", "Could not set TCP_KEEPCNT to %d: %s.", optval, strerror(errno)); - return; - } -# endif - -# if defined(TCP_KEEPINTVL) - optval = 60; - ret = setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &optval, optlen); - if (ret) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "KEEPALIVE", "Could not set TCP_KEEPINTVL to %d: %s.", optval, strerror(errno)); - return; - } -# endif -} -#endif // !WIN32 && !WINNT - -static int xdebug_create_socket(const char *hostname, int dport, int timeout) -{ - struct addrinfo hints; - struct addrinfo *remote; - struct addrinfo *ptr; - int status; - int sockfd = 0; - int sockerror; - char sport10; - int actually_connected; - struct sockaddr_in6 sa; - socklen_t size = sizeof(sa); -#if WIN32|WINNT - WSAPOLLFD ufds1 = {0}; - WORD wVersionRequested; - WSADATA wsaData; - char optval = 1; - u_long yes = 1; - u_long no = 0; - - wVersionRequested = MAKEWORD(2, 2); - WSAStartup(wVersionRequested, &wsaData); -#else - struct pollfd ufds1; - long optval = 1; -#endif - - if (!strncmp(hostname, "unix://", strlen("unix://"))) { -#if WIN32|WINNT - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "UNIX-WIN", "Creating Unix domain socket ('%s') on Windows is not supported.", hostname); - return SOCK_ERR; -#else - return xdebug_create_socket_unix(hostname + strlen("unix://")); -#endif - } - - /* Make a string of the port number that can be used with getaddrinfo */ - sprintf(sport, "%d", dport); - - /* Create hints for getaddrinfo saying that we want IPv4 and IPv6 TCP stream sockets */ - memset(&hints, 0, sizeof(hints)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - hints.ai_protocol = IPPROTO_TCP; - hints.ai_flags = AI_PASSIVE; - - /* Call getaddrinfo and return SOCK_ERR if the call fails for some reason */ - if ((status = getaddrinfo(hostname, sport, &hints, &remote)) != 0) { -#if WIN32|WINNT - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK1", "Creating socket for '%s:%d', getaddrinfo: %d.", hostname, dport, WSAGetLastError()); -#else - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK1", "Creating socket for '%s:%d', getaddrinfo: %s.", hostname, dport, strerror(errno)); -#endif - return SOCK_ERR; - } - - /* Go through every returned IP address */ - for (ptr = remote; ptr != NULL; ptr = ptr->ai_next) { - /* Try to create the socket. If the creation fails continue on with the - * next IP address in the list */ - if ((sockfd = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol)) == SOCK_ERR) { -#if WIN32|WINNT - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK2", "Creating socket for '%s:%d', socket: %d.", hostname, dport, WSAGetLastError()); -#else - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK2", "Creating socket for '%s:%d', socket: %s.", hostname, dport, strerror(errno)); -#endif - continue; - } - - /* Put socket in non-blocking mode so we can use poll for timeouts */ -#ifdef WIN32 - status = ioctlsocket(sockfd, FIONBIO, &yes); - if (SOCKET_ERROR == status) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK2", "Creating socket for '%s:%d', FIONBIO: %d.", hostname, dport, WSAGetLastError()); - } -#else - fcntl(sockfd, F_SETFL, O_NONBLOCK); -#endif - -#if !WIN32 && !WINNT - /* Prevent the socket from being inherited by exec'd children on *nix (not necessary on Win) */ - if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) < 0) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK2", "Creating socket for '%s:%d', fcntl(FD_CLOEXEC): %s.", hostname, dport, strerror(errno)); - } -#endif - - /* Try to connect to the newly created socket */ - /* Worth noting is that the port is set in the getaddrinfo call before */ - status = connect(sockfd, ptr->ai_addr, ptr->ai_addrlen); - - /* Determine if we got a connection. If no connection could be made - * we close the socket and continue with the next IP address in the list */ - if (status < 0) { -#ifdef WIN32 - errno = WSAGetLastError(); - if (errno != WSAEINPROGRESS && errno != WSAEWOULDBLOCK) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK3", "Creating socket for '%s:%d', connect: %d.", hostname, dport, errno); -#else - if (errno == EACCES) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK3", "Creating socket for '%s:%d', connect: %s.", hostname, dport, strerror(errno)); - SCLOSE(sockfd); - sockfd = SOCK_ACCESS_ERR; - - continue; - } - if (errno != EINPROGRESS) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK3", "Creating socket for '%s:%d', connect: %s.", hostname, dport, strerror(errno)); -#endif - SCLOSE(sockfd); - sockfd = SOCK_ERR; - - continue; - } - - ufds0.fd = sockfd; -#if WIN32|WINNT - ufds0.events = POLLIN | POLLOUT; -#else - ufds0.events = POLLIN | POLLOUT | POLLPRI; -#endif - while (1) { - sockerror = poll(ufds, 1, timeout); - -#if WIN32|WINNT - errno = WSAGetLastError(); - if (errno == WSAEINPROGRESS || errno == WSAEWOULDBLOCK) { - /* XXX introduce retry count? */ - continue; - } -#endif - /* If an error occured when doing the poll */ - if (sockerror == SOCK_ERR) { -#if WIN32|WINNT - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', WSAPoll error: %d (%d, %d).", hostname, dport, WSAGetLastError(), sockerror, errno); -#else - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', poll error: %s (%d).", hostname, dport, strerror(errno), sockerror); -#endif - sockerror = SOCK_ERR; - break; - } - - /* A timeout occured when polling the socket */ - if (sockerror == 0) { - sockerror = SOCK_TIMEOUT_ERR; - break; - } - - /* If the poll was successful but an error occured */ - if (ufds0.revents & (POLLERR | POLLHUP | POLLNVAL)) { -#if WIN32|WINNT - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', WSAPoll success, but error: %d (%d).", hostname, dport, WSAGetLastError(), ufds0.revents); -#else - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', poll success, but error: %s (%d).", hostname, dport, strerror(errno), ufds0.revents); -#endif - sockerror = SOCK_ERR; - break; - } - - /* If the poll was successful break out */ - if (ufds0.revents & (POLLIN | POLLOUT)) { - sockerror = sockfd; - break; - } else { - /* We should never get here, but added as a failsafe to break out from any loops */ -#if WIN32|WINNT - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', WSAPoll: %d.", hostname, dport, WSAGetLastError()); -#else - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', poll: %s.", hostname, dport, strerror(errno)); -#endif - sockerror = SOCK_ERR; - break; - } - } - - if (sockerror > 0) { - actually_connected = getpeername(sockfd, (struct sockaddr *)&sa, &size); - if (actually_connected == -1) { -#if WIN32|WINNT - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK5", "Creating socket for '%s:%d', getpeername: %d.", hostname, dport, WSAGetLastError()); -#else - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK5", "Creating socket for '%s:%d', getpeername: %s.", hostname, dport, strerror(errno)); -#endif - sockerror = SOCK_ERR; - } - } - - /* If there where some errors close the socket and continue with the next IP address */ - if (sockerror < 0) { - SCLOSE(sockfd); - sockfd = sockerror; - - continue; - } - } - - break; - } - - /* Free the result returned by getaddrinfo */ - freeaddrinfo(remote); - - /* If we got a socket, set the option "No delay" to true (1) */ - if (sockfd > 0) { -#ifdef WIN32 - status = ioctlsocket(sockfd, FIONBIO, &no); - if (SOCKET_ERROR == status) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK6", "Creating socket for '%s:%d', FIONBIO: %d.", hostname, dport, WSAGetLastError()); - } -#else - fcntl(sockfd, F_SETFL, 0); -#endif - - setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &optval, sizeof(optval)); -#if !WIN32 && !WINNT - set_keepalive_options(sockfd); -#endif - - /* Now we have a socket, update the last seen hostname and port */ - if (XG_DBG(context).connected_hostname) { - xdfree(XG_DBG(context).connected_hostname); - } - XG_DBG(context).connected_hostname = xdstrdup(hostname); - XG_DBG(context).connected_port = dport; - } - - return sockfd; -} - -void xdebug_close_socket(int socketfd) -{ - SCLOSE(socketfd); -} - -/* Starting the debugger */ -static void xdebug_init_normal_debugger(xdebug_str *connection_attempts) -{ - zval *remote_addr = NULL; - char *cp = NULL; - int cp_found = 0; - const char *header = NULL; - - if (!XINI_DBG(discover_client_host)) { - xdebug_str_add_fmt(connection_attempts, "%s:%ld (through xdebug.client_host/xdebug.client_port)", XINI_DBG(client_host), XINI_DBG(client_port)); - xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Connecting to configured address/port: %s:%ld.", XINI_DBG(client_host), (long int) XINI_DBG(client_port)); - - XG_DBG(context).socket = xdebug_create_socket(XINI_DBG(client_host), XINI_DBG(client_port), XINI_DBG(connect_timeout_ms)); - return; - } - - xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Checking remote connect back address."); - if (XINI_DBG(client_discovery_header) && XINI_DBG(client_discovery_header)0) { - header = XINI_DBG(client_discovery_header); - xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Checking user configured header '%s'.", XINI_DBG(client_discovery_header)); - - remote_addr = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_SERVER), XINI_DBG(client_discovery_header), HASH_KEY_STRLEN(XINI_DBG(client_discovery_header))); - } - if (!remote_addr) { - header = "HTTP_X_FORWARDED_FOR"; - xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Checking header 'HTTP_X_FORWARDED_FOR'."); - - remote_addr = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_SERVER), "HTTP_X_FORWARDED_FOR", HASH_KEY_SIZEOF("HTTP_X_FORWARDED_FOR")); - } - if (!remote_addr) { - header = "REMOTE_ADDR"; - xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Checking header 'REMOTE_ADDR'."); - - remote_addr = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_SERVER), "REMOTE_ADDR", HASH_KEY_SIZEOF("REMOTE_ADDR")); - } - - if (remote_addr && strstr(Z_STRVAL_P(remote_addr), "://")) { - header = NULL; - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "INVADDR", "Invalid remote address provided containing URI spec '%s'.", Z_STRVAL_P(remote_addr)); - - remote_addr = NULL; - } - - if (!remote_addr) { - xdebug_str_add_fmt(connection_attempts, "%s:%ld (fallback through xdebug.client_host/xdebug.client_port)", XINI_DBG(client_host), XINI_DBG(client_port)); - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "HDR", "Could not discover client host through HTTP headers, connecting to configured address/port: %s:%ld. :-|", XINI_DBG(client_host), (long int) XINI_DBG(client_port)); - - XG_DBG(context).socket = xdebug_create_socket(XINI_DBG(client_host), XINI_DBG(client_port), XINI_DBG(connect_timeout_ms)); - return; - } - - /* Use first IP according to RFC 7239 */ - cp = strchr(Z_STRVAL_P(remote_addr), ','); - if (cp) { - *cp = '\0'; - cp_found = 1; - } - - xdebug_str_add_fmt(connection_attempts, "%s:%ld (from %s HTTP header)", Z_STRVAL_P(remote_addr), XINI_DBG(client_port), header); - xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Client host discovered through HTTP header, connecting to %s:%ld.", Z_STRVAL_P(remote_addr), (long int) XINI_DBG(client_port)); - - XG_DBG(context).socket = xdebug_create_socket(Z_STRVAL_P(remote_addr), XINI_DBG(client_port), XINI_DBG(connect_timeout_ms)); - - if (XG_DBG(context).socket < 0) { - xdebug_str_add_fmt(connection_attempts, ", %s:%ld (fallback through xdebug.client_host/xdebug.client_port)", XINI_DBG(client_host), XINI_DBG(client_port)); - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "CON", "Could not connect to client host discovered through HTTP headers, connecting to configured address/port: %s:%ld. :-|", XINI_DBG(client_host), (long int) XINI_DBG(client_port)); - - XG_DBG(context).socket = xdebug_create_socket(XINI_DBG(client_host), XINI_DBG(client_port), XINI_DBG(connect_timeout_ms)); - } - - /* Replace the ',', in case we had changed the original header due - * to multiple values */ - if (cp_found) { - *cp = ','; - } -} - -static void xdebug_init_cloud_debugger(const char *cloud_id) -{ - unsigned long crc = xdebug_crc32(cloud_id, strlen(cloud_id)); - char *host; - - host = xdebug_sprintf("%c.cloud.xdebug.com", (crc & 0x0f) + 'a'); - - xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Connecting to configured address/port: %s:%ld.", host, 9020L); - XG_DBG(context).socket = xdebug_create_socket(host, 9020, XINI_DBG(connect_timeout_ms)); - - xdfree(host); -} - -/** - * dXXXXXXa-cXXa-4XX7-9XX3-fXXXXXXXXXX0 - */ -static int ide_key_is_cloud_id() -{ - const char *k = XG_DBG(ide_key); - - if (strlen(k) != 36) { - return 0; - } - - if (k8 != '-' || k13 != '-' || k18 != '-' || k23 != '-') { - return 0; - } - - return 1; -} - -static void xdebug_init_debugger() -{ - xdebug_str *connection_attempts = xdebug_str_new(); - - /* Get handler from mode */ - XG_DBG(context).handler = &xdebug_handler_dbgp; - - if (strcmp(XINI_DBG(cloud_id), "") != 0) { - xdebug_init_cloud_debugger(XINI_DBG(cloud_id)); - XG_DBG(context).host_type = XDEBUG_CLOUD; - } else if (XG_DBG(ide_key) && ide_key_is_cloud_id()) { - xdebug_init_cloud_debugger(XG_DBG(ide_key)); - XG_DBG(context).host_type = XDEBUG_CLOUD_FROM_TRIGGER_VALUE; - } else { - xdebug_init_normal_debugger(connection_attempts); - XG_DBG(context).host_type = XDEBUG_NORMAL; - } - - /* Check whether we're connected, or why not */ - if (XG_DBG(context).socket >= 0) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Connected to debugging client: %s. :-)", connection_attempts->d); - xdebug_mark_debug_connection_pending(); - - if (!XG_DBG(context).handler->remote_init(&(XG_DBG(context)), XDEBUG_REQ)) { - /* The request could not be started, ignore it then */ - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_ERR, "SES-INIT", "The debug session could not be started. Tried: %s. :-(", connection_attempts->d); - } else { - /* All is well, turn off script time outs */ - zend_unset_timeout(); - EG(timeout_seconds) = 0; - zend_set_timeout(EG(timeout_seconds), 0); - } - } else if (XG_DBG(context).socket == -1) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_ERR, "NOCON", "Could not connect to debugging client. Tried: %s :-(", connection_attempts->d); - } else if (XG_DBG(context).socket == -2) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_ERR, "TIMEOUT", "Time-out connecting to debugging client, waited: " ZEND_LONG_FMT " ms. Tried: %s :-(", XINI_DBG(connect_timeout_ms), connection_attempts->d); - } else if (XG_DBG(context).socket == -3) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_ERR, "NOPERM", "No permission connecting to debugging client (%s). This could be SELinux related. :-(", connection_attempts->d); - } - - xdebug_str_free(connection_attempts); -} - -void xdebug_abort_debugger() -{ - if (XG_DBG(remote_connection_enabled)) { - xdebug_mark_debug_connection_not_active(); - } -} - -void xdebug_restart_debugger() -{ - xdebug_abort_debugger(); - xdebug_init_debugger(); -} - -/* Remote connection activation and house keeping */ -int xdebug_is_debug_connection_active() -{ - return XG_DBG(remote_connection_enabled); -} - -void xdebug_mark_debug_connection_active() -{ - XG_DBG(remote_connection_enabled) = 1; - XG_DBG(remote_connection_pid) = xdebug_get_pid(); -} - -void xdebug_mark_debug_connection_pending() -{ - XG_DBG(remote_connection_enabled) = 0; - XG_DBG(remote_connection_pid) = 0; -} - -void xdebug_mark_debug_connection_not_active() -{ - if (XG_DBG(remote_connection_enabled)) { - xdebug_close_socket(XG_DBG(context).socket); - } - - XG_DBG(remote_connection_enabled) = 0; - XG_DBG(remote_connection_pid) = 0; -} - -void xdebug_debug_init_if_requested_on_error() -{ - RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); - - if (!xdebug_lib_start_upon_error()) { - return; - } - - if (!xdebug_is_debug_connection_active()) { - xdebug_init_debugger(); - } -} - -void xdebug_debug_init_if_requested_on_xdebug_break() -{ - RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); - - if (xdebug_is_debug_connection_active()) { - return; - } - - if (xdebug_lib_start_if_mode_is_trigger(XDEBUG_MODE_STEP_DEBUG)) { - xdebug_init_debugger(); - } -} - -static void xdebug_update_ide_key(char *new_key) -{ - if (XG_DBG(ide_key)) { - xdfree(XG_DBG(ide_key)); - } - XG_DBG(ide_key) = xdstrdup(new_key); -} - -static int xdebug_handle_start_session() -{ - int activate_session = 0; - zval *dummy; - char *dummy_env; - - /* Set session cookie if requested */ - if ( - (( - (dummy = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_ENV), "XDEBUG_SESSION_START", sizeof("XDEBUG_SESSION_START") - 1)) != NULL - ) || ( - (dummy = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_GET), "XDEBUG_SESSION_START", sizeof("XDEBUG_SESSION_START") - 1)) != NULL - ) || ( - (dummy = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_POST), "XDEBUG_SESSION_START", sizeof("XDEBUG_SESSION_START") - 1)) != NULL - )) - && !SG(headers_sent) - ) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "Found 'XDEBUG_SESSION_START' HTTP variable, with value '%s'", Z_STRVAL_P(dummy)); - - convert_to_string_ex(dummy); - xdebug_update_ide_key(Z_STRVAL_P(dummy)); - - xdebug_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION") - 1, Z_STRVAL_P(dummy), Z_STRLEN_P(dummy), 0, "/", 1, NULL, 0, 0, 1, 0); - activate_session = 1; - } else if ( - (dummy_env = getenv("XDEBUG_SESSION_START")) != NULL - ) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "Found 'XDEBUG_SESSION_START' ENV variable, with value '%s'", dummy_env); - - xdebug_update_ide_key(dummy_env); - - if (!SG(headers_sent)) { - xdebug_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION") - 1, XG_DBG(ide_key), strlen(XG_DBG(ide_key)), 0, "/", 1, NULL, 0, 0, 1, 0); - } - - activate_session = 1; - } else if (getenv("XDEBUG_CONFIG")) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "Found 'XDEBUG_CONFIG' ENV variable"); - - if (XG_DBG(ide_key) && *XG_DBG(ide_key) && !SG(headers_sent)) { - xdebug_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION") - 1, XG_DBG(ide_key), strlen(XG_DBG(ide_key)), 0, "/", 1, NULL, 0, 0, 1, 0); - activate_session = 1; - } - } - - /* Make sure that if we have a trigger value configured, we don't start the session unless it matches */ - if (activate_session && xdebug_lib_has_shared_secret()) { - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_INFO, "TRGSEC-LEGACY", "Not activating through legacy method because xdebug.trigger_value is set"); - activate_session = 0; - } - - return activate_session; -} - -static void xdebug_handle_stop_session() -{ - /* Remove session cookie if requested */ - if ( - (( - zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_GET), "XDEBUG_SESSION_STOP", sizeof("XDEBUG_SESSION_STOP") - 1) != NULL - ) || ( - zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_POST), "XDEBUG_SESSION_STOP", sizeof("XDEBUG_SESSION_STOP") - 1) != NULL - )) - && !SG(headers_sent) - ) { - xdebug_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION") - 1, (char*) "", 0, 0, "/", 1, NULL, 0, 0, 1, 0); - } -} - -void xdebug_debug_init_if_requested_at_startup(void) -{ - char *found_trigger_value = NULL; - - if (XG_DBG(detached)) { - return; - } - - if (xdebug_is_debug_connection_active()) { - return; - } - - if ( - xdebug_lib_start_with_request(XDEBUG_MODE_STEP_DEBUG) || - (!xdebug_lib_never_start_with_request() && xdebug_handle_start_session()) || - xdebug_lib_start_with_trigger(XDEBUG_MODE_STEP_DEBUG, &found_trigger_value) - ) { - if (found_trigger_value) { - xdebug_update_ide_key(found_trigger_value); - } - xdebug_init_debugger(); - } - - if (found_trigger_value) { - xdfree(found_trigger_value); - } - - xdebug_handle_stop_session(); -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/debugger/com.h
Deleted
@@ -1,68 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __HAVE_XDEBUG_COM_H__ -#define __HAVE_XDEBUG_COM_H__ - -#include "handlers.h" - -#if WIN32|WINNT -# define SOCK_ERR INVALID_SOCKET -# define SOCK_CONN_ERR SOCKET_ERROR -# define SOCK_RECV_ERR SOCKET_ERROR -#else -# define SOCK_ERR -1 -# define SOCK_CONN_ERR -1 -# define SOCK_RECV_ERR -1 -#endif -#define SOCK_TIMEOUT_ERR -2 -#define SOCK_ACCESS_ERR -3 - -#if WIN32|WINNT -#define SCLOSE(a) closesocket(a) -#define SSENDL(a,b,c) send(a,b,c,0) -#define SSEND(a,b) send(a,b,strlen(b),0) -#define SREAD(a,b,c) recv(a,b,c,0) -#else -#define SCLOSE(a) close(a) -#define SSENDL(a,b,c) write(a,b,c) -#define SSEND(a,b) write(a,b,strlen(b)) -#define SREAD(a,b,c) read(a,b,c) -#endif - - -#define SENDMSG(socket, str) { \ - char *message_buffer; \ - \ - message_buffer = str; \ - SSEND(socket, message_buffer); \ - xdfree(message_buffer); \ -} - -void xdebug_close_socket(int socket); - -/* Remote connection activation and house keeping */ -int xdebug_is_debug_connection_active(void); -void xdebug_stop_debugger(void); -void xdebug_restart_debugger(void); -void xdebug_mark_debug_connection_active(void); -void xdebug_mark_debug_connection_not_active(void); -void xdebug_mark_debug_connection_pending(void); -void xdebug_debug_init_if_requested_at_startup(void); -void xdebug_debug_init_if_requested_on_error(void); -void xdebug_debug_init_if_requested_on_xdebug_break(void); - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/debugger/debugger.c
Deleted
@@ -1,908 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "php_xdebug.h" - -#include "ext/standard/info.h" -#include "zend_exceptions.h" - -#include "debugger_private.h" -#include "lib/var.h" - -extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); - -static size_t (*xdebug_orig_ub_write)(const char *string, size_t len); -static size_t xdebug_ub_write(const char *string, size_t length); - -static void xdebug_line_list_dtor(xdebug_lines_list *line_list); - -void xdebug_init_debugger_globals(xdebug_debugger_globals_t *xg) -{ - xg->breakpoint_count = 0; - xg->ide_key = NULL; - xg->stdout_mode = 0; - xg->no_exec = 0; - xg->context.program_name = NULL; - xg->context.list.last_filename = NULL; - xg->context.list.last_line = 0; - xg->context.do_break = 0; - xg->context.pending_breakpoint = NULL; - xg->context.do_step = 0; - xg->context.do_next = 0; - xg->context.do_finish = 0; - xg->context.do_connect_to_client = 0; - - xg->remote_connection_enabled = 0; - xg->remote_connection_pid = 0; - xg->breakpoints_allowed = 0; - - /* Capturing output */ - if (sapi_module.ub_write != xdebug_ub_write) { - xdebug_orig_ub_write = sapi_module.ub_write; - sapi_module.ub_write = xdebug_ub_write; - } - - /* Statistics and diagnostics */ - xg->context.connected_hostname = NULL; - xg->context.connected_port = 0; - xg->context.detached_message = NULL; -} - -static char *xdebug_debugger_get_ide_key(void) -{ - char *ide_key; - - ide_key = XINI_DBG(ide_key_setting); - if (ide_key && *ide_key) { - return ide_key; - } - - ide_key = getenv("DBGP_IDEKEY"); - if (ide_key && *ide_key) { - return ide_key; - } - - return NULL; -} - -void xdebug_debugger_reset_ide_key(char *envval) -{ - if (XG_DBG(ide_key)) { - xdfree(XG_DBG(ide_key)); - } - XG_DBG(ide_key) = xdstrdup(envval); -} - -int xdebug_debugger_bailout_if_no_exec_requested(void) -{ - /* We need to do this first before the executable clauses are called */ - if (XG_DBG(no_exec) == 1) { - php_printf("DEBUG SESSION ENDED"); - return 1; - } - return 0; -} - -static void register_compiled_variables(void) -{ - function_stack_entry *loop_fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - int i; - - for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, loop_fse--) { - if (loop_fse->declared_vars) { - continue; - } - - if (loop_fse->user_defined == XDEBUG_BUILT_IN) { - continue; - } - - xdebug_lib_register_compiled_variables(loop_fse, loop_fse->op_array); - } -} - - -void xdebug_debugger_set_program_name(zend_string *filename) -{ - if (!XG_DBG(context).program_name) { - XG_DBG(context).program_name = zend_string_copy(filename); - } -} - -/* Remote debugger helper functions */ -static int xdebug_handle_hit_value(xdebug_brk_info *brk_info) -{ - /* If this is a temporary breakpoint, disable the breakpoint */ - if (brk_info->temporary) { - brk_info->disabled = 1; - } - - /* Increase hit counter */ - brk_info->hit_count++; - - /* If the hit_value is 0, the condition check is disabled */ - if (!brk_info->hit_value) { - return 1; - } - - switch (brk_info->hit_condition) { - case XDEBUG_HIT_GREATER_EQUAL: - if (brk_info->hit_count >= brk_info->hit_value) { - return 1; - } - break; - case XDEBUG_HIT_EQUAL: - if (brk_info->hit_count == brk_info->hit_value) { - return 1; - } - break; - case XDEBUG_HIT_MOD: - if (brk_info->hit_count % brk_info->hit_value == 0) { - return 1; - } - break; - case XDEBUG_HIT_DISABLED: - return 1; - break; - } - return 0; -} - -int xdebug_do_eval(char *eval_string, zval *ret_zval) -{ -#if PHP_VERSION_ID < 80000 - int old_track_errors; -#endif - volatile int res = 1; - zend_execute_data *original_execute_data = EG(current_execute_data); - int original_no_extensions = EG(no_extensions); - zend_object *original_exception = EG(exception); - JMP_BUF *original_bailout = EG(bailout); - - /* Remember error reporting level and track errors */ - XG_BASE(error_reporting_override) = EG(error_reporting); - XG_BASE(error_reporting_overridden) = 1; -#if PHP_VERSION_ID < 80000 - old_track_errors = PG(track_errors); -#endif - EG(error_reporting) = 0; -#if PHP_VERSION_ID < 80000 - PG(track_errors) = 0; -#endif - - XG_DBG(context).inhibit_notifications = 1; - XG_DBG(breakpoints_allowed) = 0; - - /* Reset exception in case we're triggered while being in xdebug_throw_exception_hook */ - EG(exception) = NULL; - - /* Do evaluation */ - zend_first_try { - res = (zend_eval_string(eval_string, ret_zval, (char*) "xdebug://debug-eval") == SUCCESS); - } zend_end_try(); - - /* FIXME: Bubble up exception message to DBGp return packet */ - if (EG(exception)) { - if (!res) { - zend_clear_exception(); - } - res = 0; - } - - /* Clean up */ - EG(error_reporting) = XG_BASE(error_reporting_override); - XG_BASE(error_reporting_overridden) = 0; -#if PHP_VERSION_ID < 80000 - PG(track_errors) = old_track_errors; -#endif - XG_DBG(breakpoints_allowed) = 1; - XG_DBG(context).inhibit_notifications = 0; - - EG(current_execute_data) = original_execute_data; - EG(no_extensions) = original_no_extensions; - EG(exception) = original_exception; - EG(bailout) = original_bailout; - - return res; -} - -void xdebug_debugger_statement_call(zend_string *filename, int lineno) -{ - xdebug_llist_element *le; - xdebug_brk_info *extra_brk_info; - function_stack_entry *fse; - int level = 0; - int func_nr = 0; - - if (XG_DBG(context).do_connect_to_client) { - XG_DBG(context).do_connect_to_client = 0; - - if (!xdebug_is_debug_connection_active()) { - xdebug_debug_init_if_requested_on_xdebug_break(); - register_compiled_variables(); - } - } - - if (xdebug_is_debug_connection_active()) { - if (XG_DBG(context).do_break) { - xdebug_brk_info *brk_info = XG_DBG(context).pending_breakpoint; - - XG_DBG(context).do_break = 0; - XG_DBG(context).pending_breakpoint = NULL; - - if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), filename, lineno, XDEBUG_BREAK, NULL, 0, NULL, brk_info)) { - xdebug_mark_debug_connection_not_active(); - return; - } - } - - /* Get latest stack level and function number */ - if (XG_BASE(stack) && XDEBUG_VECTOR_TAIL(XG_BASE(stack))) { - fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - level = fse->level; - func_nr = fse->function_nr; - } else { - level = 0; - func_nr = 0; - } - - /* Check for "finish" */ - if ( - XG_DBG(context).do_finish && - ( - (level < XG_DBG(context).finish_level) || - ((level == XG_DBG(context).finish_level) && (func_nr > XG_DBG(context).finish_func_nr)) - ) - ) { - XG_DBG(context).do_finish = 0; - - if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), filename, lineno, XDEBUG_STEP, NULL, 0, NULL, NULL)) { - xdebug_mark_debug_connection_not_active(); - return; - } - return; - } - - /* Check for "next" */ - if (XG_DBG(context).do_next && XG_DBG(context).next_level >= level) { - XG_DBG(context).do_next = 0; - - if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), filename, lineno, XDEBUG_STEP, NULL, 0, NULL, NULL)) { - xdebug_mark_debug_connection_not_active(); - return; - } - return; - } - - /* Check for "step" */ - if (XG_DBG(context).do_step) { - XG_DBG(context).do_step = 0; - - if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), filename, lineno, XDEBUG_STEP, NULL, 0, NULL, NULL)) { - xdebug_mark_debug_connection_not_active(); - return; - } - return; - } - - if (XG_DBG(context).line_breakpoints) { - int break_ok, res; - zval retval; - - for (le = XDEBUG_LLIST_HEAD(XG_DBG(context).line_breakpoints); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { - extra_brk_info = XDEBUG_LLIST_VALP(le); - - if (XG_DBG(context).handler->break_on_line(&(XG_DBG(context)), extra_brk_info, filename, lineno)) { - break_ok = 1; /* Breaking is allowed by default */ - - /* Check if we have a condition set for it */ - if (extra_brk_info->condition) { - /* If there is a condition, we disable breaking by - * default and only enabled it when the code evaluates - * to TRUE */ - break_ok = 0; - - /* Remember error reporting level */ - res = xdebug_do_eval(extra_brk_info->condition, &retval); - if (res) { - break_ok = Z_TYPE(retval) == IS_TRUE; - zval_dtor(&retval); - } - } - if (break_ok && xdebug_handle_hit_value(extra_brk_info)) { - if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), filename, lineno, XDEBUG_BREAK, NULL, 0, NULL, extra_brk_info)) { - xdebug_mark_debug_connection_not_active(); - break; - } - return; - } - } - } - } - } -} - -#if PHP_VERSION_ID >= 80000 -void xdebug_debugger_throw_exception_hook(zend_object *exception, zval *file, zval *line, zval *code, char *code_str, zval *message) -{ - zend_class_entry *exception_ce = exception->ce; -#else -void xdebug_debugger_throw_exception_hook(zval *exception, zval *file, zval *line, zval *code, char *code_str, zval *message) -{ - zend_class_entry *exception_ce = Z_OBJCE_P(exception); -#endif - xdebug_brk_info *extra_brk_info; - - /* Start JIT if requested and not yet enabled */ - xdebug_debug_init_if_requested_on_error(); - - if (xdebug_is_debug_connection_active() && XG_DBG(breakpoints_allowed)) { - int exception_breakpoint_found = 0; - - /* Check if we have a wild card exception breakpoint */ - if (xdebug_hash_find(XG_DBG(context).exception_breakpoints, "*", 1, (void *) &extra_brk_info)) { - exception_breakpoint_found = 1; - } else { - /* Check if we have a breakpoint on this exception or its parent classes */ - zend_class_entry *ce_ptr = exception_ce; - - /* Check if we have a breakpoint on this exception or its parent classes */ - do { - if (xdebug_hash_find(XG_DBG(context).exception_breakpoints, (char *) STR_NAME_VAL(ce_ptr->name), STR_NAME_LEN(ce_ptr->name), (void *) &extra_brk_info)) { - exception_breakpoint_found = 1; - } - ce_ptr = ce_ptr->parent; - } while (!exception_breakpoint_found && ce_ptr); - } -#if 0 - if (XG_DBG(context).resolved_breakpoints && exception_breakpoint_found) { - XG_DBG(context).handler->resolve_breakpoints(&(XG_DBG(context)), extra_brk_info); - } -#endif - if (exception_breakpoint_found && xdebug_handle_hit_value(extra_brk_info)) { - if ( - !XG_DBG(context).handler->remote_breakpoint( - &(XG_DBG(context)), XG_BASE(stack), - Z_STR_P(file), Z_LVAL_P(line), XDEBUG_BREAK, - (char*) STR_NAME_VAL(exception_ce->name), - code_str ? code_str : ((code && Z_TYPE_P(code) == IS_STRING) ? Z_STRVAL_P(code) : NULL), - message ? Z_STRVAL_P(message) : "", - extra_brk_info - ) - ) { - xdebug_mark_debug_connection_not_active(); - } - } - } -} - -void xdebug_debugger_error_cb(zend_string *error_filename, int error_lineno, int type, char *error_type_str, char *buffer) -{ - xdebug_brk_info *extra_brk_info = NULL; - - /* Start JIT if requested and not yet enabled */ - xdebug_debug_init_if_requested_on_error(); - - if (xdebug_is_debug_connection_active() && XG_DBG(breakpoints_allowed)) { - /* Send notification with warning/notice/error information */ - if (XG_DBG(context).send_notifications && !XG_DBG(context).inhibit_notifications) { - if (!XG_DBG(context).handler->remote_notification(&(XG_DBG(context)), error_filename, error_lineno, type, error_type_str, buffer)) { - xdebug_mark_debug_connection_not_active(); - } - } - - /* Check for the pseudo exceptions to allow breakpoints on PHP error statuses */ - if ( - xdebug_hash_find(XG_DBG(context).exception_breakpoints, error_type_str, strlen(error_type_str), (void *) &extra_brk_info) || - xdebug_hash_find(XG_DBG(context).exception_breakpoints, "*", 1, (void *) &extra_brk_info) - ) { - if (xdebug_handle_hit_value(extra_brk_info)) { - char *type_str = xdebug_sprintf("%ld", type); - - if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), error_filename, error_lineno, XDEBUG_BREAK, error_type_str, type_str, buffer, extra_brk_info)) { - xdebug_mark_debug_connection_not_active(); - } - - xdfree(type_str); - } - } - } -} - -static int handle_breakpoints(function_stack_entry *fse, int breakpoint_type) -{ - char *tmp_name = NULL; - size_t tmp_len = 0; - xdebug_brk_info *extra_brk_info = NULL; - - /* Function breakpoints */ - if (fse->function.type == XFUNC_NORMAL) { - tmp_len = 2 + strlen(fse->function.function) + 1; - tmp_name = xdmalloc(tmp_len); - /* We intentionally do not use xdebug_sprintf because it can create a bottleneck in large - * codebases due to setlocale calls. We don't care about the locale here. */ - snprintf( - tmp_name, tmp_len, - "%c/%s", - breakpoint_type == XDEBUG_BREAKPOINT_TYPE_CALL ? 'C' : 'R', - fse->function.function - ); - } - /* class->function breakpoints */ - else if (fse->function.type == XFUNC_MEMBER || fse->function.type == XFUNC_STATIC_MEMBER) { - /* Using strlen(ZSTR_VAL(...)) here to cut of the string at the first \0, which is needed - * for anonymous classes, in combination with the snprintf() below */ - tmp_len = 2 + strlen(ZSTR_VAL(fse->function.object_class)) + 2 + strlen(fse->function.function) + 1; - tmp_name = xdmalloc(tmp_len); - /* We intentionally do not use xdebug_sprintf because it can create a bottleneck in large - * codebases due to setlocale calls. We don't care about the locale here. */ - snprintf( - tmp_name, tmp_len, - "%c/%s::%s", - breakpoint_type == XDEBUG_BREAKPOINT_TYPE_CALL ? 'C' : 'R', - ZSTR_VAL(fse->function.object_class), fse->function.function - ); - } - /* Unknown */ - else { - return 1; - } - - if (xdebug_hash_find(XG_DBG(context).function_breakpoints, tmp_name, tmp_len - 1, (void *) &extra_brk_info)) { - /* Yup, breakpoint found, call handler if the breakpoint is not - * disabled AND handle_hit_value is happy */ - if (!extra_brk_info->disabled && (extra_brk_info->function_break_type == breakpoint_type)) { - if (xdebug_handle_hit_value(extra_brk_info)) { - if (fse->user_defined == XDEBUG_BUILT_IN || (breakpoint_type == XDEBUG_BREAKPOINT_TYPE_RETURN)) { - if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), fse->filename, fse->lineno, XDEBUG_BREAK, NULL, 0, NULL, extra_brk_info)) { - xdfree(tmp_name); - return 0; - } - } else { - XG_DBG(context).do_break = 1; - XG_DBG(context).pending_breakpoint = extra_brk_info; - } - } - } - } - xdfree(tmp_name); - - return 1; -} - -void xdebug_debugger_handle_breakpoints(function_stack_entry *fse, int breakpoint_type) -{ - if (xdebug_is_debug_connection_active() && XG_DBG(breakpoints_allowed)) { - if (!handle_breakpoints(fse, breakpoint_type)) { - xdebug_mark_debug_connection_not_active(); - } - } -} - -static size_t xdebug_ub_write(const char *string, size_t length) -{ - if (xdebug_is_debug_connection_active()) { - if (-1 == XG_DBG(context).handler->remote_stream_output(string, length)) { - return 0; - } - } - return xdebug_orig_ub_write(string, length); -} - -static void xdebug_hook_output_handlers() -{ - /* Override output handler for capturing output */ - if (xdebug_orig_ub_write == NULL) { - xdebug_orig_ub_write = sapi_module.ub_write; - sapi_module.ub_write = xdebug_ub_write; - } -} - -static void xdebug_unhook_output_handlers() -{ - /* Restore original output handler */ - sapi_module.ub_write = xdebug_orig_ub_write; - xdebug_orig_ub_write = NULL; -} - -void xdebug_debugger_zend_startup(void) -{ - /* Hook output handlers (header and output writer) */ - xdebug_hook_output_handlers(); -} - -void xdebug_debugger_zend_shutdown(void) -{ - /* Remove our hooks to output handlers (header and output writer) */ - xdebug_unhook_output_handlers(); -} - -void xdebug_debugger_minit(void) -{ - XG_DBG(breakpoint_count) = 0; -} - -void xdebug_debugger_minfo(void) -{ - php_info_print_table_start(); - php_info_print_table_header(2, "Debugger", "enabled"); - php_info_print_table_row(2, "IDE Key", XG_DBG(ide_key)); - php_info_print_table_end(); -} - -void xdebug_debugger_rinit(void) -{ - char *idekey; - - xdebug_disable_opcache_optimizer(); - - /* Get the ide key for this session */ - XG_DBG(ide_key) = NULL; - idekey = xdebug_debugger_get_ide_key(); - if (idekey && *idekey) { - if (XG_DBG(ide_key)) { - xdfree(XG_DBG(ide_key)); - } - XG_DBG(ide_key) = xdstrdup(idekey); - } - - XG_DBG(no_exec) = 0; - xdebug_lib_set_active_symbol_table(NULL); - - /* Check if we have this special get variable that stops a debugging - * request without executing any code */ - { - zend_string *stop_no_exec = zend_string_init(ZEND_STRL("XDEBUG_SESSION_STOP_NO_EXEC"), 0); - if ( - ( - ( - zend_hash_find(Z_ARR(PG(http_globals)TRACK_VARS_GET), stop_no_exec) != NULL - ) || ( - zend_hash_find(Z_ARR(PG(http_globals)TRACK_VARS_POST), stop_no_exec) != NULL - ) - ) - && !SG(headers_sent) - ) { - xdebug_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION"), (char*) "", 0, 0, "/", 1, NULL, 0, 0, 1, 0); - XG_DBG(no_exec) = 1; - } - zend_string_release(stop_no_exec); - } - - xdebug_mark_debug_connection_not_active(); - - XG_DBG(breakpoints_allowed) = 1; - XG_DBG(detached) = 0; - XG_DBG(breakable_lines_map) = xdebug_hash_alloc(2048, (xdebug_hash_dtor_t) xdebug_line_list_dtor); - XG_DBG(function_count) = 0; - XG_DBG(class_count) = 0; - - /* Initialize some debugger context properties */ - XG_DBG(context).program_name = NULL; - XG_DBG(context).list.last_filename = NULL; - XG_DBG(context).list.last_line = 0; - XG_DBG(context).do_break = 0; - XG_DBG(context).pending_breakpoint = NULL; - XG_DBG(context).do_step = 0; - XG_DBG(context).do_next = 0; - XG_DBG(context).do_finish = 0; - XG_DBG(context).do_connect_to_client = 0; - - /* Statistics and diagnostics */ - XG_DBG(context).connected_hostname = NULL; - XG_DBG(context).connected_port = 0; - XG_DBG(context).detached_message = NULL; -} - -void xdebug_debugger_post_deactivate(void) -{ - if (XG_DBG(remote_connection_enabled)) { - XG_DBG(context).handler->remote_deinit(&(XG_DBG(context))); - xdebug_close_socket(XG_DBG(context).socket); - } - if (XG_DBG(context).program_name) { - zend_string_release(XG_DBG(context).program_name); - } - - if (XG_DBG(ide_key)) { - xdfree(XG_DBG(ide_key)); - XG_DBG(ide_key) = NULL; - } - - if (XG_DBG(context.list.last_filename)) { - zend_string_release(XG_DBG(context).list.last_filename); - XG_DBG(context).list.last_filename = NULL; - } - - xdebug_hash_destroy(XG_DBG(breakable_lines_map)); - XG_DBG(breakable_lines_map) = NULL; - - if (XG_DBG(context).connected_hostname) { - xdfree(XG_DBG(context).connected_hostname); - XG_DBG(context).connected_hostname = NULL; - } - - if (XG_DBG(context).detached_message) { - xdfree(XG_DBG(context).detached_message); - XG_DBG(context).detached_message = NULL; - } -} - -xdebug_set *xdebug_debugger_get_breakable_lines_from_oparray(zend_op_array *opa) -{ - int i; - xdebug_set *tmp; - - tmp = xdebug_set_create(opa->line_end); - - for (i = 0; i < opa->last; i++ ) { - if (opa->opcodesi.opcode == ZEND_EXT_STMT ) { - xdebug_set_add(tmp, opa->opcodesi.lineno); - } - } - - return tmp; -} - - -/* {{{ function/lines map collection helpers */ -static void xdebug_function_lines_map_dtor(xdebug_function_lines_map_item *lines_map) -{ - xdebug_set_free(lines_map->lines_breakable); - xdfree(lines_map); -} - -static void xdebug_line_list_dtor(xdebug_lines_list *line_list) -{ - size_t i; - - for (i = 0; i < line_list->count; i++) { - xdebug_function_lines_map_dtor(line_list->functionsi); - } - xdfree(line_list->functions); - xdfree(line_list); -} - -static xdebug_lines_list *get_file_function_line_list(zend_string *filename) -{ - xdebug_lines_list *lines_list; - - if (xdebug_hash_find(XG_DBG(breakable_lines_map), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &lines_list)) { - return lines_list; - } - - lines_list = xdmalloc(sizeof(xdebug_lines_list)); - lines_list->count = 0; - lines_list->size = 0; - lines_list->functions = NULL; - - xdebug_hash_add(XG_DBG(breakable_lines_map), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) lines_list); - - return lines_list; -} - -static void add_function_to_lines_list(xdebug_lines_list *lines_list, zend_op_array *opa) -{ - xdebug_function_lines_map_item *map_item = xdmalloc(sizeof(xdebug_function_lines_map_item)); - - map_item->line_start = opa->line_start; - map_item->line_end = opa->line_end; - map_item->line_span = opa->line_end - opa->line_start; - map_item->lines_breakable = xdebug_debugger_get_breakable_lines_from_oparray(opa); - - if (lines_list->count >= lines_list->size) { - lines_list->size = lines_list->size == 0 ? 16 : lines_list->size * 2; - lines_list->functions = xdrealloc(lines_list->functions, sizeof(xdebug_function_lines_map_item *) * lines_list->size); - } - lines_list->functionslines_list->count = map_item; - lines_list->count++; - -#if PHP_VERSION_ID >= 80100 - if (opa->num_dynamic_func_defs) { - uint32_t i; - - for (i = 0; i < opa->num_dynamic_func_defs; i++) { - add_function_to_lines_list(lines_list, opa->dynamic_func_defsi); - } - } -#endif -} -/* }}} */ - -static void resolve_breakpoints_for_function(xdebug_lines_list *lines_list, zend_op_array *opa) -{ - add_function_to_lines_list(lines_list, opa); -} - -static void resolve_breakpoints_for_class(xdebug_lines_list *file_function_lines_list, zend_class_entry *ce, zend_string *filename) -{ - zend_op_array *function_op_array; - - ZEND_HASH_FOREACH_PTR(&ce->function_table, function_op_array) { - if (!ZEND_USER_CODE(function_op_array->type)) { - continue; - } - /* Only resolve if the file names are the same. This is needed in case - * of inheritance or traits where op arrays from other files might get introduced */ - if (ZSTR_LEN(filename) != ZSTR_LEN(function_op_array->filename)) { - continue; - } - if (strcmp(ZSTR_VAL(filename), ZSTR_VAL(function_op_array->filename)) != 0) { - continue; - } - resolve_breakpoints_for_function(file_function_lines_list, function_op_array); - } ZEND_HASH_FOREACH_END(); -} - -void xdebug_debugger_compile_file(zend_op_array *op_array) -{ - zend_op_array *function_op_array; - zend_class_entry *class_entry; - xdebug_lines_list *file_function_lines_list; - - RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); - - /* The breakable_lines_map can not be set if another extension compiles - * scripts during RINIT */ - if (!XG_DBG(breakable_lines_map)) { - return; - } - - file_function_lines_list = get_file_function_line_list(op_array->filename); - - ZEND_HASH_REVERSE_FOREACH_PTR(CG(function_table), function_op_array) { - if (_idx == XG_DBG(function_count)) { - break; - } - if (!ZEND_USER_CODE(function_op_array->type)) { - continue; - } - resolve_breakpoints_for_function(file_function_lines_list, function_op_array); - } ZEND_HASH_FOREACH_END(); - XG_DBG(function_count) = CG(function_table)->nNumUsed; - - ZEND_HASH_REVERSE_FOREACH_PTR(CG(class_table), class_entry) { - if (_idx == XG_DBG(class_count)) { - break; - } - if (class_entry->type == ZEND_INTERNAL_CLASS) { - continue; - } - resolve_breakpoints_for_class(file_function_lines_list, class_entry, op_array->filename); - } ZEND_HASH_FOREACH_END(); - XG_DBG(class_count) = CG(class_table)->nNumUsed; - - add_function_to_lines_list(file_function_lines_list, op_array); - - if (!xdebug_is_debug_connection_active()) { - return; - } - - XG_DBG(context).handler->resolve_breakpoints( - &(XG_DBG(context)), - op_array->filename - ); -} - -static void resolve_breakpoints_for_eval(int eval_id, zend_op_array *opa) -{ - xdebug_lines_list *lines_list; - char *eval_filename = xdebug_sprintf("dbgp://%d", eval_id); - zend_string *eval_string = zend_string_init(eval_filename, strlen(eval_filename), 0); - - lines_list = get_file_function_line_list(eval_string); - add_function_to_lines_list(lines_list, opa); - - resolve_breakpoints_for_function(lines_list, opa); - - if (!xdebug_is_debug_connection_active()) { - zend_string_release(eval_string); - xdfree(eval_filename); - return; - } - - XG_DBG(context).handler->resolve_breakpoints( - &(XG_DBG(context)), - eval_string - ); - - zend_string_release(eval_string); - xdfree(eval_filename); -} - -void xdebug_debugger_register_eval(function_stack_entry *fse) -{ - if (xdebug_is_debug_connection_active() && XG_DBG(context).handler->register_eval_id) { - int eval_id = XG_DBG(context).handler->register_eval_id(&(XG_DBG(context)), fse); - - resolve_breakpoints_for_eval(eval_id, fse->op_array); - } -} - -void xdebug_debugger_restart_if_pid_changed() -{ - zend_ulong pid; - - if (!xdebug_is_debug_connection_active()) { - return; - } - - pid = xdebug_get_pid(); - - /* Start debugger if previously a connection was established and this - * process no longer has the same PID */ - if (XG_DBG(remote_connection_pid) != pid) { - xdebug_restart_debugger(); - } -} - -PHP_FUNCTION(xdebug_break) -{ - RETURN_FALSE_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); - - xdebug_debug_init_if_requested_on_xdebug_break(); - - if (!xdebug_is_debug_connection_active()) { - RETURN_FALSE; - } - - register_compiled_variables(); - - XG_DBG(context).do_break = 1; - XG_DBG(context).pending_breakpoint = NULL; - - RETURN_TRUE; -} - -PHP_FUNCTION(xdebug_connect_to_client) -{ - RETURN_FALSE_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); - - XG_DBG(context).do_connect_to_client = 1; - - RETURN_TRUE; -} - -PHP_FUNCTION(xdebug_is_debugger_active) -{ - RETURN_BOOL(xdebug_is_debug_connection_active()); -} - -PHP_FUNCTION(xdebug_notify) -{ - function_stack_entry *fse; - zval *data; - - RETURN_FALSE_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); - - if (!xdebug_is_debug_connection_active()) { - RETURN_FALSE; - } - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &data) == FAILURE) { - return; - } - - fse = xdebug_get_stack_frame(0); - - XG_DBG(context).handler->user_notification( - &(XG_DBG(context)), - fse->filename, fse->lineno, - data - ); - - RETURN_TRUE; -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/debugger/debugger.h
Deleted
@@ -1,95 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __XDEBUG_DEBUGGER_H__ -#define __XDEBUG_DEBUGGER_H__ - -#include "com.h" - -typedef struct _xdebug_debugger_globals_t { - int status; - int reason; - const char *lastcmd; - char *lasttransid; - - zend_bool remote_connection_enabled; - zend_ulong remote_connection_pid; - zend_bool breakpoints_allowed; - zend_bool detached; - xdebug_con context; - unsigned int breakpoint_count; - unsigned int no_exec; - char *ide_key; /* As Xdebug uses it, from environment, USER, USERNAME or empty */ - - /* breakpoint resolving */ - size_t function_count; - size_t class_count; - xdebug_hash *breakable_lines_map; - - /* output redirection */ - int stdout_mode; -} xdebug_debugger_globals_t; - -typedef struct _xdebug_debugger_settings_t { - /* Cloud */ - char *cloud_id; - char *cloud_shared_key; - - /* Step Debugger */ - zend_long client_port; /* 9000 */ - char *client_host; /* localhost */ - zend_bool discover_client_host; /* (try to) connect back to the HTTP requestor */ - char *client_discovery_header; /* User configured header to check for forwarded IP address */ - zend_long connect_timeout_ms; /* Timeout in MS for remote connections */ - - char *ide_key_setting; /* Set through php.ini and friends */ -} xdebug_debugger_settings_t; - -PHP_INI_MH(OnUpdateDebugMode); - -void xdebug_init_debugger_globals(xdebug_debugger_globals_t *xg); - -void xdebug_debugger_reset_ide_key(char *envval); -int xdebug_debugger_bailout_if_no_exec_requested(void); -void xdebug_debugger_set_program_name(zend_string *filename); -void xdebug_debugger_register_eval(function_stack_entry *fse); -void xdebug_debugger_restart_if_pid_changed(void); - -xdebug_set *xdebug_debugger_get_breakable_lines_from_oparray(zend_op_array *opa); -int xdebug_do_eval(char *eval_string, zval *ret_zval); - -void xdebug_debugger_statement_call(zend_string *filename, int lineno); -#if PHP_VERSION_ID >= 80000 -void xdebug_debugger_throw_exception_hook(zend_object *exception, zval *file, zval *line, zval *code, char *code_str, zval *message); -#else -void xdebug_debugger_throw_exception_hook(zval *exception, zval *file, zval *line, zval *code, char *code_str, zval *message); -#endif -void xdebug_debugger_error_cb(zend_string *error_filename, int error_lineno, int type, char *error_type_str, char *buffer); -void xdebug_debugger_handle_breakpoints(function_stack_entry *fse, int breakpoint_type); - -void xdebug_debugger_zend_startup(void); -void xdebug_debugger_zend_shutdown(void); -void xdebug_debugger_minit(void); -void xdebug_debugger_minfo(void); -void xdebug_debugger_rinit(void); -void xdebug_debugger_post_deactivate(void); - -void xdebug_debugger_compile_file(zend_op_array *op_array); - -PHP_FUNCTION(xdebug_break); - - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/debugger/handler_dbgp.c
Deleted
@@ -1,3041 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include <sys/types.h> - -#ifndef PHP_WIN32 -#include <unistd.h> -#endif - -#include "php.h" -#include "SAPI.h" - -#include "ext/standard/php_string.h" -#include "ext/standard/url.h" -#include "main/php_version.h" -#include "main/php_network.h" -#include "ext/standard/base64.h" -#include "TSRM.h" - -#include "php_globals.h" -#include "php_xdebug.h" - -#include "com.h" -#include "handler_dbgp.h" -#include "debugger_private.h" - -#include "coverage/code_coverage.h" -#include "develop/stack.h" -#include "lib/compat.h" -#include "lib/hash.h" -#include "lib/llist.h" -#include "lib/log.h" -#include "lib/mm.h" -#include "lib/var_export_xml.h" -#include "lib/vector.h" -#include "lib/xml.h" - -#ifdef PHP_WIN32 -#include "win32/time.h" -#include <process.h> -#endif -#include <fcntl.h> - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -xdebug_remote_handler xdebug_handler_dbgp = { - xdebug_dbgp_init, - xdebug_dbgp_deinit, - xdebug_dbgp_error, - xdebug_dbgp_break_on_line, - xdebug_dbgp_breakpoint, - xdebug_dbgp_resolve_breakpoints, - xdebug_dbgp_stream_output, - xdebug_dbgp_notification, - xdebug_dbgp_user_notify, - xdebug_dbgp_register_eval_id, -}; - -static char *create_eval_key_id(int id); -static void line_breakpoint_resolve_helper(xdebug_con *context, xdebug_lines_list *lines_list, xdebug_brk_info *brk_info); - -/***************************************************************************** -** Constants and strings for statii and reasons -*/ - -/* Status structure */ -#define DBGP_STATUS_STARTING 1 -#define DBGP_STATUS_STOPPING 2 -#define DBGP_STATUS_STOPPED 3 -#define DBGP_STATUS_RUNNING 4 -#define DBGP_STATUS_BREAK 5 -#define DBGP_STATUS_DETACHED 6 - -const char *xdebug_dbgp_status_strings7 = - {"", "starting", "stopping", "stopped", "running", "break", "detached"}; - -#define DBGP_REASON_OK 0 -#define DBGP_REASON_ERROR 1 -#define DBGP_REASON_ABORTED 2 -#define DBGP_REASON_EXCEPTION 3 - -const char *xdebug_dbgp_reason_strings4 = - {"ok", "error", "aborted", "exception"}; - -typedef struct { - int code; - const char *message; -} xdebug_error_entry; - -xdebug_error_entry xdebug_error_codes24 = { - { 0, "no error" }, - { 1, "parse error in command" }, - { 2, "duplicate arguments in command" }, - { 3, "invalid or missing options" }, - { 4, "unimplemented command" }, - { 5, "command is not available" }, - { 100, "can not open file" }, - { 101, "stream redirect failed" }, - { 200, "breakpoint could not be set" }, - { 201, "breakpoint type is not supported" }, - { 202, "invalid breakpoint line" }, - { 203, "no code on breakpoint line" }, - { 204, "invalid breakpoint state" }, - { 205, "no such breakpoint" }, - { 206, "error evaluating code" }, - { 207, "invalid expression" }, - { 300, "can not get property" }, - { 301, "stack depth invalid" }, - { 302, "context invalid" }, - { 800, "profiler not started" }, - { 900, "encoding not supported" }, - { 998, "an internal exception in the debugger" }, - { 999, "unknown error" }, - { -1, NULL } -}; - -#define XDEBUG_STR_SWITCH_DECL char *__switch_variable -#define XDEBUG_STR_SWITCH(s) __switch_variable = (s); -#define XDEBUG_STR_CASE(s) if (strcmp(__switch_variable, s) == 0) { -#define XDEBUG_STR_CASE_END } else -#define XDEBUG_STR_CASE_DEFAULT { -#define XDEBUG_STR_CASE_DEFAULT_END } - -#define XDEBUG_TYPES_COUNT 8 -const char *xdebug_dbgp_typemapXDEBUG_TYPES_COUNT3 = { - /* common, lang, schema */ - {"bool", "bool", "xsd:boolean"}, - {"int", "int", "xsd:decimal"}, - {"float", "float", "xsd:double"}, - {"string", "string", "xsd:string"}, - {"null", "null", NULL}, - {"hash", "array", NULL}, - {"object", "object", NULL}, - {"resource", "resource", NULL} -}; - - -typedef struct { - int value; - const char *name; -} xdebug_breakpoint_entry; - -#define XDEBUG_BREAKPOINT_TYPES_COUNT 6 -xdebug_breakpoint_entry xdebug_breakpoint_typesXDEBUG_BREAKPOINT_TYPES_COUNT = { - { XDEBUG_BREAKPOINT_TYPE_LINE, "line" }, - { XDEBUG_BREAKPOINT_TYPE_CONDITIONAL, "conditional" }, - { XDEBUG_BREAKPOINT_TYPE_CALL, "call" }, - { XDEBUG_BREAKPOINT_TYPE_RETURN, "return" }, - { XDEBUG_BREAKPOINT_TYPE_EXCEPTION, "exception" }, - { XDEBUG_BREAKPOINT_TYPE_WATCH, "watch" } -}; - -#define XDEBUG_DBGP_SCAN_RANGE 5 - -/***************************************************************************** -** Prototypes for debug command handlers -*/ - -/* DBGP_FUNC(break); */ -DBGP_FUNC(breakpoint_get); -DBGP_FUNC(breakpoint_list); -DBGP_FUNC(breakpoint_remove); -DBGP_FUNC(breakpoint_set); -DBGP_FUNC(breakpoint_update); - -DBGP_FUNC(context_get); -DBGP_FUNC(context_names); - -DBGP_FUNC(eval); -DBGP_FUNC(feature_get); -DBGP_FUNC(feature_set); - -DBGP_FUNC(typemap_get); -DBGP_FUNC(property_get); -DBGP_FUNC(property_set); -DBGP_FUNC(property_value); - -DBGP_FUNC(source); -DBGP_FUNC(stack_depth); -DBGP_FUNC(stack_get); -DBGP_FUNC(status); - -DBGP_FUNC(stderr); -DBGP_FUNC(stdout); - -DBGP_FUNC(stop); -DBGP_FUNC(run); -DBGP_FUNC(step_into); -DBGP_FUNC(step_out); -DBGP_FUNC(step_over); -DBGP_FUNC(detach); - -/* Non standard comments */ -DBGP_FUNC(xcmd_profiler_name_get); -DBGP_FUNC(xcmd_get_executable_lines); - -/***************************************************************************** -** Dispatcher tables for supported debug commands -*/ - -static xdebug_dbgp_cmd dbgp_commands = { - /* DBGP_FUNC_ENTRY(break) */ - DBGP_FUNC_ENTRY(breakpoint_get, XDEBUG_DBGP_NONE) - DBGP_FUNC_ENTRY(breakpoint_list, XDEBUG_DBGP_POST_MORTEM) - DBGP_FUNC_ENTRY(breakpoint_remove, XDEBUG_DBGP_NONE) - DBGP_FUNC_ENTRY(breakpoint_set, XDEBUG_DBGP_NONE) - DBGP_FUNC_ENTRY(breakpoint_update, XDEBUG_DBGP_NONE) - - DBGP_FUNC_ENTRY(context_get, XDEBUG_DBGP_NONE) - DBGP_FUNC_ENTRY(context_names, XDEBUG_DBGP_POST_MORTEM) - - DBGP_FUNC_ENTRY(eval, XDEBUG_DBGP_NONE) - DBGP_FUNC_ENTRY(feature_get, XDEBUG_DBGP_POST_MORTEM) - DBGP_FUNC_ENTRY(feature_set, XDEBUG_DBGP_NONE) - - DBGP_FUNC_ENTRY(typemap_get, XDEBUG_DBGP_POST_MORTEM) - DBGP_FUNC_ENTRY(property_get, XDEBUG_DBGP_NONE) - DBGP_FUNC_ENTRY(property_set, XDEBUG_DBGP_NONE) - DBGP_FUNC_ENTRY(property_value, XDEBUG_DBGP_NONE) - - DBGP_FUNC_ENTRY(source, XDEBUG_DBGP_NONE) - DBGP_FUNC_ENTRY(stack_depth, XDEBUG_DBGP_NONE) - DBGP_FUNC_ENTRY(stack_get, XDEBUG_DBGP_NONE) - DBGP_FUNC_ENTRY(status, XDEBUG_DBGP_POST_MORTEM) - - DBGP_FUNC_ENTRY(stderr, XDEBUG_DBGP_NONE) - DBGP_FUNC_ENTRY(stdout, XDEBUG_DBGP_NONE) - - DBGP_CONT_FUNC_ENTRY(run, XDEBUG_DBGP_NONE) - DBGP_CONT_FUNC_ENTRY(step_into, XDEBUG_DBGP_NONE) - DBGP_CONT_FUNC_ENTRY(step_out, XDEBUG_DBGP_NONE) - DBGP_CONT_FUNC_ENTRY(step_over, XDEBUG_DBGP_NONE) - - DBGP_STOP_FUNC_ENTRY(stop, XDEBUG_DBGP_POST_MORTEM) - DBGP_STOP_FUNC_ENTRY(detach, XDEBUG_DBGP_POST_MORTEM) - - /* Non standard functions */ - DBGP_FUNC_ENTRY(xcmd_profiler_name_get, XDEBUG_DBGP_POST_MORTEM) - DBGP_FUNC_ENTRY(xcmd_get_executable_lines, XDEBUG_DBGP_NONE) - { NULL, NULL, 0 } -}; - -/***************************************************************************** -** Utility functions -*/ - -static xdebug_dbgp_cmd* lookup_cmd(char *cmd) -{ - xdebug_dbgp_cmd *ptr = dbgp_commands; - - while (ptr->name) { - if (strcmp(ptr->name, cmd) == 0) { - return ptr; - } - ptr++; - } - return NULL; -} - -static xdebug_str *make_message(xdebug_con *context, xdebug_xml_node *message) -{ - xdebug_str xml_message = XDEBUG_STR_INITIALIZER; - xdebug_str *ret = xdebug_str_new(); - - xdebug_xml_return_node(message, &xml_message); - xdebug_log(XLOG_CHAN_DEBUG, XLOG_COM, "-> %s\n", xml_message.d); - - xdebug_str_add_fmt(ret, "%d", xml_message.l + sizeof("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n") - 1); - xdebug_str_addc(ret, '\0'); - xdebug_str_add_literal(ret, "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"); - xdebug_str_add(ret, xml_message.d, 0); - xdebug_str_addc(ret, '\0'); - xdebug_str_destroy(&xml_message); - - return ret; -} - -static void send_message_ex(xdebug_con *context, xdebug_xml_node *message, int stage) -{ - xdebug_str *tmp; - - /* Sometimes we end up in 'send_message' although the debugging connection - * is already closed. In that case, we early return. */ - if (XG_DBG(status) != DBGP_STATUS_STARTING && !xdebug_is_debug_connection_active()) { - return; - } - - tmp = make_message(context, message); - if ((size_t) SSENDL(context->socket, tmp->d, tmp->l) != tmp->l) { - char *sock_error = php_socket_strerror(php_socket_errno(), NULL, 0); - char *utime_str = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6); - - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SENDERR", "%s: There was a problem sending %zd bytes on socket %d: %s.", utime_str, tmp->l, context->socket, sock_error); - - efree(sock_error); - xdfree(utime_str); - } - xdebug_str_free(tmp); -} - -static void send_message(xdebug_con *context, xdebug_xml_node *message) -{ - send_message_ex(context, message, 0); -} - - -static xdebug_xml_node* get_symbol(xdebug_str *name, xdebug_var_export_options *options) -{ - zval retval; - xdebug_xml_node *tmp_node; - - xdebug_get_php_symbol(&retval, name); - - if (Z_TYPE(retval) == IS_UNDEF) { - return NULL; - } - - if (strcmp(name->d, "this") == 0 && Z_TYPE(retval) == IS_NULL) { - return NULL; - } - - tmp_node = xdebug_get_zval_value_xml_node(name, &retval, options); - zval_ptr_dtor_nogc(&retval); - - return tmp_node; -} - -static int get_symbol_contents(xdebug_str *name, xdebug_xml_node *node, xdebug_var_export_options *options) -{ - zval retval; - zval *retval_ptr; - - xdebug_get_php_symbol(&retval, name); - - if (Z_TYPE(retval) == IS_UNDEF) { - return 0; - } - - // TODO WTF??? - retval_ptr = &retval; - - xdebug_var_export_xml_node(&retval_ptr, name, node, options, 1); - zval_ptr_dtor_nogc(&retval); - - return 1; -} - -static xdebug_str* return_file_source(zend_string *filename, int begin, int end) -{ - php_stream *stream; - int i = begin; - char *line = NULL; - xdebug_str *source = xdebug_str_new(); - char *tmp_filename = NULL; - - if (i < 0) { - begin = 0; - i = 0; - } - xdebug_str_add_literal(source, ""); - - tmp_filename = xdebug_path_from_url(filename); - stream = php_stream_open_wrapper(tmp_filename, "rb", - USE_PATH | REPORT_ERRORS, - NULL); - xdfree(tmp_filename); - - /* Read until the "begin" line has been read */ - if (!stream) { - return NULL; - } - - /* skip to the first requested line */ - while (i > 0 && !php_stream_eof(stream)) { - if (line) { - efree(line); - line = NULL; - } - line = php_stream_gets(stream, NULL, 1024); - i--; - } - /* Read until the "end" line has been read */ - do { - if (line) { - xdebug_str_add(source, line, 0); - efree(line); - line = NULL; - if (php_stream_eof(stream)) break; - } - line = php_stream_gets(stream, NULL, 1024); - i++; - } while (i < end + 1 - begin); - - /* Print last line */ - if (line) { - efree(line); - line = NULL; - } - php_stream_close(stream); - return source; -} - -static xdebug_str* return_eval_source(char *id, int begin, int end) -{ - char *key; - xdebug_str *joined; - xdebug_eval_info *ei; - xdebug_arg *parts; - - if (begin < 0) { - begin = 0; - } - - key = create_eval_key_id(atoi(id)); - - if (!xdebug_hash_find(XG_DBG(context).eval_id_lookup, key, strlen(key), (void *) &ei)) { - return NULL; - } - - parts = xdebug_arg_ctor(); - xdebug_explode("\n", ZSTR_VAL(ei->contents), parts, end + 2); - joined = xdebug_join("\n", parts, begin, end); - xdebug_arg_dtor(parts); - - return joined; -} - -static int is_dbgp_url(zend_string *filename) -{ - return (strncmp(ZSTR_VAL(filename), "dbgp://", 7) == 0); -} - -static xdebug_str* return_source(zend_string *filename, int begin, int end) -{ - if (is_dbgp_url(filename)) { - return return_eval_source(ZSTR_VAL(filename) + 7, begin, end); - } else { - return return_file_source(filename, begin, end); - } -} - - -static int check_evaled_code(zend_string *filename_in, char **filename_out) -{ - char *end_marker; - xdebug_eval_info *ei; - - end_marker = ZSTR_VAL(filename_in) + ZSTR_LEN(filename_in) - strlen("eval()'d code"); - if (end_marker >= ZSTR_VAL(filename_in) && strcmp("eval()'d code", end_marker) == 0) { - if (xdebug_hash_find(XG_DBG(context).eval_id_lookup, ZSTR_VAL(filename_in), ZSTR_LEN(filename_in), (void *) &ei)) { - *filename_out = xdebug_sprintf("dbgp://%lu", ei->id); - return 1; - } - } - return 0; -} - -static xdebug_xml_node* return_stackframe(int nr) -{ - function_stack_entry *fse, *fse_prev; - char *tmp_fname; - char *tmp_filename; - xdebug_xml_node *tmp; - - fse = xdebug_get_stack_frame(nr); - fse_prev = xdebug_get_stack_frame(nr - 1); - - tmp_fname = xdebug_show_fname(fse->function, 0); - - tmp = xdebug_xml_node_init("stack"); - xdebug_xml_add_attribute_ex(tmp, "where", xdstrdup(tmp_fname), 0, 1); - xdebug_xml_add_attribute_ex(tmp, "level", xdebug_sprintf("%ld", nr), 0, 1); - if (fse_prev) { - if (check_evaled_code(fse_prev->filename, &tmp_filename)) { - xdebug_xml_add_attribute_ex(tmp, "type", xdstrdup("eval"), 0, 1); - xdebug_xml_add_attribute_ex(tmp, "filename", tmp_filename, 0, 0); - xdfree(tmp_filename); - } else { - xdebug_xml_add_attribute_ex(tmp, "type", xdstrdup("file"), 0, 1); - xdebug_xml_add_attribute_ex(tmp, "filename", xdebug_path_to_url(fse_prev->filename), 0, 1); - } - xdebug_xml_add_attribute_ex(tmp, "lineno", xdebug_sprintf("%lu", fse_prev->lineno), 0, 1); - } else { - zend_string *executed_filename = zend_get_executed_filename_ex(); - int executed_lineno = zend_get_executed_lineno(); - char *tmp_filename; - - if (check_evaled_code(executed_filename, &tmp_filename)) { - xdebug_xml_add_attribute_ex(tmp, "type", xdstrdup("eval"), 0, 1); - xdebug_xml_add_attribute_ex(tmp, "filename", tmp_filename, 0, 0); - xdfree(tmp_filename); - } else { - xdebug_xml_add_attribute_ex(tmp, "type", xdstrdup("file"), 0, 1); - xdebug_xml_add_attribute_ex(tmp, "filename", xdebug_path_to_url(executed_filename), 0, 1); - } - xdebug_xml_add_attribute_ex(tmp, "lineno", xdebug_sprintf("%lu", executed_lineno), 0, 1); - } - - xdfree(tmp_fname); - return tmp; -} - -/***************************************************************************** -** Client command handlers - Breakpoints -*/ - -/* Helper functions */ -static void xdebug_hash_admin_dtor(xdebug_brk_admin *admin) -{ - xdfree(admin->key); - xdfree(admin); -} - -static int breakpoint_admin_add(xdebug_con *context, int type, char *key) -{ - xdebug_brk_admin *admin = xdmalloc(sizeof(xdebug_brk_admin)); - char *hkey; - - XG_DBG(breakpoint_count)++; - admin->id = ((xdebug_get_pid() & 0x1ffff) * 10000) + XG_DBG(breakpoint_count); - admin->type = type; - admin->key = xdstrdup(key); - - hkey = xdebug_sprintf("%lu", admin->id); - xdebug_hash_add(context->breakpoint_list, hkey, strlen(hkey), (void*) admin); - xdfree(hkey); - - return admin->id; -} - -static int breakpoint_admin_fetch(xdebug_con *context, char *hkey, int *type, char **key) -{ - xdebug_brk_admin *admin; - - if (!xdebug_hash_find(context->breakpoint_list, hkey, strlen(hkey), (void *) &admin)) { - return FAILURE; - } - - *type = admin->type; - *key = admin->key; - - return SUCCESS; -} - -static int breakpoint_admin_remove(xdebug_con *context, char *hkey) -{ - if (!xdebug_hash_delete(context->breakpoint_list, hkey, strlen(hkey))) { - return FAILURE; - } - - return SUCCESS; -} - -static void breakpoint_brk_info_add_resolved(xdebug_xml_node *xml, xdebug_brk_info *brk_info) -{ - if (!XG_DBG(context).resolved_breakpoints) { - return; - } - - if (brk_info->resolved == XDEBUG_BRK_RESOLVED) { - xdebug_xml_add_attribute(xml, "resolved", "resolved"); - } else { - xdebug_xml_add_attribute(xml, "resolved", "unresolved"); - } -} - -static void breakpoint_brk_info_add(xdebug_xml_node *xml, xdebug_brk_info *brk_info) -{ - xdebug_xml_add_attribute_ex(xml, "type", xdstrdup(XDEBUG_BREAKPOINT_TYPE_NAME(brk_info->brk_type)), 0, 1); - breakpoint_brk_info_add_resolved(xml, brk_info); - if (brk_info->filename) { - if (is_dbgp_url(brk_info->filename)) { - xdebug_xml_add_attribute_ex(xml, "filename", ZSTR_VAL(brk_info->filename), 0, 0); - } else { - xdebug_xml_add_attribute_ex(xml, "filename", xdebug_path_to_url(brk_info->filename), 0, 1); - } - } - if (brk_info->resolved_lineno) { - xdebug_xml_add_attribute_ex(xml, "lineno", xdebug_sprintf("%lu", brk_info->resolved_lineno), 0, 1); - } - if (brk_info->functionname) { - xdebug_xml_add_attribute_ex(xml, "function", xdstrdup(brk_info->functionname), 0, 1); - } - if (brk_info->classname) { - xdebug_xml_add_attribute_ex(xml, "class", xdstrdup(brk_info->classname), 0, 1); - } - if (brk_info->exceptionname) { - xdebug_xml_add_attribute_ex(xml, "exception", xdstrdup(brk_info->exceptionname), 0, 1); - } - if (brk_info->temporary) { - xdebug_xml_add_attribute(xml, "state", "temporary"); - } else if (brk_info->disabled) { - xdebug_xml_add_attribute(xml, "state", "disabled"); - } else { - xdebug_xml_add_attribute(xml, "state", "enabled"); - } - xdebug_xml_add_attribute_ex(xml, "hit_count", xdebug_sprintf("%lu", brk_info->hit_count), 0, 1); - switch (brk_info->hit_condition) { - case XDEBUG_HIT_GREATER_EQUAL: - xdebug_xml_add_attribute(xml, "hit_condition", ">="); - break; - case XDEBUG_HIT_EQUAL: - xdebug_xml_add_attribute(xml, "hit_condition", "=="); - break; - case XDEBUG_HIT_MOD: - xdebug_xml_add_attribute(xml, "hit_condition", "%"); - break; - } - if (brk_info->condition) { - xdebug_xml_node *condition = xdebug_xml_node_init("expression"); - xdebug_xml_add_text_ex(condition, brk_info->condition, strlen(brk_info->condition), 0, 1); - xdebug_xml_add_child(xml, condition); - } - xdebug_xml_add_attribute_ex(xml, "hit_value", xdebug_sprintf("%lu", brk_info->hit_value), 0, 1); - xdebug_xml_add_attribute_ex(xml, "id", xdebug_sprintf("%lu", brk_info->id), 0, 1); -} - -static xdebug_brk_info* breakpoint_brk_info_fetch(int type, char *hkey) -{ - xdebug_llist_element *le; - xdebug_brk_info *brk_info = NULL; - - switch (type) { - case XDEBUG_BREAKPOINT_TYPE_LINE: - case XDEBUG_BREAKPOINT_TYPE_CONDITIONAL: { - xdebug_arg *parts; - - /* First we split the key into filename and linenumber */ - parts = xdebug_arg_ctor(); - xdebug_explode("$", hkey, parts, -1); - - /* Second we loop through the list of file/line breakpoints to - * look for our thingy */ - for (le = XDEBUG_LLIST_HEAD(XG_DBG(context).line_breakpoints); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { - brk_info = XDEBUG_LLIST_VALP(le); - - if (atoi(parts->args1) == brk_info->original_lineno && memcmp(ZSTR_VAL(brk_info->filename), parts->args0, ZSTR_LEN(brk_info->filename)) == 0) { - xdebug_arg_dtor(parts); - return brk_info; - } - } - - /* Cleaning up */ - xdebug_arg_dtor(parts); - - break; - } - - case XDEBUG_BREAKPOINT_TYPE_CALL: - case XDEBUG_BREAKPOINT_TYPE_RETURN: - if (xdebug_hash_find(XG_DBG(context).function_breakpoints, hkey, strlen(hkey), (void *) &brk_info)) { - return brk_info; - } - break; - - case XDEBUG_BREAKPOINT_TYPE_EXCEPTION: - if (xdebug_hash_find(XG_DBG(context).exception_breakpoints, hkey, strlen(hkey), (void *) &brk_info)) { - return brk_info; - } - break; - } - return brk_info; -} - -static int breakpoint_remove(int type, char *hkey) -{ - xdebug_llist_element *le; - xdebug_brk_info *brk_info = NULL; - int retval = FAILURE; - - switch (type) { - case XDEBUG_BREAKPOINT_TYPE_LINE: - case XDEBUG_BREAKPOINT_TYPE_CONDITIONAL: { - xdebug_arg *parts; - - /* First we split the key into filename and linenumber */ - parts = xdebug_arg_ctor(); - xdebug_explode("$", hkey, parts, -1); - - /* Second we loop through the list of file/line breakpoints to - * look for our thingy */ - for (le = XDEBUG_LLIST_HEAD(XG_DBG(context).line_breakpoints); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { - brk_info = XDEBUG_LLIST_VALP(le); - - if (atoi(parts->args1) == brk_info->original_lineno && memcmp(ZSTR_VAL(brk_info->filename), parts->args0, ZSTR_LEN(brk_info->filename)) == 0) { - xdebug_llist_remove(XG_DBG(context).line_breakpoints, le, NULL); - retval = SUCCESS; - break; - } - } - - /* Cleaning up */ - xdebug_arg_dtor(parts); - break; - } - - case XDEBUG_BREAKPOINT_TYPE_CALL: - case XDEBUG_BREAKPOINT_TYPE_RETURN: - if (xdebug_hash_delete(XG_DBG(context).function_breakpoints, hkey, strlen(hkey))) { - retval = SUCCESS; - } - break; - - case XDEBUG_BREAKPOINT_TYPE_EXCEPTION: - if (xdebug_hash_delete(XG_DBG(context).exception_breakpoints, hkey, strlen(hkey))) { - retval = SUCCESS; - } - break; - } - return retval; -} - -#define BREAKPOINT_ACTION_GET 1 -#define BREAKPOINT_ACTION_REMOVE 2 -#define BREAKPOINT_ACTION_UPDATE 3 - -#define BREAKPOINT_CHANGE_STATE() \ - XDEBUG_STR_SWITCH(CMD_OPTION_CHAR('s')) { \ - XDEBUG_STR_CASE("enabled") \ - brk_info->disabled = 0; \ - XDEBUG_STR_CASE_END \ - \ - XDEBUG_STR_CASE("disabled") \ - brk_info->disabled = 1; \ - XDEBUG_STR_CASE_END \ - \ - XDEBUG_STR_CASE_DEFAULT \ - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); \ - XDEBUG_STR_CASE_DEFAULT_END \ - } - -#define BREAKPOINT_CHANGE_OPERATOR() \ - XDEBUG_STR_SWITCH(CMD_OPTION_CHAR('o')) { \ - XDEBUG_STR_CASE(">=") \ - brk_info->hit_condition = XDEBUG_HIT_GREATER_EQUAL; \ - XDEBUG_STR_CASE_END \ - \ - XDEBUG_STR_CASE("==") \ - brk_info->hit_condition = XDEBUG_HIT_EQUAL; \ - XDEBUG_STR_CASE_END \ - \ - XDEBUG_STR_CASE("%") \ - brk_info->hit_condition = XDEBUG_HIT_MOD; \ - XDEBUG_STR_CASE_END \ - \ - XDEBUG_STR_CASE_DEFAULT \ - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); \ - XDEBUG_STR_CASE_DEFAULT_END \ - } - - - -static void breakpoint_do_action(DBGP_FUNC_PARAMETERS, int action) -{ - int type; - char *hkey; - xdebug_brk_info *brk_info; - xdebug_xml_node *breakpoint_node; - XDEBUG_STR_SWITCH_DECL; - - if (!CMD_OPTION_SET('d')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - - /* Lets check if it exists */ - if (breakpoint_admin_fetch(context, CMD_OPTION_CHAR('d'), &type, (char**) &hkey) == FAILURE) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_NO_SUCH_BREAKPOINT) - } - - /* so it exists, now we're going to find it in the correct hash/list - * and return the info we have on it */ - brk_info = breakpoint_brk_info_fetch(type, hkey); - - if (action == BREAKPOINT_ACTION_UPDATE) { - if (CMD_OPTION_SET('s')) { - BREAKPOINT_CHANGE_STATE(); - } - if (CMD_OPTION_SET('n')) { - brk_info->original_lineno = strtol(CMD_OPTION_CHAR('n'), NULL, 10); - brk_info->resolved_lineno = brk_info->original_lineno; - } - if (CMD_OPTION_SET('h')) { - brk_info->hit_value = strtol(CMD_OPTION_CHAR('h'), NULL, 10); - } - if (CMD_OPTION_SET('o')) { - BREAKPOINT_CHANGE_OPERATOR(); - } - } - - breakpoint_node = xdebug_xml_node_init("breakpoint"); - breakpoint_brk_info_add(breakpoint_node, brk_info); - xdebug_xml_add_child(*retval, breakpoint_node); - - if (action == BREAKPOINT_ACTION_REMOVE) { - /* Now we remove the crap */ - breakpoint_remove(type, hkey); - breakpoint_admin_remove(context, CMD_OPTION_CHAR('d')); - } -} - -DBGP_FUNC(breakpoint_get) -{ - breakpoint_do_action(DBGP_FUNC_PASS_PARAMETERS, BREAKPOINT_ACTION_GET); -} - -DBGP_FUNC(breakpoint_remove) -{ - breakpoint_do_action(DBGP_FUNC_PASS_PARAMETERS, BREAKPOINT_ACTION_REMOVE); -} - -DBGP_FUNC(breakpoint_update) -{ - breakpoint_do_action(DBGP_FUNC_PASS_PARAMETERS, BREAKPOINT_ACTION_UPDATE); -} - - -static void breakpoint_list_helper(void *xml, xdebug_hash_element *he, void *dummy) -{ - xdebug_xml_node *xml_node = (xdebug_xml_node*) xml; - xdebug_xml_node *child; - xdebug_brk_admin *admin = (xdebug_brk_admin*) he->ptr; - xdebug_brk_info *brk_info; - - child = xdebug_xml_node_init("breakpoint"); - brk_info = breakpoint_brk_info_fetch(admin->type, admin->key); - breakpoint_brk_info_add(child, brk_info); - xdebug_xml_add_child(xml_node, child); -} - -DBGP_FUNC(breakpoint_list) -{ - xdebug_hash_apply_with_argument(context->breakpoint_list, (void *) *retval, breakpoint_list_helper, NULL); -} - -DBGP_FUNC(breakpoint_set) -{ - xdebug_brk_info *brk_info; - XDEBUG_STR_SWITCH_DECL; - - brk_info = xdebug_brk_info_ctor(); - - if (!CMD_OPTION_SET('t')) { - xdebug_brk_info_dtor(brk_info); - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } else { - int i; - int found = 0; - - for (i = 0; i < XDEBUG_BREAKPOINT_TYPES_COUNT; i++) { - if (strcmp(xdebug_breakpoint_typesi.name, CMD_OPTION_CHAR('t')) == 0) { - brk_info->brk_type = xdebug_breakpoint_typesi.value; - found = 1; - break; - } - } - - if (!found) { - xdebug_brk_info_dtor(brk_info); - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - } - - if (CMD_OPTION_SET('s')) { - BREAKPOINT_CHANGE_STATE(); - xdebug_xml_add_attribute_ex(*retval, "state", xdstrdup(CMD_OPTION_CHAR('s')), 0, 1); - } - if (CMD_OPTION_SET('o') && CMD_OPTION_SET('h')) { - BREAKPOINT_CHANGE_OPERATOR(); - brk_info->hit_value = strtol(CMD_OPTION_CHAR('h'), NULL, 10); - } - if (CMD_OPTION_SET('r')) { - brk_info->temporary = strtol(CMD_OPTION_CHAR('r'), NULL, 10); - } - - if ((strcmp(CMD_OPTION_CHAR('t'), "line") == 0) || (strcmp(CMD_OPTION_CHAR('t'), "conditional") == 0)) { - size_t new_length = 0; - char *tmp_name; - - if (!CMD_OPTION_SET('n')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - brk_info->original_lineno = strtol(CMD_OPTION_CHAR('n'), NULL, 10); - brk_info->resolved_lineno = brk_info->original_lineno; - - /* If no filename is given, we use the current one */ - if (!CMD_OPTION_SET('f')) { - function_stack_entry *fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - - if (!fse) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); - } else { - char *tmp_path = xdebug_path_from_url(fse->filename); - brk_info->filename = zend_string_init(tmp_path, strlen(tmp_path), 0); - } - } else { - char realpath_fileMAXPATHLEN; - zend_string *tmp_f = zend_string_init(CMD_OPTION_CHAR('f'), CMD_OPTION_LEN('f'), 0); - char *tmp_path = xdebug_path_from_url(tmp_f); - - brk_info->filename = zend_string_init(tmp_path, strlen(tmp_path), 0); - - /* Now we do some real path checks to resolve symlinks. */ - if (VCWD_REALPATH(ZSTR_VAL(brk_info->filename), realpath_file)) { - zend_string_release(brk_info->filename); - brk_info->filename = zend_string_init(realpath_file, strlen(realpath_file), 0); - } - - zend_string_release(tmp_f); - xdfree(tmp_path); - } - - /* Perhaps we have a break condition */ - if (CMD_OPTION_SET('-')) { - brk_info->condition = (char*) xdebug_base64_decode((unsigned char*) CMD_OPTION_CHAR('-'), CMD_OPTION_LEN('-'), &new_length); - } - - tmp_name = xdebug_sprintf("%s$%lu", ZSTR_VAL(brk_info->filename), brk_info->original_lineno); - if (strcmp(CMD_OPTION_CHAR('t'), "line") == 0) { - brk_info->id = breakpoint_admin_add(context, XDEBUG_BREAKPOINT_TYPE_LINE, tmp_name); - } else { - brk_info->id = breakpoint_admin_add(context, XDEBUG_BREAKPOINT_TYPE_CONDITIONAL, tmp_name); - } - xdfree(tmp_name); - xdebug_llist_insert_next(context->line_breakpoints, XDEBUG_LLIST_TAIL(context->line_breakpoints), (void*) brk_info); - - if (XG_DBG(context).resolved_breakpoints) { - xdebug_lines_list *lines_list; - - if (xdebug_hash_find(XG_DBG(breakable_lines_map), ZSTR_VAL(brk_info->filename), ZSTR_LEN(brk_info->filename), (void *) &lines_list)) { - line_breakpoint_resolve_helper(context, lines_list, brk_info); - } - } - } else - - if ((strcmp(CMD_OPTION_CHAR('t'), "call") == 0) || (strcmp(CMD_OPTION_CHAR('t'), "return") == 0)) { - void *dummy = NULL; - char *tmp_name; - - if (strcmp(CMD_OPTION_CHAR('t'), "call") == 0) { - brk_info->function_break_type = XDEBUG_BREAKPOINT_TYPE_CALL; - } else { - brk_info->function_break_type = XDEBUG_BREAKPOINT_TYPE_RETURN; - } - - if (!CMD_OPTION_SET('m')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - brk_info->functionname = xdstrdup(CMD_OPTION_CHAR('m')); - - if (CMD_OPTION_SET('a')) { - brk_info->classname = xdstrdup(CMD_OPTION_CHAR('a')); - tmp_name = xdebug_sprintf( - "%c/%s::%s", - brk_info->function_break_type == XDEBUG_BREAKPOINT_TYPE_CALL ? 'C' : 'R', - CMD_OPTION_CHAR('a'), CMD_OPTION_CHAR('m') - ); - } else { - tmp_name = xdebug_sprintf( - "%c/%s", - brk_info->function_break_type == XDEBUG_BREAKPOINT_TYPE_CALL ? 'C' : 'R', - CMD_OPTION_CHAR('m') - ); - } - - if (xdebug_hash_find(context->function_breakpoints, tmp_name, strlen(tmp_name), (void*) &dummy)) { - xdfree(tmp_name); - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_BREAKPOINT_NOT_SET); - } - - if (!xdebug_hash_add(context->function_breakpoints, tmp_name, strlen(tmp_name), brk_info)) { - xdfree(tmp_name); - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_BREAKPOINT_NOT_SET); - } else { - if (brk_info->function_break_type == XDEBUG_BREAKPOINT_TYPE_CALL) { - brk_info->id = breakpoint_admin_add(context, XDEBUG_BREAKPOINT_TYPE_CALL, tmp_name); - } else { - brk_info->id = breakpoint_admin_add(context, XDEBUG_BREAKPOINT_TYPE_RETURN, tmp_name); - } - } - - brk_info->resolved = XDEBUG_BRK_RESOLVED; - - xdfree(tmp_name); - } else - - if (strcmp(CMD_OPTION_CHAR('t'), "exception") == 0) { - if (!CMD_OPTION_SET('x')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - brk_info->exceptionname = xdstrdup(CMD_OPTION_CHAR('x')); - if (!xdebug_hash_add(context->exception_breakpoints, CMD_OPTION_CHAR('x'), CMD_OPTION_LEN('x'), (void*) brk_info)) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_BREAKPOINT_NOT_SET); - } else { - brk_info->id = breakpoint_admin_add(context, XDEBUG_BREAKPOINT_TYPE_EXCEPTION, CMD_OPTION_CHAR('x')); - } - - brk_info->resolved = XDEBUG_BRK_RESOLVED; - } else - - if (strcmp(CMD_OPTION_CHAR('t'), "watch") == 0) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_BREAKPOINT_TYPE_NOT_SUPPORTED); - } - - xdebug_xml_add_attribute_ex(*retval, "id", xdebug_sprintf("%lu", brk_info->id), 0, 1); - breakpoint_brk_info_add_resolved(*retval, brk_info); -} - -DBGP_FUNC(eval) -{ - char *eval_string; - xdebug_xml_node *ret_xml; - zval ret_zval; - size_t new_length = 0; - int res; - xdebug_var_export_options *options; - - if (!CMD_OPTION_SET('-')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - - options = (xdebug_var_export_options*) context->options; - - if (CMD_OPTION_SET('p')) { - options->runtime0.page = strtol(CMD_OPTION_CHAR('p'), NULL, 10); - } else { - options->runtime0.page = 0; - } - - /* base64 decode eval string */ - eval_string = (char*) xdebug_base64_decode((unsigned char*) CMD_OPTION_CHAR('-'), CMD_OPTION_LEN('-'), &new_length); - - res = xdebug_do_eval(eval_string, &ret_zval); - - xdfree(eval_string); - - /* Handle result */ - if (!res) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_EVALUATING_CODE); - } else { - ret_xml = xdebug_get_zval_value_xml_node(NULL, &ret_zval, options); - xdebug_xml_add_child(*retval, ret_xml); - zval_ptr_dtor(&ret_zval); - } -} - -/* these functions interupt PHP's output functions, so we can - redirect to our remote debugger! */ -static void xdebug_send_stream(const char *name, const char *str, unsigned int str_length) -{ - /* create an xml document to send as the stream */ - xdebug_xml_node *message; - - if (!xdebug_is_debug_connection_active()) { - return; - } - - message = xdebug_xml_node_init("stream"); - xdebug_xml_add_attribute(message, "xmlns", "urn:debugger_protocol_v1"); - xdebug_xml_add_attribute(message, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); - xdebug_xml_add_attribute_ex(message, "type", (char *)name, 0, 0); - xdebug_xml_add_text_encodel(message, xdstrndup(str, str_length), str_length); - send_message(&XG_DBG(context), message); - xdebug_xml_node_dtor(message); - - return; -} - - -DBGP_FUNC(stderr) -{ - xdebug_xml_add_attribute(*retval, "success", "0"); -} - -DBGP_FUNC(stdout) -{ - int mode = 0; - const char *success = "0"; - - if (!CMD_OPTION_SET('c')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - - mode = strtol(CMD_OPTION_CHAR('c'), NULL, 10); - XG_DBG(stdout_mode) = mode; - success = "1"; - - xdebug_xml_add_attribute_ex(*retval, "success", xdstrdup(success), 0, 1); -} - -DBGP_FUNC(stop) -{ - XG_DBG(status) = DBGP_STATUS_STOPPED; - xdebug_xml_add_attribute(*retval, "status", xdebug_dbgp_status_stringsXG_DBG(status)); - xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason)); -} - -DBGP_FUNC(run) -{ - xdebug_xml_add_attribute_ex(*retval, "filename", ZSTR_VAL(context->program_name), 0, 0); -} - -DBGP_FUNC(step_into) -{ - XG_DBG(context).do_next = 0; - XG_DBG(context).do_step = 1; - XG_DBG(context).do_finish = 0; -} - -DBGP_FUNC(step_out) -{ - function_stack_entry *fse; - - XG_DBG(context).do_next = 0; - XG_DBG(context).do_step = 0; - XG_DBG(context).do_finish = 1; - - if ((fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)))) { - XG_DBG(context).finish_level = fse->level; - XG_DBG(context).finish_func_nr = fse->function_nr; - } else { - XG_DBG(context).finish_level = -1; - XG_DBG(context).finish_func_nr = -1; - } -} - -DBGP_FUNC(step_over) -{ - function_stack_entry *fse; - - XG_DBG(context).do_next = 1; - XG_DBG(context).do_step = 0; - XG_DBG(context).do_finish = 0; - - if ((fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)))) { - XG_DBG(context).next_level = fse->level; - } else { - XG_DBG(context).next_level = 0; - } -} - -DBGP_FUNC(detach) -{ - XG_DBG(status) = DBGP_STATUS_DETACHED; - - xdebug_xml_add_attribute(*retval, "status", xdebug_dbgp_status_stringsDBGP_STATUS_STOPPED); - xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason)); - XG_DBG(context).handler->remote_deinit(&(XG_DBG(context))); - xdebug_mark_debug_connection_not_active(); - XG_DBG(stdout_mode) = 0; - XG_DBG(detached) = 1; - - if (CMD_OPTION_SET('-')) { - XG_DBG(context).detached_message = xdstrdup(CMD_OPTION_CHAR('-')); - xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "DETACH", "Debug client detached: %s.", XG_DBG(context).detached_message); - } -} - - -DBGP_FUNC(source) -{ - xdebug_str *source; - int begin = 0, end = 999999; - zend_string *filename; - function_stack_entry *fse; - - if (!CMD_OPTION_SET('f')) { - if ((fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)))) { - filename = zend_string_copy(fse->filename); - } else { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); - } - } else { - filename = zend_string_init(CMD_OPTION_CHAR('f'), CMD_OPTION_LEN('f'), 0); - } - - if (CMD_OPTION_SET('b')) { - begin = strtol(CMD_OPTION_CHAR('b'), NULL, 10); - } - if (CMD_OPTION_SET('e')) { - end = strtol(CMD_OPTION_CHAR('e'), NULL, 10); - } - - /* return_source allocates memory for source */ - XG_DBG(breakpoints_allowed) = 0; - source = return_source(filename, begin, end); - XG_DBG(breakpoints_allowed) = 1; - - zend_string_release(filename); - - if (!source) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_CANT_OPEN_FILE); - } else { - xdebug_xml_add_text_ex(*retval, xdstrdup(source->d), source->l, 1, 1); - xdebug_str_free(source); - } -} - -DBGP_FUNC(feature_get) -{ - xdebug_var_export_options *options; - XDEBUG_STR_SWITCH_DECL; - - options = (xdebug_var_export_options*) context->options; - - if (!CMD_OPTION_SET('n')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - xdebug_xml_add_attribute_ex(*retval, "feature_name", xdstrdup(CMD_OPTION_CHAR('n')), 0, 1); - - XDEBUG_STR_SWITCH(CMD_OPTION_CHAR('n')) { - XDEBUG_STR_CASE("breakpoint_languages") - xdebug_xml_add_attribute(*retval, "supported", "0"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("breakpoint_types") - xdebug_xml_add_text(*retval, xdstrdup("line conditional call return exception")); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("data_encoding") - xdebug_xml_add_attribute(*retval, "supported", "0"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("encoding") - xdebug_xml_add_text(*retval, xdstrdup("iso-8859-1")); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("language_name") - xdebug_xml_add_text(*retval, xdstrdup("PHP")); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("language_supports_threads") - xdebug_xml_add_text(*retval, xdstrdup("0")); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("language_version") - xdebug_xml_add_text(*retval, xdstrdup(XG_BASE(php_version_run_time))); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("max_children") - xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", options->max_children)); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("max_data") - xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", options->max_data)); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("max_depth") - xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", options->max_depth)); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("protocol_version") - xdebug_xml_add_text(*retval, xdstrdup(DBGP_VERSION)); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("supported_encodings") - xdebug_xml_add_text(*retval, xdstrdup("iso-8859-1")); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("supports_async") - xdebug_xml_add_text(*retval, xdstrdup("0")); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("supports_postmortem") - xdebug_xml_add_text(*retval, xdstrdup("1")); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("show_hidden") - xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", options->show_hidden)); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("extended_properties") - xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", options->extended_properties)); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("notify_ok") - xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", XG_DBG(context).send_notifications)); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("resolved_breakpoints") - xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", XG_DBG(context).resolved_breakpoints)); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("breakpoint_details") - xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", XG_DBG(context).breakpoint_details)); - xdebug_xml_add_attribute(*retval, "supported", "1"); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE_DEFAULT - xdebug_xml_add_text(*retval, xdstrdup(lookup_cmd(CMD_OPTION_CHAR('n')) ? "1" : "0")); - xdebug_xml_add_attribute(*retval, "supported", lookup_cmd(CMD_OPTION_CHAR('n')) ? "1" : "0"); - XDEBUG_STR_CASE_DEFAULT_END - } -} - -DBGP_FUNC(feature_set) -{ - xdebug_var_export_options *options; - XDEBUG_STR_SWITCH_DECL; - - options = (xdebug_var_export_options*) context->options; - - if (!CMD_OPTION_SET('n') || !CMD_OPTION_SET('v')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - - XDEBUG_STR_SWITCH(CMD_OPTION_CHAR('n')) { - - XDEBUG_STR_CASE("encoding") - if (strcmp(CMD_OPTION_CHAR('v'), "iso-8859-1") != 0) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_ENCODING_NOT_SUPPORTED); - } - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("max_children") - options->max_children = strtol(CMD_OPTION_CHAR('v'), NULL, 10); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("max_data") - options->max_data = strtol(CMD_OPTION_CHAR('v'), NULL, 10); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("max_depth") - int i; - options->max_depth = strtol(CMD_OPTION_CHAR('v'), NULL, 10); - - /* Reallocating page structure */ - xdfree(options->runtime); - options->runtime = (xdebug_var_runtime_page*) xdmalloc(options->max_depth * sizeof(xdebug_var_runtime_page)); - for (i = 0; i < options->max_depth; i++) { - options->runtimei.page = 0; - options->runtimei.current_element_nr = 0; - } - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("show_hidden") - options->show_hidden = strtol(CMD_OPTION_CHAR('v'), NULL, 10); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("multiple_sessions") - /* FIXME: Add new boolean option check / struct field for this */ - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("extended_properties") - options->extended_properties = strtol(CMD_OPTION_CHAR('v'), NULL, 10); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("notify_ok") - XG_DBG(context).send_notifications = strtol(CMD_OPTION_CHAR('v'), NULL, 10); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("resolved_breakpoints") - XG_DBG(context).resolved_breakpoints = strtol(CMD_OPTION_CHAR('v'), NULL, 10); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("breakpoint_details") - XG_DBG(context).breakpoint_details = strtol(CMD_OPTION_CHAR('v'), NULL, 10); - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE_DEFAULT - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - XDEBUG_STR_CASE_DEFAULT_END - } - xdebug_xml_add_attribute_ex(*retval, "feature", xdstrdup(CMD_OPTION_CHAR('n')), 0, 1); - xdebug_xml_add_attribute_ex(*retval, "success", "1", 0, 0); -} - -DBGP_FUNC(typemap_get) -{ - int i; - xdebug_xml_node *type; - - xdebug_xml_add_attribute(*retval, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - xdebug_xml_add_attribute(*retval, "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); - - /* Add our basic types */ - for (i = 0; i < XDEBUG_TYPES_COUNT; i++) { - type = xdebug_xml_node_init("map"); - xdebug_xml_add_attribute(type, "name", xdebug_dbgp_typemapi1); - xdebug_xml_add_attribute(type, "type", xdebug_dbgp_typemapi0); - if (xdebug_dbgp_typemapi2) { - xdebug_xml_add_attribute(type, "xsi:type", xdebug_dbgp_typemapi2); - } - xdebug_xml_add_child(*retval, type); - } -} - -static int add_constant_node(xdebug_xml_node *node, xdebug_str *name, zval *const_val, xdebug_var_export_options *options) -{ - xdebug_xml_node *contents; - - contents = xdebug_get_zval_value_xml_node_ex(name, const_val, XDEBUG_VAR_TYPE_CONSTANT, options); - if (!contents) { - return FAILURE; - } - - xdebug_xml_expand_attribute_value(contents, "facet", "constant"); - xdebug_xml_add_child(node, contents); - - return SUCCESS; -} - -static int add_variable_node(xdebug_xml_node *node, xdebug_str *name, int var_only, int non_null, int no_eval, xdebug_var_export_options *options) -{ - xdebug_xml_node *contents; - - contents = get_symbol(name, options); - if (!contents) { - return FAILURE; - } - - xdebug_xml_add_child(node, contents); - - return SUCCESS; -} - -static int xdebug_get_constant(xdebug_str *val, zval *const_val) -{ - zval *tmp_const = NULL; - tmp_const = zend_get_constant_str(val->d, val->l); - - if (!tmp_const) { - return 0; - } - - *const_val = *tmp_const; - - return 1; -} - -DBGP_FUNC(property_get) -{ - int depth = 0; - int context_nr = 0; - function_stack_entry *fse; - int old_max_data; - xdebug_var_export_options *options = (xdebug_var_export_options*) context->options; - - if (!CMD_OPTION_SET('n')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - - if (CMD_OPTION_SET('d')) { - depth = strtol(CMD_OPTION_CHAR('d'), NULL, 10); - } - - if (CMD_OPTION_SET('c')) { - context_nr = strtol(CMD_OPTION_CHAR('c'), NULL, 10); - } - - /* Set the symbol table corresponding with the requested stack depth */ - if (context_nr == 0) { /* locals */ - if ((fse = xdebug_get_stack_frame(depth))) { - function_stack_entry *old_fse; - - if (!fse->user_defined) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTENT); - } - - old_fse = xdebug_get_stack_frame(depth - 1); - - if (depth > 0) { - xdebug_lib_set_active_data(old_fse->execute_data); - } else { - xdebug_lib_set_active_data(EG(current_execute_data)); - } - xdebug_lib_set_active_stack_entry(fse); - xdebug_lib_set_active_symbol_table(fse->symbol_table); - } else { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); - } - } else if (context_nr == 1) { /* superglobals */ - xdebug_lib_set_active_symbol_table(&EG(symbol_table)); - } else if (context_nr == 2) { /* constants */ - /* Do nothing */ - } else { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - - if (CMD_OPTION_SET('p')) { - options->runtime0.page = strtol(CMD_OPTION_CHAR('p'), NULL, 10); - } else { - options->runtime0.page = 0; - } - - /* Override max data size if necessary */ - old_max_data = options->max_data; - if (CMD_OPTION_SET('m')) { - options->max_data= strtol(CMD_OPTION_CHAR('m'), NULL, 10); - } - - if (context_nr == 2) { /* constants */ - zval const_val; - - if (!xdebug_get_constant(CMD_OPTION_XDEBUG_STR('n'), &const_val)) { - options->max_data = old_max_data; - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTENT); - } - if (add_constant_node(*retval, CMD_OPTION_XDEBUG_STR('n'), &const_val, options) == FAILURE) { - options->max_data = old_max_data; - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTENT); - } - } else { - int add_var_retval; - - XG_DBG(context).inhibit_notifications = 1; - add_var_retval = add_variable_node(*retval, CMD_OPTION_XDEBUG_STR('n'), 1, 0, 0, options); - XG_DBG(context).inhibit_notifications = 0; - - if (add_var_retval) { - options->max_data = old_max_data; - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTENT); - } - } - options->max_data = old_max_data; -} - -DBGP_FUNC(property_set) -{ - unsigned char *new_value; - size_t new_length = 0; - int depth = 0; - int context_nr = 0; - int res; - char *eval_string; - const char *cast_as; - zval ret_zval; - function_stack_entry *fse; - xdebug_var_export_options *options = (xdebug_var_export_options*) context->options; - zend_execute_data *original_execute_data; - XDEBUG_STR_SWITCH_DECL; - - if (!CMD_OPTION_SET('n')) { /* name */ - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - - if (!CMD_OPTION_SET('-')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - - if (CMD_OPTION_SET('d')) { /* depth */ - depth = strtol(CMD_OPTION_CHAR('d'), NULL, 10); - } - - if (CMD_OPTION_SET('c')) { /* context_id */ - context_nr = strtol(CMD_OPTION_CHAR('c'), NULL, 10); - } - - /* Set the symbol table corresponding with the requested stack depth */ - if (context_nr == 0) { /* locals */ - if ((fse = xdebug_get_stack_frame(depth))) { - function_stack_entry *old_fse = xdebug_get_stack_frame(depth - 1); - - if (depth > 0) { - xdebug_lib_set_active_data(old_fse->execute_data); - } else { - xdebug_lib_set_active_data(EG(current_execute_data)); - } - xdebug_lib_set_active_stack_entry(fse); - xdebug_lib_set_active_symbol_table(fse->symbol_table); - } else { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); - } - } else { /* superglobals */ - xdebug_lib_set_active_symbol_table(&EG(symbol_table)); - } - - if (CMD_OPTION_SET('p')) { - options->runtime0.page = strtol(CMD_OPTION_CHAR('p'), NULL, 10); - } else { - options->runtime0.page = 0; - } - - new_value = xdebug_base64_decode((unsigned char*) CMD_OPTION_CHAR('-'), CMD_OPTION_LEN('-'), &new_length); - - /* Set a cast, if requested through the 't' option */ - cast_as = ""; - - if (CMD_OPTION_SET('t')) { - XDEBUG_STR_SWITCH(CMD_OPTION_CHAR('t')) { - XDEBUG_STR_CASE("bool") - cast_as = "(bool) "; - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("int") - cast_as = "(int) "; - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("float") - cast_as = "(float) "; - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE("string") - cast_as = "(string) "; - XDEBUG_STR_CASE_END - - XDEBUG_STR_CASE_DEFAULT - xdebug_xml_add_attribute(*retval, "success", "0"); - XDEBUG_STR_CASE_DEFAULT_END - } - } - - /* backup executor state */ - if (depth > 0) { - original_execute_data = EG(current_execute_data); - - EG(current_execute_data) = xdebug_lib_get_active_data(); - } - - /* Do the eval */ - eval_string = xdebug_sprintf("%s = %s %s", CMD_OPTION_CHAR('n'), cast_as, new_value); - res = xdebug_do_eval(eval_string, &ret_zval); - - /* restore executor state */ - if (depth > 0) { - EG(current_execute_data) = original_execute_data; - } - - /* Free data */ - xdfree(eval_string); - xdfree(new_value); - - /* Handle result */ - if (!res) { - /* don't send an error, send success = zero */ - xdebug_xml_add_attribute(*retval, "success", "0"); - } else { - zval_dtor(&ret_zval); - xdebug_xml_add_attribute(*retval, "success", "1"); - } -} - -static int add_variable_contents_node(xdebug_xml_node *node, xdebug_str *name, int var_only, int non_null, int no_eval, xdebug_var_export_options *options) -{ - int contents_found; - - contents_found = get_symbol_contents(name, node, options); - - if (!contents_found) { - return FAILURE; - } - - return SUCCESS; -} - -DBGP_FUNC(property_value) -{ - int depth = 0; - int context_nr = 0; - function_stack_entry *fse; - int old_max_data; - xdebug_var_export_options *options = (xdebug_var_export_options*) context->options; - - if (!CMD_OPTION_SET('n')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - - if (CMD_OPTION_SET('d')) { - depth = strtol(CMD_OPTION_CHAR('d'), NULL, 10); - } - - if (CMD_OPTION_SET('c')) { - context_nr = strtol(CMD_OPTION_CHAR('c'), NULL, 10); - } - - /* Set the symbol table corresponding with the requested stack depth */ - if (context_nr == 0) { /* locals */ - if ((fse = xdebug_get_stack_frame(depth))) { - function_stack_entry *old_fse = xdebug_get_stack_frame(depth - 1); - - if (depth > 0) { - xdebug_lib_set_active_data(old_fse->execute_data); - } else { - xdebug_lib_set_active_data(EG(current_execute_data)); - } - xdebug_lib_set_active_stack_entry(fse); - xdebug_lib_set_active_symbol_table(fse->symbol_table); - } else { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); - } - } else { /* superglobals */ - xdebug_lib_set_active_symbol_table(&EG(symbol_table)); - } - - if (CMD_OPTION_SET('p')) { - options->runtime0.page = strtol(CMD_OPTION_CHAR('p'), NULL, 10); - } else { - options->runtime0.page = 0; - } - - /* Override max data size if necessary */ - old_max_data = options->max_data; - if (CMD_OPTION_SET('m')) { - options->max_data = strtol(CMD_OPTION_CHAR('m'), NULL, 10); - } - if (options->max_data < 0) { - options->max_data = old_max_data; - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - if (add_variable_contents_node(*retval, CMD_OPTION_XDEBUG_STR('n'), 1, 0, 0, options) == FAILURE) { - options->max_data = old_max_data; - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTENT); - } - options->max_data = old_max_data; -} - -static void attach_declared_var_with_contents(void *xml, xdebug_hash_element* he, void *options) -{ - xdebug_str *name = (xdebug_str*) he->ptr; - xdebug_xml_node *node = (xdebug_xml_node *) xml; - xdebug_xml_node *contents; - - contents = get_symbol(name, options); - if (!contents) { - xdebug_var_xml_attach_uninitialized_var(options, node, name); - return; - } - - xdebug_xml_add_child(node, contents); -} - -static int xdebug_add_filtered_symboltable_var(zval *symbol, int num_args, va_list args, zend_hash_key *hash_key) -{ - xdebug_hash *tmp_hash; - - tmp_hash = va_arg(args, xdebug_hash *); - - /* We really ought to deal properly with non-associate keys for symbol - * tables, but for now, we'll just ignore them. */ - if (!hash_key->key) { return 0; } - - if (hash_key->key->val0 == '\0') { return 0; } - - if (strcmp("argc", hash_key->key->val) == 0) { return 0; } - if (strcmp("argv", hash_key->key->val) == 0) { return 0; } - if (hash_key->key->val0 == '_') { - if (strcmp("_COOKIE", hash_key->key->val) == 0) { return 0; } - if (strcmp("_ENV", hash_key->key->val) == 0) { return 0; } - if (strcmp("_FILES", hash_key->key->val) == 0) { return 0; } - if (strcmp("_GET", hash_key->key->val) == 0) { return 0; } - if (strcmp("_POST", hash_key->key->val) == 0) { return 0; } - if (strcmp("_REQUEST", hash_key->key->val) == 0) { return 0; } - if (strcmp("_SERVER", hash_key->key->val) == 0) { return 0; } - if (strcmp("_SESSION", hash_key->key->val) == 0) { return 0; } - } - if (hash_key->key->val0 == 'H') { - if (strcmp("HTTP_COOKIE_VARS", hash_key->key->val) == 0) { return 0; } - if (strcmp("HTTP_ENV_VARS", hash_key->key->val) == 0) { return 0; } - if (strcmp("HTTP_GET_VARS", hash_key->key->val) == 0) { return 0; } - if (strcmp("HTTP_POST_VARS", hash_key->key->val) == 0) { return 0; } - if (strcmp("HTTP_POST_FILES", hash_key->key->val) == 0) { return 0; } - if (strcmp("HTTP_RAW_POST_DATA", hash_key->key->val) == 0) { return 0; } - if (strcmp("HTTP_SERVER_VARS", hash_key->key->val) == 0) { return 0; } - if (strcmp("HTTP_SESSION_VARS", hash_key->key->val) == 0) { return 0; } - } - if (strcmp("GLOBALS", hash_key->key->val) == 0) { return 0; } - - xdebug_hash_add(tmp_hash, (char*) hash_key->key->val, hash_key->key->len, xdebug_str_create(hash_key->key->val, hash_key->key->len)); - - return 0; -} - -static int attach_context_vars(xdebug_xml_node *node, xdebug_var_export_options *options, long context_id, long depth, void (*func)(void *, xdebug_hash_element*, void*)) -{ - function_stack_entry *fse; - char *var_name; - - /* right now, we only have zero, one, or two with one being globals, which - * is always the head of the stack */ - if (context_id == 1) { - /* add super globals */ - xdebug_lib_set_active_symbol_table(&EG(symbol_table)); - xdebug_lib_set_active_data(NULL); - add_variable_node(node, XDEBUG_STR_WRAP_CHAR("_COOKIE"), 1, 1, 0, options); - add_variable_node(node, XDEBUG_STR_WRAP_CHAR("_ENV"), 1, 1, 0, options); - add_variable_node(node, XDEBUG_STR_WRAP_CHAR("_FILES"), 1, 1, 0, options); - add_variable_node(node, XDEBUG_STR_WRAP_CHAR("_GET"), 1, 1, 0, options); - add_variable_node(node, XDEBUG_STR_WRAP_CHAR("_POST"), 1, 1, 0, options); - add_variable_node(node, XDEBUG_STR_WRAP_CHAR("_REQUEST"), 1, 1, 0, options); - add_variable_node(node, XDEBUG_STR_WRAP_CHAR("_SERVER"), 1, 1, 0, options); - add_variable_node(node, XDEBUG_STR_WRAP_CHAR("_SESSION"), 1, 1, 0, options); - add_variable_node(node, XDEBUG_STR_WRAP_CHAR("GLOBALS"), 1, 1, 0, options); - xdebug_lib_set_active_symbol_table(NULL); - return 0; - } - - /* add user defined constants */ - if (context_id == 2) { - zend_constant *val; - - ZEND_HASH_FOREACH_PTR(EG(zend_constants), val) { - xdebug_str *tmp_name; - - if (!val->name) { - /* skip special constants */ - continue; - } - - if (XDEBUG_ZEND_CONSTANT_MODULE_NUMBER(val) != PHP_USER_CONSTANT) { - /* we're only interested in user defined constants */ - continue; - } - - tmp_name = xdebug_str_create(val->name->val, val->name->len); - add_constant_node(node, tmp_name, &(val->value), options); - xdebug_str_free(tmp_name); - } ZEND_HASH_FOREACH_END(); - - return 0; - } - - /* Here the context_id is 0 */ - if ((fse = xdebug_get_stack_frame(depth))) { - function_stack_entry *old_fse = xdebug_get_stack_frame(depth - 1); - - if (depth > 0) { - xdebug_lib_set_active_data(old_fse->execute_data); - } else { - xdebug_lib_set_active_data(EG(current_execute_data)); - } - xdebug_lib_set_active_symbol_table(fse->symbol_table); - - /* Only show vars when they are scanned */ - if (fse->declared_vars) { - xdebug_hash *tmp_hash; - - /* Get a hash from all the used vars (which can have duplicates) */ - tmp_hash = xdebug_declared_var_hash_from_llist(fse->declared_vars); - - /* Check for dynamically defined variables, but make sure we don't already - * have them. Also exclude superglobals and argv/argc */ - if (xdebug_lib_has_active_symbol_table()) { - zend_hash_apply_with_arguments(xdebug_lib_get_active_symbol_table(), (apply_func_args_t) xdebug_add_filtered_symboltable_var, 1, tmp_hash); - } - - /* Add all the found variables to the node */ - xdebug_hash_apply_with_argument(tmp_hash, (void *) node, func, (void *) options); - - /* Zend engine 2 does not give us $this, eval so we can get it */ - if (!xdebug_hash_find(tmp_hash, "this", 4, (void *) &var_name)) { - add_variable_node(node, XDEBUG_STR_WRAP_CHAR("this"), 1, 1, 0, options); - } - - xdebug_hash_destroy(tmp_hash); - } - - /* Check for static variables and constants, but only if it's a static - * method call as we attach constants and static properties to "this" - * too normally. */ - if (fse->function.type == XFUNC_STATIC_MEMBER) { - zend_class_entry *ce = zend_fetch_class(fse->function.object_class, ZEND_FETCH_CLASS_DEFAULT); - -#if PHP_VERSION_ID >= 70400 - if (ce->type == ZEND_INTERNAL_CLASS || (ce->ce_flags & ZEND_ACC_IMMUTABLE)) { - zend_class_init_statics(ce); - } -#endif - - xdebug_var_xml_attach_static_vars(node, options, ce); - } - - xdebug_lib_set_active_data(NULL); - xdebug_lib_set_active_symbol_table(NULL); - return 0; - } - - return 1; -} - -DBGP_FUNC(stack_depth) -{ - xdebug_xml_add_attribute_ex(*retval, "depth", xdebug_sprintf("%lu", XDEBUG_VECTOR_COUNT(XG_BASE(stack))), 0, 1); -} - -DBGP_FUNC(stack_get) -{ - xdebug_xml_node *stackframe; - long depth; - - if (CMD_OPTION_SET('d')) { - depth = strtol(CMD_OPTION_CHAR('d'), NULL, 10); - if (depth >= 0 && depth < (long) XDEBUG_VECTOR_COUNT(XG_BASE(stack))) { - stackframe = return_stackframe(depth); - xdebug_xml_add_child(*retval, stackframe); - } else { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); - } - } else { - function_stack_entry *fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - int i = 0; - - for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, fse--) { - stackframe = return_stackframe(i); - xdebug_xml_add_child(*retval, stackframe); - } - } -} - -DBGP_FUNC(status) -{ - xdebug_xml_add_attribute(*retval, "status", xdebug_dbgp_status_stringsXG_DBG(status)); - xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason)); -} - - -DBGP_FUNC(context_names) -{ - xdebug_xml_node *child; - - child = xdebug_xml_node_init("context"); - xdebug_xml_add_attribute(child, "name", "Locals"); - xdebug_xml_add_attribute(child, "id", "0"); - xdebug_xml_add_child(*retval, child); - - child = xdebug_xml_node_init("context"); - xdebug_xml_add_attribute(child, "name", "Superglobals"); - xdebug_xml_add_attribute(child, "id", "1"); - xdebug_xml_add_child(*retval, child); - - child = xdebug_xml_node_init("context"); - xdebug_xml_add_attribute(child, "name", "User defined constants"); - xdebug_xml_add_attribute(child, "id", "2"); - xdebug_xml_add_child(*retval, child); -} - -DBGP_FUNC(context_get) -{ - int res; - int context_id = 0; - int depth = 0; - xdebug_var_export_options *options = (xdebug_var_export_options*) context->options; - - if (CMD_OPTION_SET('c')) { - context_id = atol(CMD_OPTION_CHAR('c')); - } - if (CMD_OPTION_SET('d')) { - depth = atol(CMD_OPTION_CHAR('d')); - } - /* Always reset to page = 0, as it might have been modified by property_get or property_value */ - options->runtime0.page = 0; - - res = attach_context_vars(*retval, options, context_id, depth, attach_declared_var_with_contents); - switch (res) { - case 1: - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); - break; - } - - xdebug_xml_add_attribute_ex(*retval, "context", xdebug_sprintf("%d", context_id), 0, 1); -} - -DBGP_FUNC(xcmd_profiler_name_get) -{ - char *filename = xdebug_get_profiler_filename(); - - if (!filename) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROFILING_NOT_STARTED); - } - - xdebug_xml_add_text(*retval, xdstrdup(filename)); -} - -DBGP_FUNC(xcmd_get_executable_lines) -{ - function_stack_entry *fse; - unsigned int i; - long depth; - xdebug_xml_node *lines, *line; - - if (!CMD_OPTION_SET('d')) { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); - } - - depth = strtol(CMD_OPTION_CHAR('d'), NULL, 10); - if (depth >= 0 && depth < (long) XDEBUG_VECTOR_COUNT(XG_BASE(stack))) { - fse = xdebug_get_stack_frame(depth); - } else { - RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); - } - - lines = xdebug_xml_node_init("xdebug:lines"); - for (i = 0; i < fse->op_array->last; i++ ) { - if (fse->op_array->opcodesi.opcode == ZEND_EXT_STMT ) { - line = xdebug_xml_node_init("xdebug:line"); - xdebug_xml_add_attribute_ex(line, "lineno", xdebug_sprintf("%lu", fse->op_array->opcodesi.lineno), 0, 1); - xdebug_xml_add_child(lines, line); - } - } - xdebug_xml_add_child(*retval, lines); -} - - -/***************************************************************************** -** Parsing functions -*/ - -/* {{{ Constants for state machine */ -#define STATE_NORMAL 0 -#define STATE_QUOTED 1 -#define STATE_OPT_FOLLOWS 2 -#define STATE_SEP_FOLLOWS 3 -#define STATE_VALUE_FOLLOWS_FIRST_CHAR 4 -#define STATE_VALUE_FOLLOWS 5 -#define STATE_SKIP_CHAR 6 -#define STATE_ESCAPED_CHAR_FOLLOWS 7 -/* }}} */ - -static void xdebug_dbgp_arg_dtor(xdebug_dbgp_arg *arg) -{ - int i; - - for (i = 0; i < 27; i++) { - if (arg->valuei) { - xdebug_str_free(arg->valuei); - } - } - xdfree(arg); -} - -static int xdebug_dbgp_parse_cmd(char *line, char **cmd, xdebug_dbgp_arg **ret_args) -{ - xdebug_dbgp_arg *args = NULL; - char *ptr; - int state; - int charescaped = 0; - char opt = ' ', *value_begin = NULL; - - args = xdmalloc(sizeof (xdebug_dbgp_arg)); - memset(args->value, 0, sizeof(args->value)); - *cmd = NULL; - - /* Find the end of the command, this is always on the first space */ - ptr = strchr(line, ' '); - if (!ptr) { - /* No space found. If the line is not empty, return the line - * and assume it only consists of the command name. If the line - * is 0 chars long, we return a failure. */ - if (strlen(line)) { - *cmd = strdup(line); - *ret_args = args; - return XDEBUG_ERROR_OK; - } else { - goto parse_error; - } - } else { - /* A space was found, so we copy everything before it - * into the cmd parameter. */ - *cmd = xdcalloc(1, ptr - line + 1); - memcpy(*cmd, line, ptr - line); - } - /* Now we loop until we find the end of the string, which is the \0 - * character */ - state = STATE_NORMAL; - do { - ptr++; - switch (state) { - case STATE_NORMAL: - if (*ptr != '-') { - goto parse_error; - } else { - state = STATE_OPT_FOLLOWS; - } - break; - case STATE_OPT_FOLLOWS: - opt = *ptr; - state = STATE_SEP_FOLLOWS; - break; - case STATE_SEP_FOLLOWS: - if (*ptr != ' ') { - goto parse_error; - } else { - state = STATE_VALUE_FOLLOWS_FIRST_CHAR; - value_begin = ptr + 1; - } - break; - case STATE_VALUE_FOLLOWS_FIRST_CHAR: - if (*ptr == '"' && opt != '-') { - value_begin = ptr + 1; - state = STATE_QUOTED; - } else { - state = STATE_VALUE_FOLLOWS; - } - break; - case STATE_VALUE_FOLLOWS: - if ((*ptr == ' ' && opt != '-') || *ptr == '\0') { - int opt_index = opt - 'a'; - - if (opt == '-') { - opt_index = 26; - } - - if (!args->valueopt_index) { - args->valueopt_index = xdebug_str_create(value_begin, ptr - value_begin); - state = STATE_NORMAL; - } else { - goto duplicate_opts; - } - } - break; - case STATE_QUOTED: - if (*ptr == '\\') { - state = STATE_ESCAPED_CHAR_FOLLOWS; - } else - if (*ptr == '"') { - int opt_index = opt - 'a'; - - if (charescaped) { - charescaped = 0; - break; - } - if (opt == '-') { - opt_index = 26; - } - - if (!args->valueopt_index) { - int len = ptr - value_begin; - - args->valueopt_index = xdebug_str_create(value_begin, len); - xdebug_stripcslashes(args->valueopt_index->d, &len); - args->valueopt_index->l = len; - - state = STATE_SKIP_CHAR; - } else { - goto duplicate_opts; - } - } - break; - case STATE_SKIP_CHAR: - state = STATE_NORMAL; - break; - case STATE_ESCAPED_CHAR_FOLLOWS: - state = STATE_QUOTED; - break; - - } - } while (*ptr); - *ret_args = args; - return XDEBUG_ERROR_OK; - -parse_error: - *ret_args = args; - return XDEBUG_ERROR_PARSE; - -duplicate_opts: - *ret_args = args; - return XDEBUG_ERROR_DUP_ARG; -} - -static int xdebug_dbgp_parse_option(xdebug_con *context, char* line, int flags, xdebug_xml_node *retval) -{ - char *cmd = NULL; - int res, ret = 0; - xdebug_dbgp_arg *args; - xdebug_dbgp_cmd *command; - xdebug_xml_node *error; - - xdebug_log(XLOG_CHAN_DEBUG, XLOG_COM, "<- %s", line); - res = xdebug_dbgp_parse_cmd(line, (char**) &cmd, (xdebug_dbgp_arg**) &args); - - /* Add command name to return packet */ - if (cmd) { - /* if no cmd res will be XDEBUG_ERROR_PARSE */ - xdebug_xml_add_attribute_ex(retval, "command", xdstrdup(cmd), 0, 1); - } - - /* Handle missing transaction ID, and if it exist add it to the result */ - if (!CMD_OPTION_SET('i')) { - /* we need the transaction_id even for errors in parse_cmd, but if - we error out here, just force the error to happen below */ - res = XDEBUG_ERROR_INVALID_ARGS; - } else { - xdebug_xml_add_attribute_ex(retval, "transaction_id", xdstrdup(CMD_OPTION_CHAR('i')), 0, 1); - } - - /* Handle parse errors */ - /* FIXME: use RETURN_RESULT here too */ - if (res != XDEBUG_ERROR_OK) { - error = xdebug_xml_node_init("error"); - xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", res), 0, 1); - xdebug_xml_add_child(retval, error); - ADD_REASON_MESSAGE(res); - } else { - - /* Execute commands and stuff */ - command = lookup_cmd(cmd); - - if (command) { - if (command->cont) { - XG_DBG(status) = DBGP_STATUS_RUNNING; - XG_DBG(reason) = DBGP_REASON_OK; - } - XG_DBG(lastcmd) = command->name; - if (XG_DBG(lasttransid)) { - xdfree(XG_DBG(lasttransid)); - } - XG_DBG(lasttransid) = xdstrdup(CMD_OPTION_CHAR('i')); - if ( - XG_DBG(status) != DBGP_STATUS_STOPPING - || - (XG_DBG(status) == DBGP_STATUS_STOPPING && command->flags & XDEBUG_DBGP_POST_MORTEM)) - { - command->handler((xdebug_xml_node**) &retval, context, args); - ret = command->cont; - } else { - error = xdebug_xml_node_init("error"); - xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", XDEBUG_ERROR_COMMAND_UNAVAILABLE), 0, 1); - ADD_REASON_MESSAGE(XDEBUG_ERROR_COMMAND_UNAVAILABLE); - xdebug_xml_add_child(retval, error); - - ret = -1; - } - } else { - error = xdebug_xml_node_init("error"); - xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", XDEBUG_ERROR_UNIMPLEMENTED), 0, 1); - ADD_REASON_MESSAGE(XDEBUG_ERROR_UNIMPLEMENTED); - xdebug_xml_add_child(retval, error); - - ret = -1; - } - } - - xdfree(cmd); - xdebug_dbgp_arg_dtor(args); - return ret; -} - -/***************************************************************************** -** Handlers for debug functions -*/ -#define READ_BUFFER_SIZE 128 - -#define FD_RL_FILE 0 -#define FD_RL_SOCKET 1 - - -static char* xdebug_fd_read_line_delim(int socketfd, fd_buf *context, int type, unsigned char delim, int *length) -{ - int size = 0, newl = 0, nbufsize = 0; - char *tmp; - char *tmp_buf = NULL; - char *ptr; - char bufferREAD_BUFFER_SIZE + 1; - - if (!context->buffer) { - context->buffer = calloc(1,1); - context->buffer_size = 0; - } - - while (context->buffer_size < 1 || context->buffercontext->buffer_size - 1 != delim) { - ptr = context->buffer + context->buffer_size; - if (type == FD_RL_FILE) { - newl = read(socketfd, buffer, READ_BUFFER_SIZE); - } else { - newl = recv(socketfd, buffer, READ_BUFFER_SIZE, 0); - } - if (newl > 0) { - context->buffer = realloc(context->buffer, context->buffer_size + newl + 1); - memcpy(context->buffer + context->buffer_size, buffer, newl); - context->buffer_size += newl; - context->buffercontext->buffer_size = '\0'; - } else if (newl == -1 && errno == EINTR) { - continue; - } else { - free(context->buffer); - context->buffer = NULL; - context->buffer_size = 0; - return NULL; - } - } - - ptr = memchr(context->buffer, delim, context->buffer_size); - size = ptr - context->buffer; - /* Copy that line into tmp */ - tmp = malloc(size + 1); - tmpsize = '\0'; - memcpy(tmp, context->buffer, size); - /* Rewrite existing buffer */ - if ((nbufsize = context->buffer_size - size - 1) > 0) { - tmp_buf = malloc(nbufsize + 1); - memcpy(tmp_buf, ptr + 1, nbufsize); - tmp_bufnbufsize = 0; - } - free(context->buffer); - context->buffer = tmp_buf; - context->buffer_size = context->buffer_size - (size + 1); - - /* Return normal line */ - if (length) { - *length = size; - } - return tmp; -} - -static int xdebug_dbgp_cmdloop(xdebug_con *context, int bail) -{ - char *option; - int length; - int ret; - xdebug_xml_node *response; - - do { - length = 0; - - option = xdebug_fd_read_line_delim(context->socket, context->buffer, FD_RL_SOCKET, '\0', &length); - if (!option) { - return 0; - } - - response = xdebug_xml_node_init("response"); - xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); - xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); - ret = xdebug_dbgp_parse_option(context, option, 0, response); - if (ret != 1) { - send_message(context, response); - } - xdebug_xml_node_dtor(response); - - free(option); - } while (0 == ret); - - if (bail && XG_DBG(status) == DBGP_STATUS_STOPPED) { - _zend_bailout((char*)__FILE__, __LINE__); - } - return ret; - -} - -static int xdebug_compare_brk_info(const void *le1, const void *le2) -{ - xdebug_brk_info *a = (xdebug_brk_info *) XDEBUG_LLIST_VALP(*(xdebug_llist_element **) le1); - xdebug_brk_info *b = (xdebug_brk_info *) XDEBUG_LLIST_VALP(*(xdebug_llist_element **) le2); - - return (a->id > b->id); -} - -int xdebug_dbgp_init(xdebug_con *context, int mode) -{ - xdebug_var_export_options *options; - xdebug_xml_node *response, *child; - int i; - - /* initialize our status information */ - if (mode == XDEBUG_REQ) { - XG_DBG(status) = DBGP_STATUS_STARTING; - XG_DBG(reason) = DBGP_REASON_OK; - } else if (mode == XDEBUG_JIT) { - XG_DBG(status) = DBGP_STATUS_BREAK; - XG_DBG(reason) = DBGP_REASON_ERROR; - } - XG_DBG(lastcmd) = NULL; - XG_DBG(lasttransid) = NULL; - - response = xdebug_xml_node_init("init"); - xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); - xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); - -/* {{{ XML Init Stuff*/ - child = xdebug_xml_node_init("engine"); - xdebug_xml_add_attribute(child, "version", XDEBUG_VERSION); - xdebug_xml_add_text(child, xdstrdup(XDEBUG_NAME)); - xdebug_xml_add_child(response, child); - - child = xdebug_xml_node_init("author"); - xdebug_xml_add_text(child, xdstrdup(XDEBUG_AUTHOR)); - xdebug_xml_add_child(response, child); - - child = xdebug_xml_node_init("url"); - xdebug_xml_add_text(child, xdstrdup(XDEBUG_URL)); - xdebug_xml_add_child(response, child); - - child = xdebug_xml_node_init("copyright"); - xdebug_xml_add_text(child, xdstrdup(XDEBUG_COPYRIGHT)); - xdebug_xml_add_child(response, child); - - if (zend_string_equals_literal(context->program_name, "-") || zend_string_equals_literal(context->program_name, "Command line code")) { - xdebug_xml_add_attribute_ex(response, "fileuri", xdstrdup("dbgp://stdin"), 0, 1); - } else { - xdebug_xml_add_attribute_ex(response, "fileuri", xdebug_path_to_url(context->program_name), 0, 1); - } - xdebug_xml_add_attribute_ex(response, "language", "PHP", 0, 0); - xdebug_xml_add_attribute_ex(response, "xdebug:language_version", XG_BASE(php_version_run_time), 0, 0); - xdebug_xml_add_attribute_ex(response, "protocol_version", DBGP_VERSION, 0, 0); - xdebug_xml_add_attribute_ex(response, "appid", xdebug_sprintf(ZEND_ULONG_FMT, xdebug_get_pid()), 0, 1); - - if (getenv("DBGP_COOKIE")) { - xdebug_xml_add_attribute_ex(response, "session", xdstrdup(getenv("DBGP_COOKIE")), 0, 1); - } - - if (XG_DBG(context).host_type == XDEBUG_CLOUD && XINI_DBG(cloud_id) && *XINI_DBG(cloud_id)) { - xdebug_xml_add_attribute_ex(response, "xdebug:userid", xdstrdup(XINI_DBG(cloud_id)), 0, 1); - } - if (XG_DBG(context).host_type == XDEBUG_CLOUD_FROM_TRIGGER_VALUE && XG_DBG(ide_key) && *XG_DBG(ide_key)) { - xdebug_xml_add_attribute_ex(response, "xdebug:userid", xdstrdup(XG_DBG(ide_key)), 0, 1); - } - if (XG_DBG(context).host_type == XDEBUG_NORMAL && XG_DBG(ide_key) && *XG_DBG(ide_key)) { - xdebug_xml_add_attribute_ex(response, "idekey", xdstrdup(XG_DBG(ide_key)), 0, 1); - } - - context->buffer = xdmalloc(sizeof(fd_buf)); - context->buffer->buffer = NULL; - context->buffer->buffer_size = 0; - - send_message_ex(context, response, DBGP_STATUS_STARTING); - xdebug_xml_node_dtor(response); -/* }}} */ - - context->options = xdmalloc(sizeof(xdebug_var_export_options)); - options = (xdebug_var_export_options*) context->options; - options->max_children = 32; - options->max_data = 1024; - options->max_depth = 1; - options->show_hidden = 0; - options->extended_properties = 0; - options->encode_as_extended_property = 0; - options->runtime = (xdebug_var_runtime_page*) xdmalloc((options->max_depth + 1) * sizeof(xdebug_var_runtime_page)); - for (i = 0; i < options->max_depth; i++) { - options->runtimei.page = 0; - options->runtimei.current_element_nr = 0; - } - - context->breakpoint_list = xdebug_hash_alloc_with_sort(64, (xdebug_hash_dtor_t) xdebug_hash_admin_dtor, xdebug_compare_brk_info); - context->function_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_brk_dtor); - context->exception_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_brk_dtor); - context->line_breakpoints = xdebug_llist_alloc((xdebug_llist_dtor) xdebug_llist_brk_dtor); - context->eval_id_lookup = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_eval_info_dtor); - context->eval_id_sequence = 0; - context->send_notifications = 0; - context->inhibit_notifications = 0; - context->resolved_breakpoints = 0; - context->breakpoint_details = 0; - - xdebug_mark_debug_connection_active(); - xdebug_dbgp_cmdloop(context, XDEBUG_CMDLOOP_BAIL); - - return 1; -} - -int xdebug_dbgp_deinit(xdebug_con *context) -{ - xdebug_xml_node *response; - xdebug_var_export_options *options; - int detaching = (XG_DBG(status) == DBGP_STATUS_DETACHED); - - if (xdebug_is_debug_connection_active()) { - XG_DBG(status) = DBGP_STATUS_STOPPING; - XG_DBG(reason) = DBGP_REASON_OK; - response = xdebug_xml_node_init("response"); - xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); - xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); - /* lastcmd and lasttransid are not always set (for example when the - * connection is severed before the first command is send) */ - if (XG_DBG(lastcmd) && XG_DBG(lasttransid)) { - xdebug_xml_add_attribute_ex(response, "command", XG_DBG(lastcmd), 0, 0); - xdebug_xml_add_attribute_ex(response, "transaction_id", XG_DBG(lasttransid), 0, 0); - } - xdebug_xml_add_attribute_ex(response, "status", xdebug_dbgp_status_stringsXG_DBG(status), 0, 0); - xdebug_xml_add_attribute_ex(response, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason), 0, 0); - - send_message(context, response); - xdebug_xml_node_dtor(response); - - if (!detaching) { - xdebug_dbgp_cmdloop(context, XDEBUG_CMDLOOP_NONBAIL); - } - } - - if (xdebug_is_debug_connection_active()) { - options = (xdebug_var_export_options*) context->options; - xdfree(options->runtime); - xdfree(context->options); - xdebug_hash_destroy(context->function_breakpoints); - xdebug_hash_destroy(context->exception_breakpoints); - xdebug_hash_destroy(context->eval_id_lookup); - xdebug_llist_destroy(context->line_breakpoints, NULL); - xdebug_hash_destroy(context->breakpoint_list); - xdfree(context->buffer); - context->buffer = NULL; - } - - if (XG_DBG(lasttransid)) { - xdfree(XG_DBG(lasttransid)); - XG_DBG(lasttransid) = NULL; - } - xdebug_mark_debug_connection_not_active(); - return 1; -} - -int xdebug_dbgp_error(xdebug_con *context, int type, char *exception_type, char *message, const char *location, const unsigned int line, xdebug_vector *stack) -{ - char *errortype; - xdebug_xml_node *response, *error; - - if (exception_type) { - errortype = exception_type; - } else { - errortype = xdebug_error_type(type); - } - - if (exception_type) { - XG_DBG(status) = DBGP_STATUS_BREAK; - XG_DBG(reason) = DBGP_REASON_EXCEPTION; - } else { - switch (type) { - case E_CORE_ERROR: - /* no break - intentionally */ - case E_ERROR: - /*case E_PARSE: the parser would return 1 (failure), we can bail out nicely */ - case E_COMPILE_ERROR: - case E_USER_ERROR: - XG_DBG(status) = DBGP_STATUS_STOPPING; - XG_DBG(reason) = DBGP_REASON_ABORTED; - break; - default: - XG_DBG(status) = DBGP_STATUS_BREAK; - XG_DBG(reason) = DBGP_REASON_ERROR; - } - } -/* - runtime_allowed = ( - (type != E_ERROR) && - (type != E_CORE_ERROR) && - (type != E_COMPILE_ERROR) && - (type != E_USER_ERROR) - ) ? XDEBUG_BREAKPOINT | XDEBUG_RUNTIME : 0; -*/ - - response = xdebug_xml_node_init("response"); - xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); - xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); - /* lastcmd and lasttransid are not always set (for example when the - * connection is severed before the first command is send) */ - if (XG_DBG(lastcmd) && XG_DBG(lasttransid)) { - xdebug_xml_add_attribute_ex(response, "command", XG_DBG(lastcmd), 0, 0); - xdebug_xml_add_attribute_ex(response, "transaction_id", XG_DBG(lasttransid), 0, 0); - } - xdebug_xml_add_attribute(response, "status", xdebug_dbgp_status_stringsXG_DBG(status)); - xdebug_xml_add_attribute(response, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason)); - - error = xdebug_xml_node_init("error"); - xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", type), 0, 1); - xdebug_xml_add_attribute_ex(error, "exception", xdstrdup(errortype), 0, 1); - xdebug_xml_add_text(error, xdstrdup(message)); - xdebug_xml_add_child(response, error); - - send_message(context, response); - xdebug_xml_node_dtor(response); - if (!exception_type) { - xdfree(errortype); - } - - xdebug_dbgp_cmdloop(context, XDEBUG_CMDLOOP_BAIL); - - return 1; -} - -int xdebug_dbgp_break_on_line(xdebug_con *context, xdebug_brk_info *brk, zend_string *filename, int lineno) -{ - char *tmp_file = ZSTR_VAL(filename); - int tmp_file_len = ZSTR_LEN(filename); - int free_tmp_file = 0; - - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "Checking whether to break on %s:%d.", ZSTR_VAL(brk->filename), brk->resolved_lineno); - - if (brk->disabled) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: Breakpoint is disabled."); - return 0; - } - - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Current location: %s:%d.", tmp_file, lineno); - - if (is_dbgp_url(brk->filename) && check_evaled_code(filename, &tmp_file)) { - free_tmp_file = 1; - tmp_file_len = strlen(tmp_file); - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Found eval code for '%s': %s.", ZSTR_VAL(filename), tmp_file); - } - - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Matching breakpoint '%s:%d' against location '%s:%d'.", ZSTR_VAL(brk->filename), brk->resolved_lineno, tmp_file, lineno); - - if (ZSTR_LEN(brk->filename) != tmp_file_len) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: File name length (%d) doesn't match with breakpoint (%zd).", tmp_file_len, ZSTR_LEN(brk->filename)); - - if (free_tmp_file) { - xdfree(tmp_file); - } - return 0; - } - - if (brk->resolved_lineno != lineno) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: Line number (%d) doesn't match with breakpoint (%d).", lineno, brk->resolved_lineno); - - if (free_tmp_file) { - xdfree(tmp_file); - } - return 0; - } - - if (strncasecmp(ZSTR_VAL(brk->filename), tmp_file, ZSTR_LEN(brk->filename)) == 0) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "F: File names match (%s).", ZSTR_VAL(brk->filename)); - - if (free_tmp_file) { - xdfree(tmp_file); - } - return 1; - } - - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: File names (%s) doesn't match with breakpoint (%s).", tmp_file, ZSTR_VAL(brk->filename)); - - if (free_tmp_file) { - xdfree(tmp_file); - } - return 0; -} - -int xdebug_dbgp_breakpoint(xdebug_con *context, xdebug_vector *stack, zend_string *filename, long lineno, int type, char *exception, char *code, const char *message, xdebug_brk_info *brk_info) -{ - xdebug_xml_node *response, *error_container; - - XG_DBG(status) = DBGP_STATUS_BREAK; - XG_DBG(reason) = DBGP_REASON_OK; - - response = xdebug_xml_node_init("response"); - xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); - xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); - /* lastcmd and lasttransid are not always set (for example when the - * connection is severed before the first command is send) */ - if (XG_DBG(lastcmd) && XG_DBG(lasttransid)) { - xdebug_xml_add_attribute_ex(response, "command", XG_DBG(lastcmd), 0, 0); - xdebug_xml_add_attribute_ex(response, "transaction_id", XG_DBG(lasttransid), 0, 0); - } - xdebug_xml_add_attribute(response, "status", xdebug_dbgp_status_stringsXG_DBG(status)); - xdebug_xml_add_attribute(response, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason)); - - error_container = xdebug_xml_node_init("xdebug:message"); - if (filename) { - char *tmp_filename = NULL; - - if (check_evaled_code(filename, &tmp_filename)) { - xdebug_xml_add_attribute_ex(error_container, "filename", tmp_filename, 0, 0); - xdfree(tmp_filename); - } else { - xdebug_xml_add_attribute_ex(error_container, "filename", xdebug_path_to_url(filename), 0, 1); - } - } - if (lineno) { - xdebug_xml_add_attribute_ex(error_container, "lineno", xdebug_sprintf("%lu", lineno), 0, 1); - } - if (exception) { - xdebug_xml_add_attribute_ex(error_container, "exception", xdstrdup(exception), 0, 1); - } - if (code) { - xdebug_xml_add_attribute_ex(error_container, "code", xdstrdup(code), 0, 1); - } - if (message) { - xdebug_xml_add_text(error_container, xdstrdup(message)); - } - xdebug_xml_add_child(response, error_container); - - if (XG_DBG(context).breakpoint_details && brk_info) { - xdebug_xml_node *breakpoint_node = xdebug_xml_node_init("breakpoint"); - breakpoint_brk_info_add(breakpoint_node, brk_info); - xdebug_xml_add_child(response, breakpoint_node); - } - - send_message(context, response); - xdebug_xml_node_dtor(response); - - XG_DBG(lastcmd) = NULL; - if (XG_DBG(lasttransid)) { - xdfree(XG_DBG(lasttransid)); - XG_DBG(lasttransid) = NULL; - } - - xdebug_dbgp_cmdloop(context, XDEBUG_CMDLOOP_BAIL); - - return xdebug_is_debug_connection_active(); -} - -static int xdebug_dbgp_resolved_breakpoint_notification(xdebug_con *context, xdebug_brk_info *brk_info) -{ - xdebug_xml_node *response, *child; - - if (!context->send_notifications) { - return 0; - } - - response = xdebug_xml_node_init("notify"); - xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); - xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); - xdebug_xml_add_attribute(response, "name", "breakpoint_resolved"); - - child = xdebug_xml_node_init("breakpoint"); - breakpoint_brk_info_add(child, brk_info); - xdebug_xml_add_child(response, child); - - send_message(context, response); - xdebug_xml_node_dtor(response); - - return 1; -} - -/* -static void function_breakpoint_resolve_helper(void *rctxt, xdebug_brk_info *brk_info, xdebug_hash_element *he) -{ - xdebug_dbgp_resolve_context *ctxt = (xdebug_dbgp_resolve_context*) rctxt; - - if (brk_info->resolved == XDEBUG_BRK_RESOLVED) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: %s breakpoint for '%s' has already been resolved.", - XDEBUG_BREAKPOINT_TYPE_NAME(brk_info->brk_type), ctxt->fse->function.function); - return; - } - - if (ctxt->fse->function.type == XFUNC_NORMAL) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: '%s' is a normal function (%02x).", ctxt->fse->function.function, ctxt->fse->function.type); - - if (strcmp(ctxt->fse->function.function, brk_info->functionname) == 0) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "F: Breakpoint function (%s) matches current function (%s).", brk_info->functionname, ctxt->fse->function.function); - brk_info->resolved = XDEBUG_BRK_RESOLVED; - xdebug_dbgp_resolved_breakpoint_notification(ctxt->context, brk_info); - return; - } - } else if (ctxt->fse->function.type == XFUNC_MEMBER || ctxt->fse->function.type == XFUNC_STATIC_MEMBER) { - char *tmp_name = NULL; - size_t tmp_len = 0; - - tmp_len = strlen(ctxt->fse->function.class) + strlen(ctxt->fse->function.function) + 3; - tmp_name = xdmalloc(tmp_len); - snprintf(tmp_name, tmp_len, "%s::%s", ctxt->fse->function.class, ctxt->fse->function.function); - - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: '%s::%s' is a normal method (%02x).", ctxt->fse->function.class, ctxt->fse->function.function, ctxt->fse->function.type); - - if (strcmp(tmp_name, brk_info->functionname) == 0) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "F: Breakpoint method (%s) matches current method (%s).", brk_info->functionname, tmp_name); - brk_info->resolved = XDEBUG_BRK_RESOLVED; - xdebug_dbgp_resolved_breakpoint_notification(ctxt->context, brk_info); - xdfree(tmp_name); - return; - } - - xdfree(tmp_name); - } else { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: We don't handle this function type (%02x) yet.", ctxt->fse->function.type); - return; - } -} -*/ - -static void line_breakpoint_resolve_helper(xdebug_con *context, xdebug_lines_list *lines_list, xdebug_brk_info *brk_info) -{ -// xdebug_func func; - int i; - xdebug_function_lines_map_item *found_item = NULL; - int found_item_span = XDEBUG_RESOLVED_SPAN_MAX; - - /* Loop over all definitions in lines_list for file */ - for (i = 0; i < lines_list->count; i++) { - xdebug_function_lines_map_item *item = lines_list->functionsi; - - /* Loop over all the file/line list entries to find the best fitting one for 'brk_info->original_lineno' */ - if (brk_info->original_lineno < item->line_start || brk_info->original_lineno > item->line_end) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: Line number (%d) out of range (%zd-%zd).", brk_info->original_lineno, item->line_start, item->line_end); - continue; - } - - if (item->line_span < found_item_span) { - found_item = item; - found_item_span = item->line_span; - } - } - - if (!found_item) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: Could not find any file/line entry in lines list."); - return; - } - - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: Line number (%d) in smallest range of range (%zd-%zd).", brk_info->original_lineno, found_item->line_start, found_item->line_end); - - /* If the breakpoint's line number is in the set, mark as resolved */ - if (xdebug_set_in(found_item->lines_breakable, brk_info->original_lineno)) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "F: Breakpoint line (%d) found in set of executable lines.", brk_info->original_lineno); - brk_info->resolved_lineno = brk_info->original_lineno; - brk_info->resolved = XDEBUG_BRK_RESOLVED; - xdebug_dbgp_resolved_breakpoint_notification(context, brk_info); - return; - } else { - int tmp_lineno; - - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Breakpoint line (%d) NOT found in set of executable lines.", brk_info->original_lineno); - - /* Check for a following line in the function */ - tmp_lineno = brk_info->original_lineno; - do { - tmp_lineno++; - - if (xdebug_set_in(found_item->lines_breakable, tmp_lineno)) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, " F: Line (%d) in set.", tmp_lineno); - - brk_info->resolved_lineno = tmp_lineno; - brk_info->resolved = XDEBUG_BRK_RESOLVED; - xdebug_dbgp_resolved_breakpoint_notification(context, brk_info); - return; - } else { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, " I: Line (%d) not in set.", tmp_lineno); - } - } while (tmp_lineno < found_item->line_end && (tmp_lineno < brk_info->original_lineno + XDEBUG_DBGP_SCAN_RANGE)); - - /* Check for a previous line in the function */ - tmp_lineno = brk_info->original_lineno; - do { - tmp_lineno--; - - if (xdebug_set_in(found_item->lines_breakable, tmp_lineno)) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, " F: Line (%d) in set.", tmp_lineno); - - brk_info->resolved_lineno = tmp_lineno; - brk_info->resolved = XDEBUG_BRK_RESOLVED; - xdebug_dbgp_resolved_breakpoint_notification(context, brk_info); - return; - } else { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, " I: Line (%d) not in set.", tmp_lineno); - } - } while (tmp_lineno > found_item->line_start && (tmp_lineno > brk_info->original_lineno - XDEBUG_DBGP_SCAN_RANGE)); - } -} - -static void breakpoint_resolve_helper(void *rctxt, xdebug_hash_element *he, void *dummy) -{ - xdebug_dbgp_resolve_context *ctxt = (xdebug_dbgp_resolve_context*) rctxt; - xdebug_brk_admin *admin = (xdebug_brk_admin*) he->ptr; - xdebug_brk_info *brk_info; - - brk_info = breakpoint_brk_info_fetch(admin->type, admin->key); - - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "Breakpoint %d (type: %s).", admin->id, XDEBUG_BREAKPOINT_TYPE_NAME(brk_info->brk_type)); - - /* Bail early if it's already resolved */ - if (brk_info->resolved == XDEBUG_BRK_RESOLVED) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "D: Breakpoint %d (type: %s) is already resolved.", admin->id, XDEBUG_BREAKPOINT_TYPE_NAME(brk_info->brk_type)); - return; - } - - switch (brk_info->brk_type) { - case XDEBUG_BREAKPOINT_TYPE_LINE: - case XDEBUG_BREAKPOINT_TYPE_CONDITIONAL: - if (!zend_string_equals(brk_info->filename, ctxt->filename)) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: File name (%s) does not match breakpoint to resolve (%s).", ZSTR_VAL(ctxt->filename), ZSTR_VAL(brk_info->filename)); - return; - } - - line_breakpoint_resolve_helper(ctxt->context, ctxt->lines_list, brk_info); - return; -/* - case XDEBUG_BREAKPOINT_TYPE_CALL: - case XDEBUG_BREAKPOINT_TYPE_RETURN: - function_breakpoint_resolve_helper(rctxt, brk_info, he); - return; -*/ - default: - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: The breakpoint type '%s' can not be resolved.", XDEBUG_BREAKPOINT_TYPE_NAME(brk_info->brk_type)); - return; - } -} - -/* Fetches the lines list for 'filename', and loops over all breakpoints to try - * to resolve them at run-time */ -int xdebug_dbgp_resolve_breakpoints(xdebug_con *context, zend_string *filename) -{ - xdebug_dbgp_resolve_context resolv_ctxt; - xdebug_lines_list *lines_list; - - /* Get the lines list for the current file */ - if (!XG_DBG(breakable_lines_map) || !xdebug_hash_find(XG_DBG(breakable_lines_map), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &lines_list)) { - xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "E: Lines list for '%s' does not exist.", ZSTR_VAL(filename)); - return 0; - } - - resolv_ctxt.context = context; - resolv_ctxt.filename = filename; - resolv_ctxt.lines_list = lines_list; - xdebug_hash_apply_with_argument(context->breakpoint_list, (void *) &resolv_ctxt, breakpoint_resolve_helper, NULL); - - return 1; -} - -int xdebug_dbgp_stream_output(const char *string, unsigned int length) -{ - if ((XG_DBG(stdout_mode) == 1 || XG_DBG(stdout_mode) == 2) && length) { - xdebug_send_stream("stdout", string, length); - } - - if (XG_DBG(stdout_mode) == 0 || XG_DBG(stdout_mode) == 1) { - return 0; - } - return -1; -} - -int xdebug_dbgp_notification(xdebug_con *context, zend_string *filename, long lineno, int type, char *type_string, char *message) -{ - xdebug_xml_node *response, *error_container; - - response = xdebug_xml_node_init("notify"); - xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); - xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); - xdebug_xml_add_attribute(response, "name", "error"); - - error_container = xdebug_xml_node_init("xdebug:message"); - if (filename) { - char *tmp_filename = NULL; - - if (check_evaled_code(filename, &tmp_filename)) { - xdebug_xml_add_attribute_ex(error_container, "filename", tmp_filename, 0, 0); - xdfree(tmp_filename); - } else { - xdebug_xml_add_attribute_ex(error_container, "filename", xdebug_path_to_url(filename), 0, 1); - } - } - if (lineno) { - xdebug_xml_add_attribute_ex(error_container, "lineno", xdebug_sprintf("%lu", lineno), 0, 1); - } - if (type_string) { - xdebug_xml_add_attribute_ex(error_container, "type", xdstrdup(type_string), 0, 1); - } - if (message) { - char *tmp_buf; - - if (type == E_ERROR && ((tmp_buf = xdebug_strip_php_stack_trace(message)) != NULL)) { - xdebug_xml_add_text(error_container, tmp_buf); - } else { - xdebug_xml_add_text(error_container, xdstrdup(message)); - } - } - xdebug_xml_add_child(response, error_container); - - send_message(context, response); - xdebug_xml_node_dtor(response); - - return 1; -} - -int xdebug_dbgp_user_notify(xdebug_con *context, zend_string *filename, long lineno, zval *data) -{ - xdebug_xml_node *response, *data_node, *location_node; - xdebug_var_export_options *options; - - if (!context->send_notifications) { - return 0; - } - - response = xdebug_xml_node_init("notify"); - xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); - xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); - xdebug_xml_add_attribute(response, "name", "user"); - - options = (xdebug_var_export_options*) context->options; - options->encode_as_extended_property = 0; - - location_node = xdebug_xml_node_init("xdebug:location"); - if (filename) { - char *tmp_filename = NULL; - - if (check_evaled_code(filename, &tmp_filename)) { - xdebug_xml_add_attribute_ex(location_node, "filename", tmp_filename, 0, 0); - xdfree(tmp_filename); - } else { - xdebug_xml_add_attribute_ex(location_node, "filename", xdebug_path_to_url(filename), 0, 1); - } - } - if (lineno) { - xdebug_xml_add_attribute_ex(location_node, "lineno", xdebug_sprintf("%lu", lineno), 0, 1); - } - xdebug_xml_add_child(response, location_node); - - data_node = xdebug_xml_node_init("property"); - xdebug_var_export_xml_node(&data, NULL, data_node, options, 0); - xdebug_xml_add_child(response, data_node); - - send_message(context, response); - xdebug_xml_node_dtor(response); - - return 1; -} - -static char *create_eval_key_file(zend_string *filename, int lineno) -{ - return xdebug_sprintf("%s(%d) : eval()'d code", ZSTR_VAL(filename), lineno); -} - -static char *create_eval_key_id(int id) -{ - return xdebug_sprintf("%04x", id); -} - -int xdebug_dbgp_register_eval_id(xdebug_con *context, function_stack_entry *fse) -{ - char *key; - xdebug_eval_info *ei; - - context->eval_id_sequence++; - - ei = xdcalloc(sizeof(xdebug_eval_info), 1); - ei->id = context->eval_id_sequence; - ei->contents = zend_string_copy(fse->include_filename); - ei->refcount = 2; - - key = create_eval_key_file(fse->filename, fse->lineno); - xdebug_hash_add(context->eval_id_lookup, key, strlen(key), (void*) ei); - xdfree(key); - - key = create_eval_key_id(ei->id); - xdebug_hash_add(context->eval_id_lookup, key, strlen(key), (void*) ei); - xdfree(key); - - return ei->id; -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/debugger/handler_dbgp.h
Deleted
@@ -1,112 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __HAVE_XDEBUG_HANDLER_DBGP_H__ -#define __HAVE_XDEBUG_HANDLER_DBGP_H__ - -#include <string.h> -#include "handlers.h" -#include "lib/xml.h" - -#define DBGP_VERSION "1.0" - -typedef struct xdebug_dbgp_result { - int status; - int reason; - int code; -} xdebug_dbgp_result; - -#define ADD_REASON_MESSAGE(c) { \ - xdebug_xml_node *message = xdebug_xml_node_init("message"); \ - xdebug_error_entry *error_entry = &xdebug_error_codes0; \ - \ - while (error_entry->message) { \ - if ((c) == error_entry->code) { \ - xdebug_xml_add_text(message, xdstrdup(error_entry->message)); \ - xdebug_xml_add_child(error, message); \ - } \ - error_entry++; \ - } \ -} - -#define RETURN_RESULT(s, r, c) { \ - xdebug_xml_node *error = xdebug_xml_node_init("error"); \ - xdebug_xml_node *message = xdebug_xml_node_init("message"); \ - xdebug_error_entry *error_entry = &xdebug_error_codes0; \ - \ - xdebug_xml_add_attribute(*retval, "status", xdebug_dbgp_status_strings(s)); \ - xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_strings(r)); \ - xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%u", (c)), 0, 1); \ - \ - while (error_entry->message) { \ - if ((c) == error_entry->code) { \ - xdebug_xml_add_text(message, xdstrdup(error_entry->message)); \ - xdebug_xml_add_child(error, message); \ - } \ - error_entry++; \ - } \ - xdebug_xml_add_child(*retval, error); \ - return; \ -} - -/* Argument structure */ -typedef struct xdebug_dbgp_arg { - xdebug_str *value27; /* one extra for - */ -} xdebug_dbgp_arg; - -#define DBGP_FUNC_PARAMETERS xdebug_xml_node **retval, xdebug_con *context, xdebug_dbgp_arg *args -#define DBGP_FUNC_PASS_PARAMETERS retval, context, args -#define DBGP_FUNC(name) static void xdebug_dbgp_handle_##name(DBGP_FUNC_PARAMETERS) -#define DBGP_FUNC_ENTRY(name,flags) { #name, xdebug_dbgp_handle_##name, 0, flags }, -#define DBGP_CONT_FUNC_ENTRY(name,flags) { #name, xdebug_dbgp_handle_##name, 1, flags }, -#define DBGP_STOP_FUNC_ENTRY(name,flags) { #name, xdebug_dbgp_handle_##name, 2, flags }, - -#define XDEBUG_DBGP_NONE 1 << 0 -#define XDEBUG_DBGP_POST_MORTEM 1 << 1 /* command is valid in 'stopping' (post mortem) state */ - -typedef struct xdebug_dbgp_cmd { - const char *name; - void (*handler)(DBGP_FUNC_PARAMETERS); - int cont; - int flags; -} xdebug_dbgp_cmd; - -typedef struct xdebug_dbgp_resolve_context { - xdebug_con *context; - zend_string *filename; - xdebug_lines_list *lines_list; -} xdebug_dbgp_resolve_context; - -#define CMD_OPTION_SET(opt) (!!(opt == '-' ? args->value26 : args->value(opt) - 'a')) -#define CMD_OPTION_CHAR(opt) (opt == '-' ? args->value26->d : args->value(opt) - 'a'->d) -#define CMD_OPTION_LEN(opt) (opt == '-' ? args->value26->l : args->value(opt) - 'a'->l) -#define CMD_OPTION_XDEBUG_STR(opt) (opt == '-' ? args->value26 : args->value(opt) - 'a') - -int xdebug_dbgp_init(xdebug_con *context, int mode); -int xdebug_dbgp_deinit(xdebug_con *context); -int xdebug_dbgp_error(xdebug_con *context, int type, char *exception_type, char *message, const char *location, const unsigned int line, xdebug_vector *stack); -int xdebug_dbgp_break_on_line(xdebug_con *context, xdebug_brk_info *brk, zend_string *filename, int lineno); -int xdebug_dbgp_breakpoint(xdebug_con *context, xdebug_vector *stack, zend_string *filename, long lineno, int type, char *exception, char *code, const char *message, xdebug_brk_info *brk_info); -int xdebug_dbgp_resolve_breakpoints(xdebug_con *context, zend_string *filename); -int xdebug_dbgp_stream_output(const char *string, unsigned int length); -int xdebug_dbgp_notification(xdebug_con *context, zend_string *filename, long lineno, int type, char *type_string, char *message); -int xdebug_dbgp_user_notify(xdebug_con *context, zend_string *filename, long lineno, zval *data); -void XDEBUG_ATTRIBUTE_FORMAT(printf, 2, 3) xdebug_dbgp_log(int log_level, const char *fmt, ...); -int xdebug_dbgp_register_eval_id(xdebug_con *context, function_stack_entry *fse); - -extern xdebug_remote_handler xdebug_handler_dbgp; - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/debugger/handlers.h
Deleted
@@ -1,164 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __HAVE_XDEBUG_HANDLERS_H__ -#define __HAVE_XDEBUG_HANDLERS_H__ - -#include "php_xdebug.h" -#include "lib/compat.h" -#include "lib/llist.h" -#include "lib/hash.h" -#include "lib/lib.h" -#include "lib/usefulstuff.h" -#include "lib/vector.h" -#include "debugger_private.h" - -typedef struct _xdebug_brk_admin xdebug_brk_admin; -typedef struct _xdebug_brk_info xdebug_brk_info; -typedef struct _xdebug_brk_span xdebug_brk_span; -typedef struct _xdebug_eval_info xdebug_eval_info; -typedef struct _xdebug_con xdebug_con; -typedef struct _xdebug_debug_list xdebug_debug_list; -typedef struct _xdebug_remote_handler xdebug_remote_handler; -typedef struct _xdebug_remote_handler_info xdebug_remote_handler_info; - -struct _xdebug_debug_list { - zend_string *last_filename; - int last_line; -}; - -#define XDEBUG_BREAKPOINT_TYPE_LINE 0x01 -#define XDEBUG_BREAKPOINT_TYPE_CONDITIONAL 0x02 -#define XDEBUG_BREAKPOINT_TYPE_CALL 0x04 -#define XDEBUG_BREAKPOINT_TYPE_RETURN 0x08 -#define XDEBUG_BREAKPOINT_TYPE_EXCEPTION 0x10 -#define XDEBUG_BREAKPOINT_TYPE_WATCH 0x20 - -#define XDEBUG_BREAKPOINT_TYPE_NAME(v) (xdebug_breakpoint_types(int)(log2(v))).name - -struct _xdebug_brk_admin { - int id; - int type; - char *key; -}; - -#define XDEBUG_NORMAL 0x01 -#define XDEBUG_CLOUD 0x02 -#define XDEBUG_CLOUD_FROM_TRIGGER_VALUE 0x03 - -struct _xdebug_con { - int socket; - int host_type; /* XDEBUG_NORMAL, XDEBUG_CLOUD, XDEBUG_CLOUD_FROM_TRIGGER_VALUE */ - void *options; - xdebug_remote_handler *handler; - fd_buf *buffer; - zend_string *program_name; - xdebug_hash *breakpoint_list; - xdebug_hash *function_breakpoints; - xdebug_hash *eval_id_lookup; - int eval_id_sequence; - xdebug_llist *line_breakpoints; - xdebug_hash *exception_breakpoints; - xdebug_debug_list list; - int do_break; - xdebug_brk_info *pending_breakpoint; - - int do_step; - int do_next; - int next_level; - int do_finish; - int do_connect_to_client; - int finish_level; - int finish_func_nr; - - int send_notifications; - int inhibit_notifications; - - int resolved_breakpoints; - int breakpoint_details; - - /* Statistics and diagnostics */ - char *connected_hostname; - int connected_port; - char *detached_message; -}; - -#define XDEBUG_BRK_UNRESOLVED 0 -#define XDEBUG_BRK_RESOLVED 1 - -#define XDEBUG_HIT_DISABLED 0 -#define XDEBUG_HIT_GREATER_EQUAL 1 -#define XDEBUG_HIT_EQUAL 2 -#define XDEBUG_HIT_MOD 3 - -#define XDEBUG_RESOLVED_SPAN_MAX 2147483647 - -struct _xdebug_brk_info { - int id; - int brk_type; - int resolved; - char *classname; - char *functionname; - char *exceptionname; - int function_break_type; /* XDEBUG_BRK_FUNC_* */ - zend_string *filename; - int original_lineno; /* line number that was set through breakpoint_set */ - int resolved_lineno; /* line number after resolving, initialised with 'original_lineno' */ - char *condition; - int disabled; - int temporary; - int hit_count; - int hit_value; - int hit_condition; -}; - -struct _xdebug_eval_info { - int id; - int refcount; - zend_string *contents; -}; - -struct _xdebug_remote_handler { - /* Init / deinit */ - int (*remote_init)(xdebug_con *h, int mode); - int (*remote_deinit)(xdebug_con *h); - - /* Stack messages */ - int (*remote_error)(xdebug_con *h, int type, char *exception_type, char *message, const char *location, const unsigned int line, xdebug_vector *stack); - - /* Breakpoints */ - int (*break_on_line)(xdebug_con *h, xdebug_brk_info *brk, zend_string *filename, int lineno); - int (*remote_breakpoint)(xdebug_con *h, xdebug_vector *stack, zend_string *filename, long lineno, int type, char *exception, char *code, const char *message, xdebug_brk_info *brk_info); - int (*resolve_breakpoints)(xdebug_con *h, zend_string *opa); - - /* Output redirection */ - int (*remote_stream_output)(const char *string, unsigned int length); - - /* Notifications & Logging */ - int (*remote_notification)(xdebug_con *h, zend_string *file, long lineno, int type, char *type_string, char *message); - int (*user_notification)(xdebug_con *h, zend_string *filename, long lineno, zval *data); - - /* Eval ID registration and removal */ - int (*register_eval_id)(xdebug_con *h, function_stack_entry *fse); -}; - -xdebug_brk_info *xdebug_brk_info_ctor(void); -void xdebug_brk_info_dtor(xdebug_brk_info *brk); -void xdebug_llist_brk_dtor(void *dummy, xdebug_brk_info *brk); -void xdebug_hash_brk_dtor(xdebug_brk_info *brk); -void xdebug_hash_eval_info_dtor(xdebug_eval_info *ei); - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/develop/develop.c
Deleted
@@ -1,137 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ -#include "php.h" -#include "zend_exceptions.h" - -#include "php_xdebug.h" -#include "monitor.h" -#include "stack.h" -#include "superglobals.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -static int xdebug_silence_handler(XDEBUG_OPCODE_HANDLER_ARGS); - -static void xdebug_develop_overloaded_functions_setup(void) -{ - zend_function *orig; - - /* Override var_dump with our own function */ - orig = zend_hash_str_find_ptr(EG(function_table), "var_dump", sizeof("var_dump") - 1); - XG_DEV(orig_var_dump_func) = orig->internal_function.handler; - orig->internal_function.handler = zif_xdebug_var_dump; -} - -static void xdebug_develop_overloaded_functions_restore(void) -{ - zend_function *orig; - - orig = zend_hash_str_find_ptr(EG(function_table), "var_dump", sizeof("var_dump") - 1); - orig->internal_function.handler = XG_DEV(orig_var_dump_func); -} - - -void xdebug_init_develop_globals(xdebug_develop_globals_t *xg) -{ - xg->do_monitor_functions = 0; - - xg->in_at = 0; /* scream */ - - xdebug_llist_init(&xg->server, xdebug_superglobals_dump_dtor); - xdebug_llist_init(&xg->get, xdebug_superglobals_dump_dtor); - xdebug_llist_init(&xg->post, xdebug_superglobals_dump_dtor); - xdebug_llist_init(&xg->cookie, xdebug_superglobals_dump_dtor); - xdebug_llist_init(&xg->files, xdebug_superglobals_dump_dtor); - xdebug_llist_init(&xg->env, xdebug_superglobals_dump_dtor); - xdebug_llist_init(&xg->request, xdebug_superglobals_dump_dtor); - xdebug_llist_init(&xg->session, xdebug_superglobals_dump_dtor); -} - -void xdebug_deinit_develop_globals(xdebug_develop_globals_t *xg) -{ - xdebug_llist_empty(&xg->server, NULL); - xdebug_llist_empty(&xg->get, NULL); - xdebug_llist_empty(&xg->post, NULL); - xdebug_llist_empty(&xg->cookie, NULL); - xdebug_llist_empty(&xg->files, NULL); - xdebug_llist_empty(&xg->env, NULL); - xdebug_llist_empty(&xg->request, NULL); - xdebug_llist_empty(&xg->session, NULL); -} - -void xdebug_develop_minit(INIT_FUNC_ARGS) -{ - /* Overload opcodes for 'scream' */ - xdebug_set_opcode_handler(ZEND_BEGIN_SILENCE, xdebug_silence_handler); - xdebug_set_opcode_handler(ZEND_END_SILENCE, xdebug_silence_handler); - - REGISTER_LONG_CONSTANT("XDEBUG_STACK_NO_DESC", XDEBUG_STACK_NO_DESC, CONST_CS | CONST_PERSISTENT); -} - -void xdebug_develop_mshutdown() -{ -} - -void xdebug_develop_rinit() -{ - XG_DEV(collected_errors) = xdebug_llist_alloc(xdebug_llist_string_dtor); - - /* Function monitoring */ - XG_DEV(do_monitor_functions) = 0; - XG_DEV(functions_to_monitor) = NULL; - XG_DEV(monitored_functions_found) = xdebug_llist_alloc(xdebug_monitored_function_dtor); - - xdebug_develop_overloaded_functions_setup(); -} - -void xdebug_develop_post_deactivate() -{ - xdebug_llist_destroy(XG_DEV(collected_errors), NULL); - XG_DEV(collected_errors) = NULL; - - xdebug_llist_destroy(XG_DEV(monitored_functions_found), NULL); - XG_DEV(monitored_functions_found) = NULL; - - if (XG_DEV(functions_to_monitor)) { - xdebug_hash_destroy(XG_DEV(functions_to_monitor)); - XG_DEV(functions_to_monitor) = NULL; - } - - xdebug_develop_overloaded_functions_restore(); -} - - -static int xdebug_silence_handler(XDEBUG_OPCODE_HANDLER_ARGS) -{ - zend_op_array *op_array = &execute_data->func->op_array; - const zend_op *cur_opcode = execute_data->opline; - - if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { - xdebug_coverage_record_if_active(execute_data, op_array); - } - - if (XINI_DEV(do_scream)) { - execute_data->opline++; - if (cur_opcode->opcode == ZEND_BEGIN_SILENCE) { - XG_DEV(in_at) = 1; - } else { - XG_DEV(in_at) = 0; - } - return ZEND_USER_OPCODE_CONTINUE; - } - - return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/develop/develop.h
Deleted
@@ -1,82 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __XDEBUG_DEVELOP_H__ -#define __XDEBUG_DEVELOP_H__ - -typedef struct _xdebug_develop_globals_t { - /* used for function monitoring */ - zend_bool do_monitor_functions; - xdebug_hash *functions_to_monitor; - xdebug_llist *monitored_functions_found; /* List of functions found */ - - /* superglobals */ - xdebug_llist server; - xdebug_llist get; - xdebug_llist post; - xdebug_llist cookie; - xdebug_llist files; - xdebug_llist env; - xdebug_llist request; - xdebug_llist session; - - /* used for collection errors */ - xdebug_llist *collected_errors; - - /* scream */ - zend_bool in_at; - - /* overloaded var_dump */ - zif_handler orig_var_dump_func; -} xdebug_develop_globals_t; - -typedef struct _xdebug_develop_settings_t { - - zend_long max_stack_frames; - zend_bool show_ex_trace; - zend_bool show_error_trace; - zend_bool show_local_vars; - zend_bool force_display_errors; - zend_long force_error_reporting; - zend_long halt_level; - - zend_long cli_color; - - /* superglobals */ - zend_bool dump_globals; - zend_bool dump_once; - zend_bool dump_undefined; - - /* scream */ - zend_bool do_scream; -} xdebug_develop_settings_t; - -void xdebug_init_develop_globals(xdebug_develop_globals_t *xg); -void xdebug_deinit_develop_globals(xdebug_develop_globals_t *xg); - -void xdebug_develop_minit(); -void xdebug_develop_mshutdown(); -void xdebug_develop_rinit(); -void xdebug_develop_post_deactivate(); - -#if PHP_VERSION_ID >= 80000 -void xdebug_develop_throw_exception_hook(zend_object *exception, zval *file, zval *line, zval *code, char *code_str, zval *message); -#else -void xdebug_develop_throw_exception_hook(zval *exception, zval *file, zval *line, zval *code, char *code_str, zval *message); -#endif -void xdebug_monitor_handler(function_stack_entry *fse); - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/develop/monitor.c
Deleted
@@ -1,173 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "php_xdebug.h" - -#include "develop_private.h" -#include "monitor.h" - -#include "lib/compat.h" -#include "lib/hash.h" -#include "lib/var.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -static void init_function_monitor_hash(xdebug_hash *internal, HashTable *functions_to_monitor) -{ - zval *val; - - ZEND_HASH_FOREACH_VAL(functions_to_monitor, val) { - if (Z_TYPE_P(val) == IS_STRING) { - xdebug_hash_add(internal, Z_STRVAL_P(val), Z_STRLEN_P(val), xdstrdup(Z_STRVAL_P(val))); - } - } ZEND_HASH_FOREACH_END(); -} - -static void xdebug_hash_function_monitor_dtor(char *function) -{ - xdfree(function); -} - -static xdebug_monitored_function_entry *xdebug_monitored_function_init(char *func_name, zend_string *filename, int lineno) -{ - xdebug_monitored_function_entry *tmp = xdmalloc(sizeof(xdebug_monitored_function_entry)); - - tmp->func_name = xdstrdup(func_name); - tmp->filename = zend_string_copy(filename); - tmp->lineno = lineno; - - return tmp; -} - -void xdebug_monitored_function_dtor(void *dummy, void *elem) -{ - xdebug_monitored_function_entry *mfe = (xdebug_monitored_function_entry*) elem; - - xdfree(mfe->func_name); - zend_string_release(mfe->filename); - xdfree(mfe); -} - -void xdebug_function_monitor_record(char *func_name, zend_string *filename, int lineno) -{ - xdebug_monitored_function_entry *record; - - record = xdebug_monitored_function_init(func_name, filename, lineno); - xdebug_llist_insert_next(XG_DEV(monitored_functions_found), XDEBUG_LLIST_TAIL(XG_DEV(monitored_functions_found)), record); -} - -void xdebug_monitor_handler(function_stack_entry *fse) -{ - char *func_name = NULL; - int func_name_len = 0; - void *dummy = NULL; - - if (!XG_DEV(do_monitor_functions)) { - return; - } - - func_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); - func_name_len = strlen(func_name); - - if (xdebug_hash_find(XG_DEV(functions_to_monitor), func_name, func_name_len, (void *) &dummy)) { - xdebug_function_monitor_record(func_name, fse->filename, fse->lineno); - } - - xdfree(func_name); -} - -PHP_FUNCTION(xdebug_start_function_monitor) -{ - HashTable *functions_to_monitor; - - if (!XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - php_error(E_WARNING, "Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop'"); - return; - } - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "H", &functions_to_monitor) == FAILURE) { - return; - } - - if (XG_DEV(do_monitor_functions) == 1) { - php_error(E_NOTICE, "Function monitoring was already started"); - } - - /* Clean and store list of functions to monitor */ - if (XG_DEV(functions_to_monitor)) { - xdebug_hash_destroy(XG_DEV(functions_to_monitor)); - } - - /* We add "1" here so that we don't alloc a 0-slot hash table */ - XG_DEV(functions_to_monitor) = xdebug_hash_alloc(zend_hash_num_elements(functions_to_monitor) + 1, (xdebug_hash_dtor_t) xdebug_hash_function_monitor_dtor); - init_function_monitor_hash(XG_DEV(functions_to_monitor), functions_to_monitor); - - XG_DEV(do_monitor_functions) = 1; -} - -PHP_FUNCTION(xdebug_stop_function_monitor) -{ - if (!XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - php_error(E_WARNING, "Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop'"); - return; - } - - if (XG_DEV(do_monitor_functions) == 0) { - php_error(E_NOTICE, "Function monitoring was not started"); - } - XG_DEV(do_monitor_functions) = 0; -} - -PHP_FUNCTION(xdebug_get_monitored_functions) -{ - xdebug_llist_element *le; - zend_bool clear = 0; - xdebug_monitored_function_entry *mfe; - - if (!XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - php_error(E_WARNING, "Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop'"); - array_init(return_value); - return; - } - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &clear) == FAILURE) { - return; - } - - array_init(return_value); - for (le = XDEBUG_LLIST_HEAD(XG_DEV(monitored_functions_found)); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { - zval *entry; - - mfe = XDEBUG_LLIST_VALP(le); - - XDEBUG_MAKE_STD_ZVAL(entry); - array_init(entry); - - add_assoc_string_ex(entry, "function", HASH_KEY_SIZEOF("function"), mfe->func_name); - add_assoc_string_ex(entry, "filename", HASH_KEY_SIZEOF("filename"), ZSTR_VAL(mfe->filename)); - add_assoc_long(entry, "lineno", mfe->lineno); - - add_next_index_zval(return_value, entry); - efree(entry); - } - - if (clear) { - xdebug_llist_destroy(XG_DEV(monitored_functions_found), NULL); - XG_DEV(monitored_functions_found) = xdebug_llist_alloc(xdebug_monitored_function_dtor); - } -} -/* }}} */
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/develop/php_functions.c
Deleted
@@ -1,383 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "php_xdebug.h" - -#include "develop_private.h" -#include "stack.h" - -#include "lib/lib_private.h" -#include "lib/var_export_html.h" -#include "lib/var_export_line.h" -#include "lib/var_export_text.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -#define MODE_MUST_BE(m,n) \ - if (!XDEBUG_MODE_IS((m))) { \ - php_error(E_WARNING, "Function must be enabled in php.ini by setting 'xdebug.mode' to '%s'", (n)); \ - return; \ - } - -/* {{{ proto void xdebug_var_dump(mixed var , ... ) - Outputs a fancy string representation of a variable */ -PHP_FUNCTION(xdebug_var_dump) -{ - zval *args; - int argc; - int i; - xdebug_str *val; - - argc = ZEND_NUM_ARGS(); - - args = safe_emalloc(argc, sizeof(zval), 0); - if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - for (i = 0; i < argc; i++) { - if (PG(html_errors)) { - val = xdebug_get_zval_value_html(NULL, (zval*) &argsi, 0, NULL); - PHPWRITE(val->d, val->l); - xdebug_str_free(val); - } - else if ((XINI_DEV(cli_color) == 1 && xdebug_is_output_tty()) || (XINI_DEV(cli_color) == 2)) { - val = xdebug_get_zval_value_ansi((zval*) &argsi, 0, NULL); - PHPWRITE(val->d, val->l); - xdebug_str_free(val); - } - else { - val = xdebug_get_zval_value_text((zval*) &argsi, 0, NULL); - PHPWRITE(val->d, val->l); - xdebug_str_free(val); - } - } - - efree(args); -} -/* }}} */ - -/* {{{ proto void xdebug_debug_zval(mixed var , ... ) - Outputs a fancy string representation of a variable */ -PHP_FUNCTION(xdebug_debug_zval) -{ - zval *args; - int argc; - int i; - xdebug_str *val; - - argc = ZEND_NUM_ARGS(); - - args = safe_emalloc(argc, sizeof(zval), 0); - if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - if (!(ZEND_CALL_INFO(EG(current_execute_data)->prev_execute_data) & ZEND_CALL_HAS_SYMBOL_TABLE)) { - zend_rebuild_symbol_table(); - } - - for (i = 0; i < argc; i++) { - if (Z_TYPE(argsi) == IS_STRING) { - zval debugzval; - xdebug_str *tmp_name; - - xdebug_lib_set_active_symbol_table(EG(current_execute_data)->prev_execute_data->symbol_table); - xdebug_lib_set_active_data(EG(current_execute_data)->prev_execute_data); - - tmp_name = xdebug_str_create(Z_STRVAL(argsi), Z_STRLEN(argsi)); - xdebug_get_php_symbol(&debugzval, tmp_name); - xdebug_str_free(tmp_name); - - /* Reduce refcount for dumping */ - Z_TRY_DELREF(debugzval); - - php_printf("%s: ", Z_STRVAL(argsi)); - if (Z_TYPE(debugzval) != IS_UNDEF) { - if (PG(html_errors)) { - val = xdebug_get_zval_value_html(NULL, &debugzval, 1, NULL); - PHPWRITE(val->d, val->l); - } - else if ((XINI_DEV(cli_color) == 1 && xdebug_is_output_tty()) || (XINI_DEV(cli_color) == 2)) { - val = xdebug_get_zval_value_ansi(&debugzval, 1, NULL); - PHPWRITE(val->d, val->l); - } - else { - val = xdebug_get_zval_value_line(&debugzval, 1, NULL); - PHPWRITE(val->d, val->l); - } - xdebug_str_free(val); - PHPWRITE("\n", 1); - } else { - PHPWRITE("no such symbol\n", 15); - } - - /* Restore original refcount */ - Z_TRY_ADDREF(debugzval); - zval_ptr_dtor_nogc(&debugzval); - } - } - - efree(args); -} -/* }}} */ - -/* {{{ proto void xdebug_debug_zval_stdout(mixed var , ... ) - Outputs a fancy string representation of a variable */ -PHP_FUNCTION(xdebug_debug_zval_stdout) -{ - zval *args; - int argc; - int i; - - argc = ZEND_NUM_ARGS(); - - args = safe_emalloc(argc, sizeof(zval), 0); - if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) { - efree(args); - WRONG_PARAM_COUNT; - } - - if (!(ZEND_CALL_INFO(EG(current_execute_data)->prev_execute_data) & ZEND_CALL_HAS_SYMBOL_TABLE)) { - zend_rebuild_symbol_table(); - } - - for (i = 0; i < argc; i++) { - if (Z_TYPE(argsi) == IS_STRING) { - zval debugzval; - xdebug_str *tmp_name; - xdebug_str *val; - - xdebug_lib_set_active_symbol_table(EG(current_execute_data)->prev_execute_data->symbol_table); - xdebug_lib_set_active_data(EG(current_execute_data)->prev_execute_data); - - tmp_name = xdebug_str_create(Z_STRVAL(argsi), Z_STRLEN(argsi)); - xdebug_get_php_symbol(&debugzval, tmp_name); - xdebug_str_free(tmp_name); - - /* Reduce refcount for dumping */ - Z_TRY_DELREF(debugzval); - - printf("%s: ", Z_STRVAL(argsi)); - if (Z_TYPE(debugzval) != IS_UNDEF) { - val = xdebug_get_zval_value_line(&debugzval, 1, NULL); - printf("%s(%zd)", val->d, val->l); - xdebug_str_free(val); - printf("\n"); - } else { - printf("no such symbol\n\n"); - } - - /* Restore original refcount */ - Z_TRY_ADDREF(debugzval); - zval_ptr_dtor_nogc(&debugzval); - } - } - - efree(args); -} -/* }}} */ - -PHP_FUNCTION(xdebug_start_error_collection) -{ - MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); - - if (XG_LIB(do_collect_errors) == 1) { - php_error(E_NOTICE, "Error collection was already started"); - } - - XG_LIB(do_collect_errors) = 1; -} - -PHP_FUNCTION(xdebug_stop_error_collection) -{ - MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); - - if (XG_LIB(do_collect_errors) == 0) { - php_error(E_NOTICE, "Error collection was not started"); - } - - XG_LIB(do_collect_errors) = 0; -} - -PHP_FUNCTION(xdebug_memory_usage) -{ - RETURN_LONG(zend_memory_usage(0)); -} - -PHP_FUNCTION(xdebug_peak_memory_usage) -{ - RETURN_LONG(zend_memory_peak_usage(0)); -} - -PHP_FUNCTION(xdebug_time_index) -{ - MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); - - RETURN_DOUBLE(XDEBUG_SECONDS_SINCE_START(xdebug_get_nanotime())); -} - -/* {{{ proto void xdebug_print_function_stack(string message , int options) - Displays a stack trace */ -PHP_FUNCTION(xdebug_print_function_stack) -{ - char *message = NULL; - size_t message_len; - function_stack_entry *fse; - char *tmp; - zend_long options = 0; - - MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sl", &message, &message_len, &options) == FAILURE) { - return; - } - - fse = xdebug_get_stack_frame(0); - if (message) { - tmp = xdebug_get_printable_stack(PG(html_errors), 0, message, ZSTR_VAL(fse->filename), fse->lineno, !(options & XDEBUG_STACK_NO_DESC)); - } else { - tmp = xdebug_get_printable_stack(PG(html_errors), 0, "user triggered", ZSTR_VAL(fse->filename), fse->lineno, !(options & XDEBUG_STACK_NO_DESC)); - } - php_printf("%s", tmp); - xdfree(tmp); -} -/* }}} */ - -/* {{{ proto string xdebug_call_class() - Returns the name of the calling class */ -PHP_FUNCTION(xdebug_call_class) -{ - function_stack_entry *fse; - zend_long depth = 2; - - MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &depth) == FAILURE) { - return; - } - - fse = xdebug_get_stack_frame(depth); - if (!fse) { - return; - } - - if (!fse->function.object_class) { - RETURN_FALSE; - } - - RETURN_STR_COPY(fse->function.object_class); -} -/* }}} */ - -/* {{{ proto string xdebug_call_function() - Returns the function name from which the current function was called from. */ -PHP_FUNCTION(xdebug_call_function) -{ - function_stack_entry *fse; - zend_long depth = 2; - - MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &depth) == FAILURE) { - return; - } - - fse = xdebug_get_stack_frame(depth); - if (!fse) { - return; - } - - if (!fse->function.function) { - RETURN_FALSE; - } - - RETURN_STRING(fse->function.function); -} -/* }}} */ - -/* {{{ proto int xdebug_call_line() - Returns the line number where the current function was called from. */ -PHP_FUNCTION(xdebug_call_line) -{ - function_stack_entry *fse; - zend_long depth = 2; - - MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &depth) == FAILURE) { - return; - } - - fse = xdebug_get_stack_frame(depth); - if (!fse) { - return; - } - - RETURN_LONG(fse->lineno); -} -/* }}} */ - -/* {{{ proto string xdebug_call_file() - Returns the filename where the current function was called from. */ -PHP_FUNCTION(xdebug_call_file) -{ - function_stack_entry *fse; - zend_long depth = 2; - - MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &depth) == FAILURE) { - return; - } - - fse = xdebug_get_stack_frame(depth); - if (!fse) { - return; - } - - RETURN_STR_COPY(fse->filename); -} -/* }}} */ - -PHP_FUNCTION(xdebug_get_collected_errors) -{ - xdebug_llist_element *le; - char *string; - zend_bool clear = 0; - - MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &clear) == FAILURE) { - return; - } - - array_init(return_value); - for (le = XDEBUG_LLIST_HEAD(XG_DEV(collected_errors)); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { - string = XDEBUG_LLIST_VALP(le); - add_next_index_string(return_value, string); - } - - if (!clear) { - return; - } - - xdebug_llist_destroy(XG_DEV(collected_errors), NULL); - XG_DEV(collected_errors) = xdebug_llist_alloc(xdebug_llist_string_dtor); -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/develop/stack.c
Deleted
@@ -1,1121 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ -#include "php_xdebug.h" - -#include "main/php_ini.h" - -#include "ext/standard/html.h" -#include "ext/standard/php_smart_string.h" -#include "zend_exceptions.h" -#include "zend_generators.h" - -#include "monitor.h" -#include "stack.h" -#include "superglobals.h" - -#include "base/filter.h" -#include "coverage/code_coverage.h" -#include "lib/compat.h" -#include "lib/lib_private.h" -#include "lib/str.h" -#include "lib/var_export_html.h" -#include "lib/var_export_line.h" -#include "profiler/profiler.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -static const char* text_formats11 = { - "\n", - "%s: %s in %s on line %d\n", - "\nCall Stack:\n", - "%10.4F %10ld %3d. %s(", - "'%s'", - ") %s:%d\n", - "\n\nVariables in local scope (#%d):\n", - "\n", - " $%s = %s\n", - " $%s = *uninitialized*\n", - "SCREAM: Error suppression ignored for\n" -}; - -static const char* ansi_formats11 = { - "\n", - "1m31m%s0m: %s22m in 31m%s0m on line 32m%d0m22m\n", - "\n1mCall Stack:22m\n", - "%10.4F %10ld %3d. %s(", - "'%s'", - ") %s:%d\n", - "\n\nVariables in local scope (#%d):\n", - "\n", - " $%s = %s\n", - " $%s = *uninitialized*\n", - "1m31mSCREAM0m: Error suppression ignored for\n" -}; - -static const char* html_formats13 = { - "<br />\n<font size='1'><table class='xdebug-error xe-%s%s' dir='ltr' border='1' cellspacing='0' cellpadding='1'>\n", - "<tr><th align='left' bgcolor='#f57900' colspan=\"5\"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> %s: %s in %s on line <i>%d</i></th></tr>\n", - "<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>\n<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>\n", - "<tr><td bgcolor='#eeeeec' align='center'>%d</td><td bgcolor='#eeeeec' align='center'>%.4F</td><td bgcolor='#eeeeec' align='right'>%ld</td><td bgcolor='#eeeeec'>%s( ", - "<font color='#00bb00'>'%s'</font>", - " )</td><td title='%s' bgcolor='#eeeeec'>%s<b>:</b>%d</td></tr>\n", - "<tr><th align='left' colspan='5' bgcolor='#e9b96e'>Variables in local scope (#%d)</th></tr>\n", - "</table></font>\n", - "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s =</pre></td><td colspan='3' bgcolor='#eeeeec'>%s</td></tr>\n", - "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s =</pre></td><td colspan='3' bgcolor='#eeeeec' valign='top'><i>Undefined</i></td></tr>\n", - " )</td><td title='%s' bgcolor='#eeeeec'><a style='color: black' href='%s'>%s<b>:</b>%d</a></td></tr>\n", - "<tr><th align='left' bgcolor='#f57900' colspan=\"5\"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> %s: %s in <a style='color: black' href='%s'>%s</a> on line <i>%d</i></th></tr>\n", - "<tr><th align='left' bgcolor='#f57900' colspan=\"5\"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> SCREAM: Error suppression ignored for</th></tr>\n" -}; - -static const char** select_formats(int html) -{ - if (html) { - return html_formats; - } else if ((XINI_DEV(cli_color) == 1 && xdebug_is_output_tty()) || (XINI_DEV(cli_color) == 2)) { - return ansi_formats; - } else { - return text_formats; - } -} - -void xdebug_log_stack(const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno) -{ - char *tmp_log_message; - int i; - function_stack_entry *fse; - - tmp_log_message = xdebug_sprintf( "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); - php_log_err(tmp_log_message); - xdfree(tmp_log_message); - - if (!XG_BASE(stack) || XDEBUG_VECTOR_COUNT(XG_BASE(stack)) < 1) { - return; - } - - fse = XDEBUG_VECTOR_HEAD(XG_BASE(stack)); - - php_log_err((char*) "PHP Stack trace:"); - - for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, fse++) - { - int c = 0; /* Comma flag */ - unsigned int j = 0; /* Counter */ - char *tmp_name; - xdebug_str log_buffer = XDEBUG_STR_INITIALIZER; - int variadic_opened = 0; - int sent_variables = fse->varc; - - if (sent_variables > 0 && fse->varsent_variables-1.is_variadic && Z_ISUNDEF(fse->varsent_variables-1.data)) { - sent_variables--; - } - - tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); - xdebug_str_add_fmt(&log_buffer, "PHP %3d. %s(", fse->level, tmp_name); - xdfree(tmp_name); - - /* Printing vars */ - for (j = 0; j < sent_variables; j++) { - xdebug_str *tmp_value; - - if (c) { - xdebug_str_add_literal(&log_buffer, ", "); - } else { - c = 1; - } - - if (fse->varj.is_variadic) { - xdebug_str_add_literal(&log_buffer, "..."); - variadic_opened = 1; - } - - if (fse->varj.name) { - xdebug_str_add_fmt(&log_buffer, "$%s = ", ZSTR_VAL(fse->varj.name)); - } - - if (fse->varj.is_variadic) { - xdebug_str_add_literal(&log_buffer, "variadic("); - c = 0; - continue; - } - - if (!Z_ISUNDEF(fse->varj.data)) { - tmp_value = xdebug_get_zval_value_line(&fse->varj.data, 0, NULL); - xdebug_str_add_str(&log_buffer, tmp_value); - xdebug_str_free(tmp_value); - } else { - xdebug_str_add_literal(&log_buffer, "*uninitialized*"); - } - } - - if (variadic_opened) { - xdebug_str_add_literal(&log_buffer, ")"); - } - - xdebug_str_add_fmt(&log_buffer, ") %s:%d", ZSTR_VAL(fse->filename), fse->lineno); - php_log_err(log_buffer.d); - xdebug_str_destroy(&log_buffer); - } -} - -void xdebug_append_error_head(xdebug_str *str, int html, const char *error_type_str) -{ - const char **formats = select_formats(html); - - if (html) { - xdebug_str_add_fmt(str, formats0, error_type_str, XG_DEV(in_at) ? " xe-scream" : ""); - if (XG_DEV(in_at)) { - xdebug_str_add_const(str, formats12); - } - } else { - xdebug_str_add_const(str, formats0); - if (XG_DEV(in_at)) { - xdebug_str_add_const(str, formats10); - } - } -} - -void xdebug_append_error_description(xdebug_str *str, int html, const char *error_type_str, const char *buffer, const char *error_filename, const int error_lineno) -{ - const char **formats = select_formats(html); - char *escaped; - - if (!html) { - escaped = estrdup(buffer); - } else { - zend_string *tmp; - char *first_closing = strchr(buffer, ''); - - /* We do need to escape HTML entities here, as HTML chars could be in - * the error message. However, PHP in some circumstances also adds an - * HTML link to a manual page. That bit, we don't need to escape. So - * this bit of code finds the portion that doesn't need escaping, adds - * it to a tmp string, and then adds an HTML escaped string for the - * rest of the original buffer. */ - if (first_closing && strstr(buffer, "() <a href=") != NULL) { - smart_string special_escaped = { 0, 0, 0 }; - - *first_closing = '\0'; - first_closing++; - - smart_string_appends(&special_escaped, buffer); - tmp = php_escape_html_entities((unsigned char *) first_closing, strlen(first_closing), 0, 0, NULL); - smart_string_appends(&special_escaped, tmp->val); - zend_string_free(tmp); - - smart_string_0(&special_escaped); - escaped = estrdup(special_escaped.c); - smart_string_free(&special_escaped); - } else if (strncmp(buffer, "assert()", 8) == 0) { - /* Also don't escape if we're in an assert, as things are already - * escaped. It's all nice and consistent ey? */ - escaped = estrdup(buffer); - } else { - tmp = php_escape_html_entities((unsigned char *) buffer, strlen(buffer), 0, 0, NULL); - escaped = estrdup(tmp->val); - zend_string_free(tmp); - } - } - - if (strlen(XINI_LIB(file_link_format)) > 0 && html && strcmp(error_filename, "Unknown") != 0) { - char *file_link; - - xdebug_format_file_link(&file_link, error_filename, error_lineno); - xdebug_str_add_fmt(str, formats11, error_type_str, escaped, file_link, error_filename, error_lineno); - xdfree(file_link); - } else { - xdebug_str_add_fmt(str, formats1, error_type_str, escaped, error_filename, error_lineno); - } - - efree(escaped); -} - -static void add_single_value(xdebug_str *str, zval *zv, int html) -{ - xdebug_str *tmp_value = NULL; - char *tmp_html_value = NULL; - size_t newlen; - - if (html) { - tmp_value = xdebug_get_zval_value_line(zv, 0, NULL); - tmp_html_value = xdebug_xmlize(tmp_value->d, tmp_value->l, &newlen); - - xdebug_str_add_literal(str, "<span>"); - xdebug_str_add(str, tmp_html_value, 0); - xdebug_str_add_literal(str, "</span>"); - - xdebug_str_free(tmp_value); - efree(tmp_html_value); - } else { - tmp_value = xdebug_get_zval_value_line(zv, 0, NULL); - - if (tmp_value) { - xdebug_str_add_str(str, tmp_value); - xdebug_str_free(tmp_value); - } else { - xdebug_str_add_literal(str, "???"); - } - } -} - -#define XDEBUG_VAR_FORMAT_INITIALISED 0 -#define XDEBUG_VAR_FORMAT_UNINITIALISED 1 - -static const char* text_var_formats2 = { - " $%s = %s\n", - " $%s = *uninitialized*\n", -}; - -static const char* ansi_var_formats2 = { - " $%s = %s\n", - " $%s = *uninitialized*\n", -}; - -static const char* html_var_formats2 = { - "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s =</pre></td><td colspan='3' bgcolor='#eeeeec'>%s</td></tr>\n", - "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s =</pre></td><td colspan='3' bgcolor='#eeeeec' valign='top'><i>Undefined</i></td></tr>\n", -}; - -static const char** get_var_format_string(int html) -{ - if (html) { - return html_var_formats; - } else if ((XINI_DEV(cli_color) == 1 && xdebug_is_output_tty()) || (XINI_DEV(cli_color) == 2)) { - return ansi_var_formats; - } else { - return text_var_formats; - } -} - - -static void xdebug_dump_used_var_with_contents(void *htmlq, xdebug_hash_element* he, void *argument) -{ - int html = *(int*) htmlq; - zval zvar; - xdebug_str *contents; - xdebug_str *name = (xdebug_str*) he->ptr; - HashTable *tmp_ht; - const char **formats; - xdebug_str *str = (xdebug_str *) argument; - - if (!he->ptr) { - return; - } - - /* Bail out on $this and $GLOBALS */ - if (strcmp(name->d, "this") == 0 || strcmp(name->d, "GLOBALS") == 0) { - return; - } - - if (EG(current_execute_data) && !(ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_HAS_SYMBOL_TABLE)) { - zend_rebuild_symbol_table(); - } - - tmp_ht = xdebug_lib_get_active_symbol_table(); - { - zend_execute_data *ex = EG(current_execute_data); - while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) { - ex = ex->prev_execute_data; - } - if (ex) { - xdebug_lib_set_active_data(ex); - xdebug_lib_set_active_symbol_table(ex->symbol_table); - } - } - - xdebug_get_php_symbol(&zvar, name); - xdebug_lib_set_active_symbol_table(tmp_ht); - - formats = get_var_format_string(PG(html_errors)); - - if (Z_TYPE(zvar) == IS_UNDEF) { - xdebug_str_add_fmt(str, formatsXDEBUG_VAR_FORMAT_UNINITIALISED, name->d); - return; - } - - if (html) { - contents = xdebug_get_zval_value_html(NULL, &zvar, 0, NULL); - } else { - contents = xdebug_get_zval_value_line(&zvar, 0, NULL); - } - - if (contents) { - xdebug_str_add_fmt(str, formatsXDEBUG_VAR_FORMAT_INITIALISED, name->d, contents->d); - } else { - xdebug_str_add_fmt(str, formatsXDEBUG_VAR_FORMAT_UNINITIALISED, name->d); - } - - if (contents) { - xdebug_str_free(contents); - } - zval_ptr_dtor_nogc(&zvar); -} - -void xdebug_append_printable_stack(xdebug_str *str, int html) -{ - int printed_frames = 0; - const char **formats = select_formats(html); - int i; - function_stack_entry *fse; - - if (!XG_BASE(stack) || XDEBUG_VECTOR_COUNT(XG_BASE(stack)) < 1) { - return; - } - - fse = XDEBUG_VECTOR_HEAD(XG_BASE(stack)); - - xdebug_str_add_const(str, formats2); - - for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, fse++) - { - int c = 0; /* Comma flag */ - unsigned int j = 0; /* Counter */ - char *tmp_name; - int variadic_opened = 0; - int sent_variables = fse->varc; - - if (sent_variables > 0 && fse->varsent_variables-1.is_variadic && Z_ISUNDEF(fse->varsent_variables-1.data)) { - sent_variables--; - } - - if (xdebug_is_stack_frame_filtered(XDEBUG_FILTER_STACK, fse)) { - continue; - } - tmp_name = xdebug_show_fname(fse->function, html ? XDEBUG_SHOW_FNAME_ALLOW_HTML : XDEBUG_SHOW_FNAME_DEFAULT); - if (html) { - xdebug_str_add_fmt(str, formats3, fse->level, XDEBUG_SECONDS_SINCE_START(fse->nanotime), fse->memory, tmp_name); - } else { - xdebug_str_add_fmt(str, formats3, XDEBUG_SECONDS_SINCE_START(fse->nanotime), fse->memory, fse->level, tmp_name); - } - xdfree(tmp_name); - - /* Printing vars */ - for (j = 0; j < sent_variables; j++) { - if (c) { - xdebug_str_add_literal(str, ", "); - } else { - c = 1; - } - - if ( - (fse->varj.is_variadic && Z_ISUNDEF(fse->varj.data)) - ) { - xdebug_str_add_literal(str, "..."); - } - - if (fse->varj.name) { - if (html) { - xdebug_str_add_literal(str, "<span>$"); - xdebug_str_add_zstr(str, fse->varj.name); - xdebug_str_add_literal(str, " = </span>"); - } else { - xdebug_str_add_literal(str, "$"); - xdebug_str_add_zstr(str, fse->varj.name); - xdebug_str_add_literal(str, " = "); - } - } - - if (!variadic_opened && fse->varj.is_variadic && Z_ISUNDEF(fse->varj.data)) { - if (html) { - xdebug_str_add_literal(str, "<i>variadic</i>("); - } else { - xdebug_str_add_literal(str, "variadic("); - } - c = 0; - variadic_opened = 1; - continue; - } - - if (!Z_ISUNDEF(fse->varj.data)) { - add_single_value(str, &fse->varj.data, html); - } else { - xdebug_str_add_literal(str, "???"); - } - } - - if (variadic_opened) { - xdebug_str_add_literal(str, ")"); - } - - if (fse->include_filename) { - if (html) { - xdebug_str_add_literal(str, "<font color='#00bb00'>'"); - xdebug_str_add_zstr(str, fse->include_filename); - xdebug_str_add_literal(str, "</font>"); - } else { - xdebug_str_addc(str, '\''); - xdebug_str_add_zstr(str, fse->include_filename); - xdebug_str_addc(str, '\''); - } - } - - if (html) { - char *formatted_filename; - xdebug_format_filename(&formatted_filename, "...%s%n", fse->filename); - - if (strlen(XINI_LIB(file_link_format)) > 0 && strcmp(ZSTR_VAL(fse->filename), "Unknown") != 0) { - char *file_link; - - xdebug_format_file_link(&file_link, ZSTR_VAL(fse->filename), fse->lineno); - xdebug_str_add_fmt(str, formats10, ZSTR_VAL(fse->filename), file_link, formatted_filename, fse->lineno); - xdfree(file_link); - } else { - xdebug_str_add_fmt(str, formats5, ZSTR_VAL(fse->filename), formatted_filename, fse->lineno); - } - - xdfree(formatted_filename); - } else { - xdebug_str_add_fmt(str, formats5, ZSTR_VAL(fse->filename), fse->lineno); - } - - printed_frames++; - if (XINI_DEV(max_stack_frames) > 0 && printed_frames >= XINI_DEV(max_stack_frames)) { - break; - } - } - - if (XINI_DEV(dump_globals) && !(XINI_DEV(dump_once) && XG_LIB(dumped))) { - char *tmp = xdebug_get_printable_superglobals(html); - - if (tmp) { - xdebug_str_add(str, tmp, 1); - } - XG_LIB(dumped) = 1; - } - - if (XINI_DEV(show_local_vars) && XG_BASE(stack) && XDEBUG_VECTOR_TAIL(XG_BASE(stack))) { - int scope_nr = XDEBUG_VECTOR_COUNT(XG_BASE(stack)); - - fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - if (fse->user_defined == XDEBUG_BUILT_IN && xdebug_vector_element_is_valid(XG_BASE(stack), fse -1)) { - fse = fse - 1; - scope_nr--; - } - if (fse->declared_vars && fse->declared_vars->size) { - xdebug_hash *tmp_hash; - - xdebug_str_add_fmt(str, formats6, scope_nr); - tmp_hash = xdebug_declared_var_hash_from_llist(fse->declared_vars); - xdebug_hash_apply_with_argument(tmp_hash, (void*) &html, xdebug_dump_used_var_with_contents, (void *) str); - xdebug_hash_destroy(tmp_hash); - } - } -} - -void xdebug_append_error_footer(xdebug_str *str, int html) -{ - const char **formats = select_formats(html); - - xdebug_str_add_const(str, formats7); -} - -char *xdebug_get_printable_stack(int html, int error_type, const char *buffer, const char *error_filename, const int error_lineno, int include_decription) -{ - char *prepend_string; - char *append_string; - char *error_type_str = xdebug_error_type(error_type); - char *error_type_str_simple = xdebug_error_type_simple(error_type); - xdebug_str str = XDEBUG_STR_INITIALIZER; - - prepend_string = INI_STR((char*) "error_prepend_string"); - append_string = INI_STR((char*) "error_append_string"); - - if (prepend_string) { - xdebug_str_add(&str, prepend_string, 0); - } - xdebug_append_error_head(&str, html, error_type_str_simple); - if (include_decription) { - xdebug_append_error_description(&str, html, error_type_str, buffer, error_filename, error_lineno); - } - xdebug_append_printable_stack(&str, html); - xdebug_append_error_footer(&str, html); - if (append_string) { - xdebug_str_add(&str, append_string, 0); - } - - xdfree(error_type_str); - xdfree(error_type_str_simple); - - return str.d; -} - -static void php_output_error(const char *error) -{ -#ifdef PHP_DISPLAY_ERRORS_STDERR - if (PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR) { - fputs(error, stderr); - fflush(stderr); - return; - } -#endif - php_printf("%s", error); -} - -char *xdebug_strip_php_stack_trace(char *buffer) -{ - char *tmp_buf, *p; - - if (strncmp(buffer, "Uncaught ", 9) != 0) { - return NULL; - } - - /* find first new line */ - p = strchr(buffer, '\n'); - if (!p) { - p = buffer + strlen(buffer); - } else { - /* find the last " in ", which isn't great and might not work... but in most cases it will */ - p = xdebug_strrstr(buffer, " in "); - if (!p) { - p = buffer + strlen(buffer); - } - } - /* Create new buffer */ - tmp_buf = calloc(p - buffer + 1, 1); - strncpy(tmp_buf, buffer, p - buffer); - - return tmp_buf; -} - -static char *xdebug_handle_stack_trace(int type, char *error_type_str, const char *error_filename, const unsigned int error_lineno, char *buffer) -{ - char *printable_stack; - char *tmp_buf; - - /* We need to see if we have an uncaught exception fatal error now */ - if (type == E_ERROR && ((tmp_buf = xdebug_strip_php_stack_trace(buffer)) != NULL)) { - xdebug_str str = XDEBUG_STR_INITIALIZER; - - /* Append error */ - xdebug_append_error_head(&str, PG(html_errors), "uncaught-exception"); - xdebug_append_error_description(&str, PG(html_errors), error_type_str, tmp_buf, error_filename, error_lineno); - xdebug_append_printable_stack(&str, PG(html_errors)); - if (XG_BASE(last_exception_trace)) { - xdebug_str_add(&str, XG_BASE(last_exception_trace), 0); - } - xdebug_append_error_footer(&str, PG(html_errors)); - - free(tmp_buf); - printable_stack = str.d; - } else { - printable_stack = xdebug_get_printable_stack(PG(html_errors), type, buffer, error_filename, error_lineno, 1); - } - - return printable_stack; -} - -#if PHP_VERSION_ID >= 80000 -static void clear_last_error() -{ - if (PG(last_error_message)) { - zend_string_release(PG(last_error_message)); - PG(last_error_message) = NULL; - } - if (PG(last_error_file)) { -# if PHP_VERSION_ID >= 80100 - zend_string_release(PG(last_error_file)); -# else - free(PG(last_error_file)); -# endif - PG(last_error_file) = NULL; - } -} -#else -static void clear_last_error() -{ - if (PG(last_error_message)) { - char *s = PG(last_error_message); - PG(last_error_message) = NULL; - free(s); - } - if (PG(last_error_file)) { - char *s = PG(last_error_file); - PG(last_error_file) = NULL; - free(s); - } -} -#endif - -/* Error callback for formatting stack traces */ -#if PHP_VERSION_ID >= 80100 -void xdebug_develop_error_cb(int orig_type, zend_string *error_filename, const unsigned int error_lineno, zend_string *message) -{ -#elif PHP_VERSION_ID >= 80000 -void xdebug_develop_error_cb(int orig_type, const char *error_filename, const unsigned int error_lineno, zend_string *message) -{ -#else -void xdebug_develop_error_cb(int orig_type, const char *error_filename, const unsigned int error_lineno, const char *format, va_list args) -{ - char *buffer; - int buffer_len; -#endif - - char *error_type_str; - int display; - int type = orig_type & E_ALL; - error_handling_t error_handling; - zend_class_entry *exception_class; - -#if PHP_VERSION_ID < 80000 - buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args); -#endif - - error_type_str = xdebug_error_type(type); - - /* check for repeated errors to be ignored */ - if (PG(ignore_repeated_errors) && PG(last_error_message)) { - /* no check for PG(last_error_file) is needed since it cannot - * be NULL if PG(last_error_message) is not NULL */ - -#if PHP_VERSION_ID >= 80000 - if (!zend_string_equals(PG(last_error_message), message) -#else - if (strcmp(PG(last_error_message), buffer) != 0 -#endif - || - (!PG(ignore_repeated_source) && ( - (PG(last_error_lineno) != (int)error_lineno) || -#if PHP_VERSION_ID >= 80100 - !zend_string_equals(PG(last_error_file), error_filename) -#else - strcmp(PG(last_error_file), error_filename) != 0 -#endif - )) - ) { - display = 1; - } else { - display = 0; - } - } else { - display = 1; - } - -#if PHP_VERSION_ID < 70300 - /* Store last error message for error_get_last() */ - if (display) { - clear_last_error(); - if (!error_filename) { - error_filename = "Unknown"; - } - PG(last_error_type) = type; - PG(last_error_message) = strdup(buffer); - PG(last_error_file) = strdup(error_filename); - PG(last_error_lineno) = error_lineno; - } -#endif - error_handling = EG(error_handling); - exception_class = EG(exception_class); -#if PHP_VERSION_ID >= 70300 - /* according to error handling mode, throw exception or show it */ - if (error_handling == EH_THROW) { -#else - /* according to error handling mode, suppress error, throw exception or show it */ - if (error_handling != EH_NORMAL) { -#endif - switch (type) { - case E_ERROR: - case E_CORE_ERROR: - case E_COMPILE_ERROR: - case E_USER_ERROR: - case E_PARSE: - /* fatal errors are real errors and cannot be made exceptions */ - break; - case E_STRICT: - case E_DEPRECATED: - case E_USER_DEPRECATED: - /* for the sake of BC to old damaged code */ - break; - case E_NOTICE: - case E_USER_NOTICE: - /* notices are no errors and are not treated as such like E_WARNINGS */ - break; - default: - /* throw an exception if we are in EH_THROW mode - * but DO NOT overwrite a pending exception - */ -#if PHP_VERSION_ID >= 70300 - if (!EG(exception)) { -#else - if (error_handling == EH_THROW && !EG(exception)) { -#endif -#if PHP_VERSION_ID >= 80000 - zend_throw_error_exception(exception_class, message, 0, type); -#else - zend_throw_error_exception(exception_class, buffer, 0, type); -#endif - } -#if PHP_VERSION_ID < 80000 - efree(buffer); -#endif - xdfree(error_type_str); - return; - } - } - -#if PHP_VERSION_ID >= 70300 - /* Store last error message for error_get_last() */ - if (display) { - clear_last_error(); - if (!error_filename) { -# if PHP_VERSION_ID >= 80100 - error_filename = zend_string_init(ZEND_STRL("Unknown"), 0); -# else - error_filename = "Unknown"; -# endif - } - PG(last_error_type) = type; -# if PHP_VERSION_ID >= 80000 - PG(last_error_message) = zend_string_copy(message); -# else - PG(last_error_message) = strdup(buffer); -# endif -# if PHP_VERSION_ID >= 80100 - PG(last_error_file) = zend_string_copy(error_filename); -# else - PG(last_error_file) = strdup(error_filename); -# endif - PG(last_error_lineno) = error_lineno; - } -#endif - - if ((EG(error_reporting) | XINI_DEV(force_error_reporting)) & type) { - /* Log to logger */ - if (PG(log_errors)) { - -#ifdef PHP_WIN32 - if (type==E_CORE_ERROR || type==E_CORE_WARNING) { -#if PHP_VERSION_ID >= 80000 - php_syslog(LOG_ALERT, "PHP %s: %s (%s)", error_type_str, ZSTR_VAL(message), GetCommandLine()); -#else - MessageBox(NULL, buffer, error_type_str, MB_OK); -#endif - } -#endif -#if PHP_VERSION_ID >= 80100 - xdebug_log_stack(error_type_str, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno); -#elif PHP_VERSION_ID >= 80000 - xdebug_log_stack(error_type_str, ZSTR_VAL(message), error_filename, error_lineno); -#else - xdebug_log_stack(error_type_str, buffer, error_filename, error_lineno); -#endif - if (XINI_DEV(dump_globals) && !(XINI_DEV(dump_once) && XG_LIB(dumped))) { - char *printable_stack = xdebug_get_printable_superglobals(0); - - if (printable_stack) { - int pc; - - xdebug_arg *parts = xdebug_arg_ctor(); - - xdebug_explode("\n", printable_stack, parts, -1); - - for (pc = 0; pc < parts->c; pc++) { - char *tmp_line = xdebug_sprintf("PHP %s", parts->argspc); - php_log_err(tmp_line); - xdfree(tmp_line); - } - - xdebug_arg_dtor(parts); - xdfree(printable_stack); - php_log_err((char*) "PHP "); - } - } - } - - /* Display errors */ - if ((PG(display_errors) || XINI_DEV(force_display_errors)) && !PG(during_request_startup)) { - char *printable_stack; - -#if PHP_VERSION_ID >= 80100 - printable_stack = xdebug_handle_stack_trace(type, error_type_str, ZSTR_VAL(error_filename), error_lineno, ZSTR_VAL(message)); -#elif PHP_VERSION_ID >= 80000 - printable_stack = xdebug_handle_stack_trace(type, error_type_str, error_filename, error_lineno, ZSTR_VAL(message)); -#else - printable_stack = xdebug_handle_stack_trace(type, error_type_str, error_filename, error_lineno, buffer); -#endif - - if (XG_LIB(do_collect_errors) && (type != E_ERROR) && (type != E_COMPILE_ERROR) && (type != E_USER_ERROR)) { - xdebug_llist_insert_next(XG_DEV(collected_errors), XDEBUG_LLIST_TAIL(XG_DEV(collected_errors)), printable_stack); - } else { - php_output_error(printable_stack); - xdfree(printable_stack); - } - } else if (XG_LIB(do_collect_errors)) { - char *printable_stack; -#if PHP_VERSION_ID >= 80100 - printable_stack = xdebug_get_printable_stack(PG(html_errors), type, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno, 1); -#elif PHP_VERSION_ID >= 80000 - printable_stack = xdebug_get_printable_stack(PG(html_errors), type, ZSTR_VAL(message), error_filename, error_lineno, 1); -#else - printable_stack = xdebug_get_printable_stack(PG(html_errors), type, buffer, error_filename, error_lineno, 1); -#endif - xdebug_llist_insert_next(XG_DEV(collected_errors), XDEBUG_LLIST_TAIL(XG_DEV(collected_errors)), printable_stack); - } - } - - { -#if PHP_VERSION_ID >= 80100 - zend_string *tmp_error_filename = zend_string_copy(error_filename); -#else - zend_string *tmp_error_filename = zend_string_init(error_filename, strlen(error_filename), 0); -#endif -#if PHP_VERSION_ID >= 80000 - xdebug_debugger_error_cb(tmp_error_filename, error_lineno, type, error_type_str, ZSTR_VAL(message)); -#else - xdebug_debugger_error_cb(tmp_error_filename, error_lineno, type, error_type_str, buffer); -#endif - zend_string_release(tmp_error_filename); - } - - xdfree(error_type_str); - - if (type & XINI_DEV(halt_level) & XDEBUG_ALLOWED_HALT_LEVELS) { - type = E_USER_ERROR; - } - - /* Bail out if we can't recover */ - switch (type) { - case E_CORE_ERROR: - if (!php_get_module_initialized()) { - /* bad error in module startup - no way we can live with this */ - exit(-2); - } - XDEBUG_BREAK_INTENTIONALLY_MISSING - - case E_ERROR: - case E_RECOVERABLE_ERROR: - case E_PARSE: - case E_COMPILE_ERROR: - case E_USER_ERROR: - EG(exit_status) = 255; - if (php_get_module_initialized()) { - if (!PG(display_errors) && - !SG(headers_sent) && - SG(sapi_headers).http_response_code == 200 - ) { - sapi_header_line ctr = { 0, 0, 0 }; - - ctr.line = (char*) "HTTP/1.0 500 Internal Server Error"; - ctr.line_len = sizeof("HTTP/1.0 500 Internal Server Error") - 1; - sapi_header_op(SAPI_HEADER_REPLACE, &ctr); - } - /* the parser would return 1 (failure), we can bail out nicely */ -#if PHP_VERSION_ID >= 80000 - if (!(orig_type & E_DONT_BAIL)) { -#else - if (type != E_PARSE) { -#endif - /* restore memory limit */ - zend_set_memory_limit(PG(memory_limit)); -#if PHP_VERSION_ID < 80000 - efree(buffer); -#endif - zend_objects_store_mark_destructed(&EG(objects_store)); - _zend_bailout((char*) __FILE__, __LINE__); - return; - } - } - break; - } - -#if PHP_VERSION_ID < 70400 - /* Log if necessary */ - if (!display) { - efree(buffer); - return; - } - - if (PG(track_errors) && EG(active)) { - zval tmp; - ZVAL_STRINGL(&tmp, buffer, buffer_len); - - if (EG(current_execute_data)) { - if (zend_set_local_var_str("php_errormsg", sizeof("php_errormsg")-1, &tmp, 0) == FAILURE) { - zval_ptr_dtor(&tmp); - } - } else { - zend_hash_str_update(&EG(symbol_table), "php_errormsg", sizeof("php_errormsg"), &tmp); - } - } -#endif - -#if PHP_VERSION_ID < 80000 - efree(buffer); -#endif -} - -#if PHP_VERSION_ID >= 80000 -void xdebug_develop_throw_exception_hook(zend_object *exception, zval *file, zval *line, zval *code, char *code_str, zval *message) -{ - zend_class_entry *exception_ce = exception->ce; -#else -void xdebug_develop_throw_exception_hook(zval *exception, zval *file, zval *line, zval *code, char *code_str, zval *message) -{ - zend_class_entry *exception_ce = Z_OBJCE_P(exception); -#endif - zval *xdebug_message_trace, *previous_exception; - char *exception_trace; - xdebug_str tmp_str = XDEBUG_STR_INITIALIZER; - zval dummy; - - previous_exception = zend_read_property(exception_ce, exception, "previous", sizeof("previous")-1, 1, &dummy); - if (previous_exception && Z_TYPE_P(previous_exception) == IS_OBJECT) { -#if PHP_VERSION_ID >= 80000 - xdebug_message_trace = zend_read_property(exception_ce, Z_OBJ_P(previous_exception), "xdebug_message", sizeof("xdebug_message")-1, 1, &dummy); -#else - xdebug_message_trace = zend_read_property(exception_ce, previous_exception, "xdebug_message", sizeof("xdebug_message")-1, 1, &dummy); -#endif - if (xdebug_message_trace && Z_TYPE_P(xdebug_message_trace) != IS_NULL) { - xdebug_str_add(&tmp_str, Z_STRVAL_P(xdebug_message_trace), 0); - } - } - - if (!PG(html_errors)) { - xdebug_str_addc(&tmp_str, '\n'); - } - xdebug_append_error_description(&tmp_str, PG(html_errors), STR_NAME_VAL(exception_ce->name), message ? Z_STRVAL_P(message) : "", Z_STRVAL_P(file), Z_LVAL_P(line)); - xdebug_append_printable_stack(&tmp_str, PG(html_errors)); - exception_trace = tmp_str.d; - zend_update_property_string(exception_ce, exception, "xdebug_message", sizeof("xdebug_message")-1, exception_trace); - - if (XG_BASE(last_exception_trace)) { - xdfree(XG_BASE(last_exception_trace)); - } - XG_BASE(last_exception_trace) = exception_trace; - - if (XINI_DEV(show_ex_trace) || (instanceof_function(exception_ce, zend_ce_error) && XINI_DEV(show_error_trace))) { - if (PG(log_errors)) { - xdebug_log_stack(STR_NAME_VAL(exception_ce->name), Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line)); - } - if (PG(display_errors)) { - xdebug_str displ_tmp_str = XDEBUG_STR_INITIALIZER; - xdebug_append_error_head(&displ_tmp_str, PG(html_errors), "exception"); - xdebug_str_add(&displ_tmp_str, exception_trace, 0); - xdebug_append_error_footer(&displ_tmp_str, PG(html_errors)); - - php_printf("%s", displ_tmp_str.d); - xdebug_str_dtor(displ_tmp_str); - } - } -} - -/* {{{ proto int xdebug_get_stack_depth() - Returns the stack depth */ -PHP_FUNCTION(xdebug_get_stack_depth) -{ - /* We substract one so that the function call to xdebug_get_stack_depth() - * is not part of the returned depth. */ - RETURN_LONG(XDEBUG_VECTOR_COUNT(XG_BASE(stack)) - 1); -} - -/* {{{ proto array xdebug_get_function_stack() - Returns an array representing the current stack */ -PHP_FUNCTION(xdebug_get_function_stack) -{ - function_stack_entry *fse; - unsigned int i; - unsigned int j; - zval *frame; - zval *params; - int variadic_opened = 0; - - if (!XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - php_error(E_WARNING, "Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop'"); - array_init(return_value); - return; - } - - array_init(return_value); - - fse = XDEBUG_VECTOR_HEAD(XG_BASE(stack)); - - for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)) - 1; i++, fse++) { - int sent_variables = fse->varc; - - if (fse->function.function) { - if (strcmp(fse->function.function, "xdebug_get_function_stack") == 0) { - return; - } - } - - if (sent_variables > 0 && fse->varsent_variables-1.is_variadic && Z_ISUNDEF(fse->varsent_variables-1.data)) { - sent_variables--; - } - - /* Initialize frame array */ - XDEBUG_MAKE_STD_ZVAL(frame); - array_init(frame); - - /* Add data */ - if (fse->function.function) { - add_assoc_string_ex(frame, "function", HASH_KEY_SIZEOF("function"), fse->function.function); - } - if (fse->function.object_class) { - add_assoc_string_ex(frame, "type", HASH_KEY_SIZEOF("type"), (char*) (fse->function.type == XFUNC_STATIC_MEMBER ? "static" : "dynamic")); - add_assoc_str_ex(frame, "class", HASH_KEY_SIZEOF("class"), zend_string_copy(fse->function.object_class)); - } - add_assoc_str_ex(frame, "file", HASH_KEY_SIZEOF("file"), zend_string_copy(fse->filename)); - add_assoc_long_ex(frame, "line", HASH_KEY_SIZEOF("line"), fse->lineno); - - /* Add parameters */ - XDEBUG_MAKE_STD_ZVAL(params); - array_init(params); - add_assoc_zval_ex(frame, "params", HASH_KEY_SIZEOF("params"), params); - - for (j = 0; j < sent_variables; j++) { - xdebug_str *argument = NULL; - - if (fse->varj.is_variadic) { - zval *vparams; - - XDEBUG_MAKE_STD_ZVAL(vparams); - array_init(vparams); - - if (fse->varj.name) { - add_assoc_zval_ex(params, ZSTR_VAL(fse->varj.name), ZSTR_LEN(fse->varj.name), vparams); - } else { - add_index_zval(params, j, vparams); - } - efree(params); - params = vparams; - variadic_opened = 1; - continue; - } - if (!Z_ISUNDEF(fse->varj.data)) { - argument = xdebug_get_zval_value_line(&fse->varj.data, 0, NULL); - } else { - argument = xdebug_str_create_from_char((char*) "???"); - } - if (fse->varj.name && !variadic_opened && argument) { - add_assoc_stringl_ex(params, ZSTR_VAL(fse->varj.name), ZSTR_LEN(fse->varj.name), argument->d, argument->l); - } else { - add_index_stringl(params, j - variadic_opened, argument->d, argument->l); - } - if (argument) { - xdebug_str_free(argument); - argument = NULL; - } - } - - if (fse->include_filename) { - add_assoc_str_ex(frame, "include_filename", HASH_KEY_SIZEOF("include_filename"), zend_string_copy(fse->include_filename)); - } - - add_next_index_zval(return_value, frame); - efree(params); - efree(frame); - } -} -/* }}} */
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/develop/stack.h
Deleted
@@ -1,40 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef XDEBUG_STACK_H -#define XDEBUG_STACK_H - -#include "lib/str.h" - -#define XDEBUG_STACK_NO_DESC 0x01 - -void xdebug_append_error_head(xdebug_str *str, int html, const char *error_type_str); -void xdebug_append_error_description(xdebug_str *str, int html, const char *error_type_str, const char *buffer, const char *error_filename, const int error_lineno); -void xdebug_append_printable_stack(xdebug_str *str, int html); -void xdebug_append_error_footer(xdebug_str *str, int html); -void xdebug_log_stack(const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno); -char *xdebug_strip_php_stack_trace(char *buffer); -char *xdebug_get_printable_stack(int html, int error_type, const char *buffer, const char *error_filename, const int error_lineno, int include_decription); - -#if PHP_VERSION_ID >= 80100 -void xdebug_develop_error_cb(int orig_type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message); -#elif PHP_VERSION_ID >= 80000 -void xdebug_develop_error_cb(int orig_type, const char *error_filename, const uint32_t error_lineno, zend_string *message); -#else -void xdebug_develop_error_cb(int orig_type, const char *error_filename, const uint32_t error_lineno, const char *format, va_list args); -#endif - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/develop/superglobals.c
Deleted
@@ -1,208 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "SAPI.h" - -#include "php_xdebug.h" -#include "superglobals.h" - -#include "lib/compat.h" -#include "lib/lib.h" -#include "lib/var_export_html.h" -#include "lib/var_export_line.h" - -extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); - -void xdebug_superglobals_dump_dtor(void *user, void *ptr) -{ - free(ptr); -} - -static void dump_hash_elem(zval *z, const char *name, long index_key, const char *elem, int html, xdebug_str *str) -{ - if (html) { - if (elem) { - xdebug_str_add_fmt(str, "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s'%s' =</pre></td>", name, elem); - } else { - xdebug_str_add_fmt(str, "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s%ld =</pre></td>", name, index_key); - } - } - - if (z != NULL) { - xdebug_str *val; - - if (html) { - val = xdebug_get_zval_value_html(NULL, z, 0, NULL); - - xdebug_str_add_literal(str, "<td colspan='3' bgcolor='#eeeeec'>"); - xdebug_str_add_str(str, val); - xdebug_str_add_literal(str, "</td>"); - } else { - val = xdebug_get_zval_value_line(z, 0, NULL); - - if (elem) { - xdebug_str_add_fmt(str, "\n $%s'%s' = ", name, elem); - } else { - xdebug_str_add_fmt(str, "\n $%s%ld = ", name, index_key); - } - xdebug_str_add_str(str, val); - } - - xdebug_str_free(val); - } else { - /* not found */ - if (html) { - xdebug_str_add_literal(str, "<td colspan='3' bgcolor='#eeeeec'><i>undefined</i></td>"); - } else if (elem) { - xdebug_str_add_fmt(str, "\n $%s'%s' is undefined", name, elem); - } else { - xdebug_str_add_fmt(str, "\n $%s%ld is undefined", name, index_key); - } - } - - if (html) { - xdebug_str_add_literal(str, "</tr>\n"); - } -} - -static int dump_hash_elem_va(zval *pDest, zend_ulong index_key, zend_string *hash_key, const char *name, int html, xdebug_str *str) -{ - if (HASH_KEY_IS_NUMERIC(hash_key)) { - dump_hash_elem(pDest, name, index_key, NULL, html, str); - } else { - dump_hash_elem(pDest, name, 0, HASH_APPLY_KEY_VAL(hash_key), html, str); - } - - return SUCCESS; -} - -static void dump_hash(xdebug_llist *l, const char *name, int name_len, int html, xdebug_str *str) -{ - zval *z; - zend_ulong num; - zend_string *key; - zval *val; - HashTable *ht = NULL; - xdebug_llist_element *elem; - - if (!XDEBUG_LLIST_COUNT(l)) { - return; - } - - { - zend_string *s_name = zend_string_init(name, name_len, 0); - if ((z = zend_hash_find(&EG(symbol_table), s_name))) { - if (Z_TYPE_P(z) == IS_REFERENCE) { - z = &z->value.ref->val; - } - if (Z_TYPE_P(z) == IS_ARRAY) { - ht = Z_ARRVAL_P(z); - } - } - zend_string_release(s_name); - } - - if (html) { - xdebug_str_add_fmt(str, "<tr><th colspan='5' align='left' bgcolor='#e9b96e'>Dump <i>$%s</i></th></tr>\n", name); - } else { - xdebug_str_add_fmt(str, "\nDump $%s", name); - } - - elem = XDEBUG_LLIST_HEAD(l); - - while (elem != NULL) { - zend_string *s; - - s = zend_string_init(elem->ptr, strlen(elem->ptr), 0); - - if (ht && (*((char *) (elem->ptr)) == '*')) { - ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num, key, val) { - dump_hash_elem_va(val, num, key, name, html, str); - } ZEND_HASH_FOREACH_END(); - } else if (ht && (z = zend_hash_find(ht, s))) { - dump_hash_elem(z, name, 0, elem->ptr, html, str); - } else if (XINI_DEV(dump_undefined)) { - dump_hash_elem(NULL, name, 0, elem->ptr, html, str); - } - - elem = XDEBUG_LLIST_NEXT(elem); - - zend_string_release(s); - } -} - -char* xdebug_get_printable_superglobals(int html) -{ - xdebug_str str = XDEBUG_STR_INITIALIZER; - - dump_hash(&XG_DEV(server), "_SERVER", HASH_KEY_SIZEOF("_SERVER"), html, &str); - dump_hash(&XG_DEV(get), "_GET", HASH_KEY_SIZEOF("_GET"), html, &str); - dump_hash(&XG_DEV(post), "_POST", HASH_KEY_SIZEOF("_POST"), html, &str); - dump_hash(&XG_DEV(cookie), "_COOKIE", HASH_KEY_SIZEOF("_COOKIE"), html, &str); - dump_hash(&XG_DEV(files), "_FILES", HASH_KEY_SIZEOF("_FILES"), html, &str); - dump_hash(&XG_DEV(env), "_ENV", HASH_KEY_SIZEOF("_ENV"), html, &str); - dump_hash(&XG_DEV(session), "_SESSION", HASH_KEY_SIZEOF("_SESSION"), html, &str); - dump_hash(&XG_DEV(request), "_REQUEST", HASH_KEY_SIZEOF("_REQUEST"), html, &str); - - return str.d; -} - -void xdebug_superglobals_dump_tok(xdebug_llist *l, char *str) -{ - char *tok; - const char *sep = ","; - - tok = strtok(str, sep); - while (tok != NULL) { - char *p = tok + strlen(tok) - 1; - - while ((*tok == ' ') || (*tok == '\t')) { - tok++; - } - - while ((p > tok) && ((*p == ' ') || (*p == '\t'))) { - p--; - } - - *(p+1) = 0; - - /* we need to strdup each element so that we can safely free it */ - xdebug_llist_insert_next(l, NULL, strdup(tok)); - - tok = strtok(NULL, sep); - } -} - -PHP_FUNCTION(xdebug_dump_superglobals) -{ - int html = PG(html_errors); - char *superglobal_info = NULL; - - if (html) { - php_printf("<table class='xdebug-superglobals' dir='ltr' border='1' cellspacing='0'>\n"); - } - - superglobal_info = xdebug_get_printable_superglobals(html); - if (superglobal_info) { - php_printf("%s", xdebug_get_printable_superglobals(html)); - } else { - php_printf("<tr><td><i>No information about superglobals is available or configured.</i></td></tr>\n"); - } - - if (html) { - php_printf("</table>\n"); - } -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/develop/superglobals.h
Deleted
@@ -1,37 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __HAVE_XDEBUG_SUPERGLOBALS_H__ -#define __HAVE_XDEBUG_SUPERGLOBALS_H__ - -#include "php.h" - -#include "develop_private.h" - -void xdebug_superglobals_dump_dtor(void *, void*); -char *xdebug_get_printable_superglobals(int html); -void xdebug_superglobals_dump_tok(xdebug_llist *l, char *str); - -# define DUMP_TOK(__llist) \ - xdebug_llist_empty(&XG_DEV(__llist), NULL); \ - if (new_value && new_value->val) { \ - char *str = estrndup(new_value->val, new_value->len); \ - xdebug_superglobals_dump_tok(&XG_DEV(__llist), str); \ - efree(str); \ - } \ - return SUCCESS; - -#endif /* __HAVE_XDEBUG_SUPERGLOBALS_H__ */
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/gcstats/gc_stats.c
Deleted
@@ -1,381 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ -#include "php.h" -#include "zend_builtin_functions.h" -#include "SAPI.h" -#include "Zend/zend_long.h" - -#include "php_xdebug.h" -#include "gc_stats_private.h" - -#include "base/base.h" -#include "lib/lib.h" -#include "lib/log.h" - -/* Set correct int format to use */ -#define XDEBUG_GCINT_FMT ZEND_LONG_FMT_SPEC - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -static void xdebug_gc_stats_print_run(xdebug_gc_run *run); -static void xdebug_gc_stats_run_free(xdebug_gc_run *run); -int (*xdebug_old_gc_collect_cycles)(void); - -static int xdebug_gc_collect_cycles(void) -{ - int ret; - uint32_t collected; - xdebug_gc_run *run; - zend_execute_data *execute_data; - long int memory; - uint64_t start; - xdebug_func tmp; -#if PHP_VERSION_ID >= 70300 - zend_gc_status status; -#endif - - if (!XG_GCSTATS(active)) { - return xdebug_old_gc_collect_cycles(); - } - - execute_data = EG(current_execute_data); - -#if PHP_VERSION_ID >= 70300 - zend_gc_get_status(&status); - collected = status.collected; -#else - collected = GC_G(collected); -#endif - start = xdebug_get_nanotime(); - memory = zend_memory_usage(0); - - ret = xdebug_old_gc_collect_cycles(); - - run = xdmalloc(sizeof(xdebug_gc_run)); - run->function_name = NULL; - run->class_name = NULL; - -#if PHP_VERSION_ID >= 70300 - zend_gc_get_status(&status); - run->collected = status.collected - collected; -#else - run->collected = GC_G(collected) - collected; -#endif - run->duration = xdebug_get_nanotime() - start; - run->memory_before = memory; - run->memory_after = zend_memory_usage(0); - - xdebug_build_fname(&tmp, execute_data); - - run->function_name = tmp.function ? xdstrdup(tmp.function) : NULL; - run->class_name = tmp.object_class ? zend_string_copy(tmp.object_class) : NULL; - - xdebug_gc_stats_print_run(run); - - xdebug_gc_stats_run_free(run); - xdebug_func_dtor_by_ref(&tmp); - - return ret; -} - -static void xdebug_gc_stats_run_free(xdebug_gc_run *run) -{ - if (!run) { - return; - } - - if (run->function_name) { - xdfree(run->function_name); - } - if (run->class_name) { - zend_string_release(run->class_name); - } - xdfree(run); -} - -static int xdebug_gc_stats_init(char *requested_filename, zend_string *script_name) -{ - char *filename_to_use = NULL; - char *generated_filename = NULL; - char *output_dir = xdebug_lib_get_output_dir(); /* not duplicated */ - -#if PHP_VERSION_ID >= 70300 - if (!gc_enabled()) { - xdebug_log_ex(XLOG_CHAN_GCSTATS, XLOG_ERR, "DISABLED", "PHP's Garbage Collection is disabled"); - return FAILURE; - } -#endif - - if (requested_filename && strlen(requested_filename)) { - filename_to_use = xdstrdup(requested_filename); - } else { - if (!strlen(XINI_GCSTATS(output_name)) || - xdebug_format_output_filename(&generated_filename, XINI_GCSTATS(output_name), ZSTR_VAL(script_name)) <= 0) - { - return FAILURE; - } - - if (IS_SLASH(output_dirstrlen(output_dir) - 1)) { - filename_to_use = xdebug_sprintf("%s%s", output_dir, generated_filename); - } else { - filename_to_use = xdebug_sprintf("%s%c%s", output_dir, DEFAULT_SLASH, generated_filename); - } - } - - XG_GCSTATS(file) = xdebug_fopen(filename_to_use, "w", NULL, &XG_GCSTATS(filename)); - - if (!XG_GCSTATS(file)) { - xdebug_log_diagnose_permissions(XLOG_CHAN_GCSTATS, output_dir, filename_to_use); - - xdfree(filename_to_use); - if (generated_filename) { - xdfree(generated_filename); - } - - return FAILURE; - } - xdfree(filename_to_use); - - fprintf(XG_GCSTATS(file), "Garbage Collection Report\n"); - fprintf(XG_GCSTATS(file), "version: 1\ncreator: xdebug %s (PHP %s)\n\n", XDEBUG_VERSION, PHP_VERSION); - - fprintf(XG_GCSTATS(file), "Collected | Efficiency%% | Duration | Memory Before | Memory After | Reduction%% | Function\n"); - fprintf(XG_GCSTATS(file), "----------+-------------+----------+---------------+--------------+------------+---------\n"); - - fflush(XG_GCSTATS(file)); - - if (generated_filename) { - xdfree(generated_filename); - } - - return SUCCESS; -} - -static void xdebug_gc_stats_stop() -{ - XG_GCSTATS(active) = 0; - - if (XG_GCSTATS(file)) { -#if PHP_VERSION_ID >= 70300 - if (!gc_enabled()) { - fprintf(XG_GCSTATS(file), "Garbage Collection Disabled End\n"); - xdebug_log_ex(XLOG_CHAN_GCSTATS, XLOG_ERR, "DISABLED", "PHP's Garbage Collection is disabled at the end of the script"); - } -#endif - fclose(XG_GCSTATS(file)); - XG_GCSTATS(file) = NULL; - } -} - -#define AS_PERCENT(n) ((n)*100.0) -#define ROOTS_AS_PERCENT(n) AS_PERCENT((n) / 10000.0) - -static void xdebug_gc_stats_print_run(xdebug_gc_run *run) -{ - double reduction; - - if (run->memory_before) { - reduction = (1 - (float)run->memory_after / (float)run->memory_before) * 100.0; - } else { - reduction = 0; - } - - if (!XG_GCSTATS(file)) { - return; - } - - if (!run->function_name) { - fprintf(XG_GCSTATS(file), - "%9" XDEBUG_GCINT_FMT " | %9.2f %% | %5.2f ms | %13" XDEBUG_GCINT_FMT " | %12" XDEBUG_GCINT_FMT " | %8.2f %% | -\n", - run->collected, - ROOTS_AS_PERCENT(run->collected), - run->duration / (double)NANOS_IN_MILLISEC, - run->memory_before, - run->memory_after, - reduction - ); - } else if (!run->class_name && run->function_name) { - fprintf(XG_GCSTATS(file), - "%9" XDEBUG_GCINT_FMT " | %9.2f %% | %5.2f ms | %13" XDEBUG_GCINT_FMT " | %12" XDEBUG_GCINT_FMT " | %8.2f %% | %s\n", - run->collected, - ROOTS_AS_PERCENT(run->collected), - run->duration / (double)NANOS_IN_MILLISEC, - run->memory_before, - run->memory_after, - reduction, - run->function_name - ); - } else if (run->class_name && run->function_name) { - fprintf(XG_GCSTATS(file), - "%9" XDEBUG_GCINT_FMT " | %9.2f %% | %5.2f ms | %13" XDEBUG_GCINT_FMT " | %12" XDEBUG_GCINT_FMT " | %8.2f %% | %s::%s\n", - run->collected, - ROOTS_AS_PERCENT(run->collected), - run->duration / (double)NANOS_IN_MILLISEC, - run->memory_before, - run->memory_after, - reduction, - ZSTR_VAL(run->class_name), - run->function_name - ); - } - - fflush(XG_GCSTATS(file)); -} - -/* {{{ proto void xdebug_get_gcstats_filename() - Returns the name of the current garbage collection statistics report file */ -PHP_FUNCTION(xdebug_get_gcstats_filename) -{ - if (XG_GCSTATS(filename)) { - RETURN_STRING(XG_GCSTATS(filename)); - } else { - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto void xdebug_start_gcstats(string $fname) - Start collecting garbage collection statistics */ -PHP_FUNCTION(xdebug_start_gcstats) -{ - char *fname = NULL; - size_t fname_len = 0; - function_stack_entry *fse; - - if (XG_GCSTATS(active)) { - php_error(E_NOTICE, "Garbage Collection statistics are already being collected."); - RETURN_FALSE; - } - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &fname, &fname_len) == FAILURE) { - return; - } - - fse = xdebug_get_stack_frame(0); - - if (xdebug_gc_stats_init(fname, fse->filename) == SUCCESS) { - XG_GCSTATS(active) = 1; - RETVAL_STRING(XG_GCSTATS(filename)); - return; - } - - php_error(E_NOTICE, "Garbage Collection statistics could not be started"); - - XG_GCSTATS(active) = 0; - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto void xdebug_stop_gcstats() - Stop collecting garbage collection statistics */ -PHP_FUNCTION(xdebug_stop_gcstats) -{ - if (!XG_GCSTATS(active)) { - php_error(E_NOTICE, "Garbage Collection statistics was not started"); - RETURN_FALSE; - } - - xdebug_gc_stats_stop(); - RETURN_STRING(XG_GCSTATS(filename)); -} - -/* {{{ proto void xdebug_get_gc_run_count() - Return number of times garbage collection was triggered. */ -PHP_FUNCTION(xdebug_get_gc_run_count) -{ -#if PHP_VERSION_ID >= 70300 - zend_gc_status status; -#endif - -#if PHP_VERSION_ID >= 70300 - zend_gc_get_status(&status); - RETURN_LONG(status.runs); -#else - RETURN_LONG(GC_G(gc_runs)); -#endif -} - -/* {{{ proto void xdebug_get_gc_total_collected_roots() - Return total number of collected root variables during garbage collection. */ -PHP_FUNCTION(xdebug_get_gc_total_collected_roots) -{ -#if PHP_VERSION_ID >= 70300 - zend_gc_status status; -#endif - -#if PHP_VERSION_ID >= 70300 - zend_gc_get_status(&status); - RETURN_LONG(status.collected); -#else - RETURN_LONG(GC_G(collected)); -#endif -} - -/* {{{ helpers */ -void xdebug_gcstats_init_if_requested(zend_op_array* op_array) -{ - RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_GCSTATS); - if (!xdebug_lib_start_with_request(XDEBUG_MODE_GCSTATS)) { - return; - } - - if (XG_GCSTATS(active)) { - return; - } - - if (xdebug_gc_stats_init(NULL, op_array->filename) == SUCCESS) { - XG_GCSTATS(active) = 1; - } -} - -/* }}} */ - -/* {{{ initialisation */ -void xdebug_init_gc_stats_globals(xdebug_gc_stats_globals_t *xg) -{ - xg->file = NULL; - xg->filename = NULL; - xg->active = 0; -} - -void xdebug_gcstats_minit() -{ - /* Replace garbage collection handler with our own */ - xdebug_old_gc_collect_cycles = gc_collect_cycles; - gc_collect_cycles = xdebug_gc_collect_cycles; -} - -void xdebug_gcstats_mshutdown() -{ - gc_collect_cycles = xdebug_old_gc_collect_cycles; -} - -void xdebug_gcstats_rinit() -{ - xdebug_init_gc_stats_globals(&XG(globals).gc_stats); -} - -void xdebug_gcstats_rshutdown() -{ - if (XG_GCSTATS(active)) { - xdebug_gc_stats_stop(); - } - - if (XG_GCSTATS(filename)) { - xdfree(XG_GCSTATS(filename)); - } -} -/* }}} */
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/compat.c
Deleted
@@ -1,448 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans <derick@xdebug.org> | - | (c) 1997-2004 Jim Winstead <jimw@trainedmonkey.com> | - | (c) 1998-2004 Andi Gutmans <andi@zend.com> and | - | Zeev Suraski <zeev@zend.com> | - +----------------------------------------------------------------------+ - | This source file is subject to the following Modified BSD license: | - | | - | Redistribution and use in source and binary forms, with or without | - | modification, are permitted provided that the following conditions | - | are met: | - | | - | 1. Redistributions of source code must retain the above copyright | - | notice, this list of conditions and the following disclaimer. | - | | - | 2. Redistributions in binary form must reproduce the above | - | copyright notice, this list of conditions and the following | - | disclaimer in the documentation and/or other materials provided | - | with the distribution. | - | | - | 3. The name of the author may not be used to endorse or promote | - | products derived from this software without specific prior | - | written permission. | - | | - | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | - | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | - | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | - | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | - | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | - | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | - | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | - | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | - | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | - | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | - | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "main/php_version.h" -#include "compat.h" -#include "zend_extensions.h" - -#include "zend_compile.h" -#include "ext/standard/base64.h" -#include "ext/standard/php_string.h" - -char *xdebug_str_to_str(char *haystack, size_t length, const char *needle, size_t needle_len, const char *str, size_t str_len, size_t *new_len) -{ - zend_string *new_str; - char *retval; - - new_str = php_str_to_str(haystack, length, (char*) needle, needle_len, (char*) str, str_len); - *new_len = new_str->len; - - retval = estrndup(new_str->val, new_str->len); - - zend_string_release(new_str); - - return retval; -} - -/* {{{ base64 tables */ -static const char base64_table = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', - 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', - 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', - 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0' -}; - -static const char base64_pad = '='; - -static const short base64_reverse_table256 = { - -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -2, -2, -1, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, -2, -2, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, -2, -2, -2, - -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, -2, - -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, - -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 -}; -/* }}} */ - -static unsigned char *xdebug_base64_encode_impl(const unsigned char *in, size_t inl, unsigned char *out) /* {{{ */ -{ - - while (inl > 2) { /* keep going until we have less than 24 bits */ - *out++ = base64_tablein0 >> 2; - *out++ = base64_table((in0 & 0x03) << 4) + (in1 >> 4); - *out++ = base64_table((in1 & 0x0f) << 2) + (in2 >> 6); - *out++ = base64_tablein2 & 0x3f; - - in += 3; - inl -= 3; /* we just handle 3 octets of data */ - } - - /* now deal with the tail end of things */ - if (inl != 0) { - *out++ = base64_tablein0 >> 2; - if (inl > 1) { - *out++ = base64_table((in0 & 0x03) << 4) + (in1 >> 4); - *out++ = base64_table(in1 & 0x0f) << 2; - *out++ = base64_pad; - } else { - *out++ = base64_table(in0 & 0x03) << 4; - *out++ = base64_pad; - *out++ = base64_pad; - } - } - - *out = '\0'; - - return out; -} -/* }}} */ - -static int xdebug_base64_decode_impl(const unsigned char *in, size_t inl, unsigned char *out, size_t *outl, zend_bool strict) /* {{{ */ -{ - int ch; - size_t i = 0, padding = 0, j = *outl; - - /* run through the whole string, converting as we go */ - while (inl-- > 0) { - ch = *in++; - if (ch == base64_pad) { - padding++; - continue; - } - - ch = base64_reverse_tablech; - if (!strict) { - /* skip unknown characters and whitespace */ - if (ch < 0) { - continue; - } - } else { - /* skip whitespace */ - if (ch == -1) { - continue; - } - /* fail on bad characters or if any data follows padding */ - if (ch == -2 || padding) { - goto fail; - } - } - - switch (i % 4) { - case 0: - outj = ch << 2; - break; - case 1: - outj++ |= ch >> 4; - outj = (ch & 0x0f) << 4; - break; - case 2: - outj++ |= ch >>2; - outj = (ch & 0x03) << 6; - break; - case 3: - outj++ |= ch; - break; - } - i++; - } - - /* fail if the input is truncated (only one char in last group) */ - if (strict && i % 4 == 1) { - goto fail; - } - - /* fail if the padding length is wrong (not VV==, VVV=), but accept zero padding - * RFC 4648: "In some circumstances, the use of padding -- is not required" */ - if (strict && padding && (padding > 2 || (i + padding) % 4 != 0)) { - goto fail; - } - - *outl = j; - outj = '\0'; - - return 1; - -fail: - return 0; -} -/* }}} */ - -unsigned char *xdebug_base64_encode(unsigned char *data, size_t data_len, size_t *new_len) -{ - unsigned char *retval = xdmalloc((((data_len + 2) / 3) + 1) * (4 * sizeof(char))); - unsigned char *end; - - end = xdebug_base64_encode_impl(data, data_len, retval); - *new_len = end - retval; - - return retval; -} - -unsigned char *xdebug_base64_decode(unsigned char *data, size_t data_len, size_t *new_len) -{ - unsigned char *retval = xdmalloc(data_len + 1); - - xdebug_base64_decode_impl(data, data_len, retval, new_len, 0); - - return retval; -} - -zend_string *xdebug_addslashes(zend_string *str) -{ - /* maximum string length, worst case situation */ - char *target; - const char *source, *end; - size_t offset; - zend_string *new_str; - - if (!str) { - return ZSTR_EMPTY_ALLOC(); - } - - source = ZSTR_VAL(str); - end = source + ZSTR_LEN(str); - - while (source < end) { - switch (*source) { - case '\0': - case '\'': - case '\"': - case '\\': - goto do_escape; - default: - source++; - break; - } - } - - return zend_string_copy(str); - -do_escape: - offset = source - (char *)ZSTR_VAL(str); - new_str = zend_string_safe_alloc(2, ZSTR_LEN(str) - offset, offset, 0); - memcpy(ZSTR_VAL(new_str), ZSTR_VAL(str), offset); - target = ZSTR_VAL(new_str) + offset; - - while (source < end) { - switch (*source) { - case '\0': - *target++ = '\\'; - *target++ = '0'; - break; - case '\'': - case '\"': - case '\\': - *target++ = '\\'; - XDEBUG_BREAK_INTENTIONALLY_MISSING - - default: - *target++ = *source; - break; - } - source++; - } - - *target = '\0'; - - if (ZSTR_LEN(new_str) - (target - ZSTR_VAL(new_str)) > 16) { - new_str = zend_string_truncate(new_str, target - ZSTR_VAL(new_str), 0); - } else { - ZSTR_LEN(new_str) = target - ZSTR_VAL(new_str); - } - - return new_str; -} - -void xdebug_stripcslashes(char *str, int *len) -{ - char *source, *target, *end; - int nlen = *len, i; - char numtmp4; - - for (source=str, end=str+nlen, target=str; source < end; source++) { - if (*source == '\\' && source+1 < end) { - source++; - switch (*source) { - case 'n': *target++='\n'; nlen--; break; - case 'r': *target++='\r'; nlen--; break; - case 'a': *target++='\a'; nlen--; break; - case 't': *target++='\t'; nlen--; break; - case 'v': *target++='\v'; nlen--; break; - case 'b': *target++='\b'; nlen--; break; - case 'f': *target++='\f'; nlen--; break; - case '\\': *target++='\\'; nlen--; break; - case 'x': - if (source+1 < end && isxdigit((int)(*(source+1)))) { - numtmp0 = *++source; - if (source+1 < end && isxdigit((int)(*(source+1)))) { - numtmp1 = *++source; - numtmp2 = '\0'; - nlen-=3; - } else { - numtmp1 = '\0'; - nlen-=2; - } - *target++=(char)strtol(numtmp, NULL, 16); - break; - } - XDEBUG_BREAK_INTENTIONALLY_MISSING - - default: - i=0; - while (source < end && *source >= '0' && *source <= '7' && i<3) { - numtmpi++ = *source++; - } - if (i) { - numtmpi='\0'; - *target++=(char)strtol(numtmp, NULL, 8); - nlen-=i; - source--; - } else { - *target++=*source; - nlen--; - } - } - } else { - *target++=*source; - } - } - - if (nlen != 0) { - *target='\0'; - } - - *len = nlen; -} - -zend_ulong xdebug_get_pid(void) -{ -#ifndef ZTS - return (zend_ulong) getpid(); -#else -# ifdef _WIN32 - return (zend_ulong) GetCurrentThreadId(); -# else - return (zend_ulong) pthread_self(); -# endif -#endif -} - -void xdebug_setcookie(const char *name, int name_len, char *value, int value_len, time_t expires, const char *path, int path_len, const char *domain, int domain_len, int secure, int url_encode, int httponly) -{ - zend_string *name_s = name ? zend_string_init(name, name_len, 0) : NULL; - zend_string *value_s = value ? zend_string_init(value, value_len, 0) : NULL; - zend_string *path_s = path ? zend_string_init(path, path_len, 0) : NULL; - zend_string *domain_s = domain ? zend_string_init(domain, domain_len, 0) : NULL; -#if PHP_VERSION_ID >= 70300 - zend_string *samesite_s = zend_string_init("Lax", sizeof("Lax") - 1, 0); - php_setcookie(name_s, value_s, expires, path_s, domain_s, secure, httponly, samesite_s, url_encode); - zend_string_release(samesite_s); -#else - php_setcookie(name_s, value_s, expires, path_s, domain_s, secure, url_encode, httponly); -#endif - name ? zend_string_release(name_s) : 0; - value ? zend_string_release(value_s) : 0; - path ? zend_string_release(path_s) : 0; - domain ? zend_string_release(domain_s) : 0; -} - -char *xdebug_get_compiled_variable_name(zend_op_array *op_array, uint32_t var, int *cv_len) -{ - zend_string *cv = NULL; - cv = zend_get_compiled_variable_name(op_array, var); - *cv_len = cv->len; - - return cv->val; -} - -#ifdef ZEND_HASH_GET_APPLY_COUNT /* PHP 7.2 or earlier recursion protection */ -zend_bool xdebug_zend_hash_is_recursive(HashTable* ht) -{ - return (ZEND_HASH_GET_APPLY_COUNT(ht) > 0); -} - -zend_bool xdebug_zend_hash_apply_protection_begin(HashTable* ht) -{ - if (!ht) { - return 1; - } - if (ZEND_HASH_GET_APPLY_COUNT(ht) > 0) { - return 0; - } - if (ZEND_HASH_APPLY_PROTECTION(ht)) { - ZEND_HASH_INC_APPLY_COUNT(ht); - } - return 1; -} - -zend_bool xdebug_zend_hash_apply_protection_end(HashTable* ht) -{ - if (!ht) { - return 1; - } - if (ZEND_HASH_GET_APPLY_COUNT(ht) == 0) { - return 0; - } - if (ZEND_HASH_APPLY_PROTECTION(ht)) { - ZEND_HASH_DEC_APPLY_COUNT(ht); - } - return 1; -} -#else /* PHP 7.3 or later */ -zend_bool xdebug_zend_hash_is_recursive(HashTable* ht) -{ - return GC_IS_RECURSIVE(ht); -} - -zend_bool xdebug_zend_hash_apply_protection_begin(zend_array* ht) -{ - if (GC_IS_RECURSIVE(ht)) { - return 0; - } - if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { - GC_PROTECT_RECURSION(ht); - } - return 1; -} - -zend_bool xdebug_zend_hash_apply_protection_end(zend_array* ht) -{ - if (!GC_IS_RECURSIVE(ht)) { - return 0; - } - if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { - GC_UNPROTECT_RECURSION(ht); - } - return 1; -} -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/compat.h
Deleted
@@ -1,96 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __HAVE_XDEBUG_COMPAT_H__ -#define __HAVE_XDEBUG_COMPAT_H__ - -#include "php.h" -#include "str.h" - -#include "ext/standard/head.h" -#include "ext/standard/php_var.h" -#define xdebug_php_var_dump php_var_dump - -char *xdebug_str_to_str(char *haystack, size_t length, const char *needle, size_t needle_len, const char *str, size_t str_len, size_t *new_len); - -unsigned char *xdebug_base64_encode(unsigned char *data, size_t data_len, size_t *new_len); -unsigned char *xdebug_base64_decode(unsigned char *data, size_t data_len, size_t *new_len); - -zend_string *xdebug_addslashes(zend_string *str); -void xdebug_stripcslashes(char *string, int *new_len); - -zend_ulong xdebug_get_pid(void); - -void xdebug_setcookie(const char *name, int name_len, char *value, int value_len, time_t expires, const char *path, int path_len, const char *domain, int domain_len, int secure, int url_encode, int httponly); -char *xdebug_get_compiled_variable_name(zend_op_array *op_array, uint32_t var, int *cv_len); - -/* Recursion protection is done differently from PHP 7.3 onwards */ -zend_bool xdebug_zend_hash_is_recursive(HashTable* ht); -zend_bool xdebug_zend_hash_apply_protection_begin(HashTable* ht); -zend_bool xdebug_zend_hash_apply_protection_end(HashTable* ht); - -# define XDEBUG_MAKE_STD_ZVAL(zv) \ - zv = ecalloc(sizeof(zval), 1); - -# define HASH_KEY_SIZEOF(k) (sizeof(k) - 1) -# define HASH_KEY_STRLEN(k) (strlen(k)) -# define HASH_KEY_IS_NUMERIC(k) ((k) == NULL) -# define HASH_APPLY_KEY_VAL(k) (k)->val -# define HASH_APPLY_KEY_LEN(k) (k)->len + 1 - -# define STR_NAME_VAL(k) (k)->val -# define STR_NAME_LEN(k) (k)->len - -# if defined (__GNUC__) -# define XDEBUG_GNUC_CHECK_VERSION(major, minor) \ - ((__GNUC__ > (major)) || \ - ((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor)))) -# else -# define XDEBUG_GNUC_CHECK_VERSION(major, minor) 0 -# endif - -# if XDEBUG_GNUC_CHECK_VERSION(7, 0) -# define XDEBUG_BREAK_INTENTIONALLY_MISSING __attribute__ ((fallthrough)); -# else -# define XDEBUG_BREAK_INTENTIONALLY_MISSING -# endif - -# if XDEBUG_GNUC_CHECK_VERSION(2, 7) || __has_attribute(format) -# define XDEBUG_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first))) -# else -# define XDEBUG_ATTRIBUTE_FORMAT(type, idx, first) -# endif - -# if PHP_VERSION_ID >= 70300 -# define XDEBUG_ZEND_CONSTANT_MODULE_NUMBER(v) ZEND_CONSTANT_MODULE_NUMBER((v)) -# else -# define XDEBUG_ZEND_CONSTANT_MODULE_NUMBER(v) ((v)->module_number) -# endif - -# if PHP_VERSION_ID < 70400 -# define ZEND_COMPILE_EXTENDED_STMT ZEND_COMPILE_EXTENDED_INFO -# endif - -# if PHP_VERSION_ID < 80000 -# define ZEND_ARG_IS_VARIADIC(ptr) (*ptr).is_variadic -# define ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(a, b, c, d, e) ZEND_ARG_TYPE_INFO((a), b, (c), (d)) -# define IS_MIXED 0 -# endif - -#define XDEBUG_OPCODE_HANDLER_ARGS zend_execute_data *execute_data -#define XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU execute_data - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/file.c
Deleted
@@ -1,201 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "php_xdebug.h" -#include "lib_private.h" -#include "log.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -#include "file.h" - -void xdebug_file_init(xdebug_file *xf) -{ - xf->type = XDEBUG_FILE_TYPE_NULL; - xf->fp.normal = NULL; -#if HAVE_XDEBUG_ZLIB - xf->fp.gz = NULL; -#endif - xf->name = NULL; -} - -xdebug_file *xdebug_file_ctor(void) -{ - xdebug_file *tmp = xdmalloc(sizeof(xdebug_file)); - xdebug_file_init(tmp); - - return tmp; -} - -void xdebug_file_deinit(xdebug_file *xf) -{ - xf->type = XDEBUG_FILE_TYPE_NULL; - xf->fp.normal = NULL; -#if HAVE_XDEBUG_ZLIB - xf->fp.gz = NULL; -#endif - xdfree(xf->name); -} - -void xdebug_file_dtor(xdebug_file *xf) -{ - xdebug_file_deinit(xf); - xdfree(xf); -} - -int xdebug_file_open(xdebug_file *file, const char *filename, const char *extension, const char *mode) -{ - if (XINI_LIB(use_compression)) { -#ifdef HAVE_XDEBUG_ZLIB - FILE *tmp_file; - char *combined_extension; - - /* Can't use profiler append with compression */ - if (strcmp(mode, "a") == 0) { - xdebug_log_ex( - XLOG_CHAN_CONFIG, XLOG_WARN, "ZLIB-A", - "Cannot append to profiling file while file compression is turned on. Falling back to creating an uncompressed file" - ); - goto uncompressed; - } - - combined_extension = extension ? xdebug_sprintf("%s.gz", extension) : xdstrdup("gz"); - tmp_file = xdebug_fopen((char*) filename, mode, combined_extension, &(file->name)); - xdfree(combined_extension); - - if (!tmp_file) { - return 0; - } - - file->type = XDEBUG_FILE_TYPE_GZ; - file->fp.normal = tmp_file; - file->fp.gz = gzdopen(fileno(tmp_file), mode); - - if (!file->fp.gz) { - fclose(tmp_file); - return 0; - } - - return 1; -#else - char *combined_extension; - - combined_extension = extension ? xdebug_sprintf("%s.gz", extension) : xdstrdup("gz"); - xdebug_log_ex( - XLOG_CHAN_CONFIG, XLOG_WARN, "NOZLIB", - "Cannot create the compressed file '%s.%s', because support for zlib has not been compiled in. Falling back to '%s%s%s'", - filename, combined_extension, - filename, extension ? "." : "", extension ? extension : "" - ); - xdfree(combined_extension); -#endif - } - -#ifdef HAVE_XDEBUG_ZLIB -uncompressed: -#endif - file->type = XDEBUG_FILE_TYPE_NORMAL; - file->fp.normal = xdebug_fopen((char*) filename, mode, extension, &(file->name)); - - if (!file->fp.normal) { - return 0; - } - - return 1; -} - -int XDEBUG_ATTRIBUTE_FORMAT(printf, 2, 3) xdebug_file_printf(xdebug_file *file, const char *fmt, ...) -{ - va_list argv; - - switch (file->type) { - case XDEBUG_FILE_TYPE_NORMAL: - va_start(argv, fmt); - vfprintf(file->fp.normal, fmt, argv); - va_end(argv); - break; -#if HAVE_XDEBUG_ZLIB - case XDEBUG_FILE_TYPE_GZ: { - xdebug_str formatted_string = XDEBUG_STR_INITIALIZER; - - va_start(argv, fmt); - xdebug_str_add_va_fmt(&formatted_string, fmt, argv); - va_end(argv); - - gzwrite(file->fp.gz, formatted_string.d, formatted_string.l); - - xdebug_str_destroy(&formatted_string); - break; - } -#endif - default: - xdebug_log_ex(XLOG_CHAN_BASE, XLOG_CRIT, "FTYPE", "Unknown file type used with '%s'", file->name); - return 0; - } - - return 1; -} - -int xdebug_file_flush(xdebug_file *file) -{ - switch (file->type) { - case XDEBUG_FILE_TYPE_NORMAL: - return fflush(file->fp.normal); -#if HAVE_XDEBUG_ZLIB - case XDEBUG_FILE_TYPE_GZ: - return gzflush(file->fp.gz, Z_FULL_FLUSH); -#endif - default: - xdebug_log_ex(XLOG_CHAN_BASE, XLOG_CRIT, "FTYPE", "Unknown file type used with '%s'", file->name); - return EOF; - } -} - -int xdebug_file_close(xdebug_file *file) -{ - switch (file->type) { - case XDEBUG_FILE_TYPE_NORMAL: - return fclose(file->fp.normal); -#if HAVE_XDEBUG_ZLIB - case XDEBUG_FILE_TYPE_GZ: { - int gzret; - - gzret = gzclose(file->fp.gz); - fclose(file->fp.normal); - - return gzret; - } -#endif - default: - xdebug_log_ex(XLOG_CHAN_BASE, XLOG_CRIT, "FTYPE", "Unknown file type used with '%s'", file->name); - return EOF; - } -} - -size_t xdebug_file_write(const void *ptr, size_t size, size_t nmemb, xdebug_file *file) -{ - switch (file->type) { - case XDEBUG_FILE_TYPE_NORMAL: - return fwrite(ptr, size, nmemb, file->fp.normal); -#if HAVE_XDEBUG_ZLIB - case XDEBUG_FILE_TYPE_GZ: - return gzfwrite(ptr, size, nmemb, file->fp.gz); -#endif - default: - xdebug_log_ex(XLOG_CHAN_BASE, XLOG_CRIT, "FTYPE", "Unknown file type used with '%s'", file->name); - return EOF; - } -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/lib.c
Deleted
@@ -1,769 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2022 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "php_xdebug.h" - -#include "headers.h" - -#include "lib_private.h" -#include "log.h" - -extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); - -void xdebug_init_library_globals(xdebug_library_globals_t *xg) -{ - xg->headers = NULL; - xg->mode = 0xFFFFFFFF; - xg->mode_from_environment = 0; - - xg->log_file = 0; - - xg->active_execute_data = NULL; - xg->opcode_handlers_set = xdebug_set_create(256); - memset(xg->original_opcode_handlers, 0, sizeof(xg->original_opcode_handlers)); - memset(xg->opcode_multi_handlers, 0, sizeof(xg->opcode_multi_handlers)); - - XINI_LIB(log_level) = 0; - xg->diagnosis_buffer = NULL; -} - - -void xdebug_library_zend_startup(void) -{ - xdebug_lib_zend_startup_overload_sapi_headers(); -} - -void xdebug_library_zend_shutdown(void) -{ - xdebug_lib_zend_shutdown_restore_sapi_headers(); -} - - -void xdebug_library_minit(void) -{ - xdebug_set_opcode_multi_handler(ZEND_ASSIGN); - xdebug_set_opcode_multi_handler(ZEND_ASSIGN_DIM); - xdebug_set_opcode_multi_handler(ZEND_ASSIGN_OBJ); -#if PHP_VERSION_ID >= 70400 - xdebug_set_opcode_multi_handler(ZEND_ASSIGN_STATIC_PROP); -#endif - xdebug_set_opcode_multi_handler(ZEND_QM_ASSIGN); - xdebug_set_opcode_multi_handler(ZEND_INCLUDE_OR_EVAL); -} - -static void xdebug_multi_opcode_handler_dtor(xdebug_multi_opcode_handler_t *ptr) -{ - if (ptr->next) { - xdebug_multi_opcode_handler_dtor(ptr->next); - } - xdfree(ptr); -} - -void xdebug_library_mshutdown(void) -{ - int i; - - /* Restore all opcode handlers that we have set */ - for (i = 0; i < 256; i++) { - if (XG_LIB(opcode_multi_handlers)i != NULL) { - xdebug_multi_opcode_handler_dtor(XG_LIB(opcode_multi_handlers)i); - } - xdebug_unset_opcode_handler(i); - } - - xdebug_set_free(XG_LIB(opcode_handlers_set)); -} - -void xdebug_library_rinit(void) -{ - XG_LIB(diagnosis_buffer) = xdebug_str_new(); - xdebug_open_log(); - - XG_LIB(headers) = xdebug_llist_alloc(xdebug_llist_string_dtor); - - XG_LIB(dumped) = 0; - XG_LIB(do_collect_errors) = 0; -} - -void xdebug_library_post_deactivate(void) -{ - /* Clean up collected headers */ - xdebug_llist_destroy(XG_LIB(headers), NULL); - XG_LIB(headers) = NULL; - - - xdebug_close_log(); - xdebug_str_free(XG_LIB(diagnosis_buffer)); -} - - -void xdebug_disable_opcache_optimizer(void) -{ - zend_string *key = zend_string_init(ZEND_STRL("opcache.optimization_level"), 1); - zend_string *value = zend_string_init(ZEND_STRL("0"), 1); - - zend_alter_ini_entry(key, value, ZEND_INI_SYSTEM, ZEND_INI_STAGE_STARTUP); - - zend_string_release(key); - zend_string_release(value); -} - - -static int xdebug_lib_set_mode_item(char *mode, int len) -{ - if (strncmp(mode, "off", len) == 0) { - XG_LIB(mode) |= XDEBUG_MODE_OFF; - return 1; - } - if (strncmp(mode, "develop", len) == 0) { - XG_LIB(mode) |= XDEBUG_MODE_DEVELOP; - return 1; - } - if (strncmp(mode, "coverage", len) == 0) { - XG_LIB(mode) |= XDEBUG_MODE_COVERAGE; - return 1; - } - if (strncmp(mode, "debug", len) == 0) { - XG_LIB(mode) |= XDEBUG_MODE_STEP_DEBUG; - return 1; - } - if (strncmp(mode, "gcstats", len) == 0) { - XG_LIB(mode) |= XDEBUG_MODE_GCSTATS; - return 1; - } - if (strncmp(mode, "profile", len) == 0) { - XG_LIB(mode) |= XDEBUG_MODE_PROFILING; - return 1; - } - if (strncmp(mode, "trace", len) == 0) { - XG_LIB(mode) |= XDEBUG_MODE_TRACING; - return 1; - } - - return 0; -} - -static int xdebug_lib_set_mode_from_setting(char *mode) -{ - char *mode_ptr = mode; - char *comma = NULL; - int errors = 0; - - XG_LIB(mode) = 0; - - comma = strchr(mode_ptr, ','); - while (comma) { - errors += !xdebug_lib_set_mode_item(mode_ptr, comma - mode_ptr); - mode_ptr = comma + 1; - while (*mode_ptr == ' ') { - mode_ptr++; - } - comma = strchr(mode_ptr, ','); - } - errors += !xdebug_lib_set_mode_item(mode_ptr, strlen(mode_ptr)); - - return !errors; -} - -int xdebug_lib_set_mode(char *mode) -{ - char *config = getenv("XDEBUG_MODE"); - int result = 0; - - /* XDEBUG_MODE environment variable */ - if (config && strlen(config)) { - result = xdebug_lib_set_mode_from_setting(config); - - if (!result) { - xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_CRIT, "ENVMODE", "Invalid mode '%s' set for 'XDEBUG_MODE' environment variable, fall back to 'xdebug.mode' configuration setting", config); - } else { - XG_LIB(mode_from_environment) = 1; - return result; - } - } - - /* 'xdebug.mode' configuration setting */ - result = xdebug_lib_set_mode_from_setting(mode); - - if (!result) { - xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_CRIT, "MODE", "Invalid mode '%s' set for 'xdebug.mode' configuration setting", mode); - } - - return result; -} - -int xdebug_lib_get_start_with_request(void) -{ - return XG_LIB(start_with_request); -} - -int xdebug_lib_set_start_with_request(char *value) -{ - if (strcmp(value, "default") == 0) { - XG_LIB(start_with_request) = XDEBUG_START_WITH_REQUEST_DEFAULT; - return 1; - } - if (strcmp(value, "yes") == 0 || strcmp(value, "1") == 0) { - XG_LIB(start_with_request) = XDEBUG_START_WITH_REQUEST_YES; - return 1; - } - if (strcmp(value, "no") == 0 || value0 == '\0') { - XG_LIB(start_with_request) = XDEBUG_START_WITH_REQUEST_NO; - return 1; - } - if (strcmp(value, "trigger") == 0) { - XG_LIB(start_with_request) = XDEBUG_START_WITH_REQUEST_TRIGGER; - return 1; - } - - return 0; -} - -int xdebug_lib_start_with_request(int for_mode) -{ - if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_YES) { - return 1; - } - - if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_DEFAULT) { - if (for_mode == XDEBUG_MODE_PROFILING && XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - return 1; - } - } - - return 0; -} - -int xdebug_lib_never_start_with_request(void) -{ - if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_NO) { - return 1; - } - - return 0; -} - - -int xdebug_lib_get_start_upon_error(void) -{ - return XG_LIB(start_upon_error); -} - -int xdebug_lib_set_start_upon_error(char *value) -{ - if (strcmp(value, "default") == 0) { - XG_LIB(start_upon_error) = XDEBUG_START_UPON_ERROR_DEFAULT; - return 1; - } - if (strcmp(value, "yes") == 0 || strcmp(value, "1") == 0) { - XG_LIB(start_upon_error) = XDEBUG_START_UPON_ERROR_YES; - return 1; - } - if (strcmp(value, "no") == 0 || value0 == '\0') { - XG_LIB(start_upon_error) = XDEBUG_START_UPON_ERROR_NO; - return 1; - } - - return 0; -} - -int xdebug_lib_start_upon_error(void) -{ - if (XG_LIB(start_upon_error) == XDEBUG_START_UPON_ERROR_YES) { - return 1; - } - - return 0; -} - -const char *xdebug_lib_mode_from_value(int mode) -{ - switch (mode) { - case XDEBUG_MODE_DEVELOP: - return "develop"; - case XDEBUG_MODE_COVERAGE: - return "coverage"; - case XDEBUG_MODE_STEP_DEBUG: - return "debug"; - case XDEBUG_MODE_GCSTATS: - return "gcstats"; - case XDEBUG_MODE_PROFILING: - return "profile"; - case XDEBUG_MODE_TRACING: - return "trace"; - default: - return "?"; - } -} - -static const char *find_in_globals(const char *element) -{ - zval *trigger_val = NULL; - const char *env_value = getenv(element); - - if (env_value) { - return env_value; - } - - if ( - ( - (trigger_val = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_ENV), element, strlen(element))) != NULL - ) || ( - (trigger_val = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_GET), element, strlen(element))) != NULL - ) || ( - (trigger_val = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_POST), element, strlen(element))) != NULL - ) || ( - (trigger_val = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_COOKIE), element, strlen(element))) != NULL - ) - ) { - return Z_STRVAL_P(trigger_val); - } - - return NULL; -} - -int xdebug_lib_has_shared_secret(void) -{ - char *shared_secret = XINI_LIB(trigger_value); - - if (shared_secret != NULL && shared_secret0 != '\0') { - return 1; - } - - return 0; -} - -static int does_shared_secret_match_single(int mode, const char *trimmed_trigger_value, const char *trimmed_shared_secret, char **found_trigger_value) -{ - if (strcmp(trimmed_shared_secret, trimmed_trigger_value) == 0) { - xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_DEBUG, "TRGSEC-MATCH", "The trigger value '%s' matched the shared secret '%s' for mode '%s'", trimmed_trigger_value, trimmed_shared_secret, xdebug_lib_mode_from_value(mode)); - - if (found_trigger_value != NULL) { - *found_trigger_value = xdstrdup(trimmed_trigger_value); - } - - return 1; - } - - return 0; -} - -static int does_shared_secret_match(int mode, const char *trigger_name, const char *trigger_value, char **found_trigger_value) -{ - int retval = 0; - const char *shared_secret = XINI_LIB(trigger_value); - char *trimmed_trigger_value = xdebug_trim(trigger_value); - - /* Check we have a multi-value-shared secret setting */ - if (strchr(shared_secret, ',') != NULL) { - int i; - xdebug_arg *values = xdebug_arg_ctor(); - - xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_DEBUG, "TRGSEC-MULT", "The shared secret (xdebug.trigger_value) is multi-value for mode '%s'", xdebug_lib_mode_from_value(mode)); - - xdebug_explode(",", shared_secret, values, -1); - - for (i = 0; i < values->c; i++) { - char *trimmed_shared_secret = xdebug_trim(values->argsi); - - retval = does_shared_secret_match_single(mode, trimmed_trigger_value, trimmed_shared_secret, found_trigger_value); - - xdfree(trimmed_shared_secret); - - /* Jump out of the loop if we found a match */ - if (retval != 0) { - break; - } - } - - xdebug_arg_dtor(values); - - if (retval == 0) { - xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "TRGSEC-MNO", "The trigger value '%s', as set through '%s', did not match any of the shared secrets (xdebug.trigger_value) for mode '%s'", trimmed_trigger_value, trigger_name, xdebug_lib_mode_from_value(mode)); - } - } else { - char *trimmed_shared_secret = xdebug_trim(shared_secret); - - retval = does_shared_secret_match_single(mode, trimmed_trigger_value, trimmed_shared_secret, found_trigger_value); - - xdfree(trimmed_shared_secret); - - if (retval == 0) { - xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "TRGSEC-NO", "The trigger value '%s', as set through '%s', did not match the shared secret (xdebug.trigger_value) for mode '%s'", trimmed_trigger_value, trigger_name, xdebug_lib_mode_from_value(mode)); - } - } - - xdfree(trimmed_trigger_value); - - return retval; -} - -static int trigger_enabled(int for_mode, char **found_trigger_value) -{ - const char *trigger_value = NULL; - const char *trigger_name = "XDEBUG_TRIGGER"; - - xdebug_log(XLOG_CHAN_CONFIG, XLOG_DEBUG, "Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode '%s'", xdebug_lib_mode_from_value(for_mode)); - - /* First we check for the generic 'XDEBUG_TRIGGER' option */ - trigger_value = find_in_globals(trigger_name); - - /* If not found, we fall back to the per-mode name for backwards compatibility reasons */ - if (!trigger_value) { - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING) && (for_mode == XDEBUG_MODE_PROFILING)) { - trigger_name = "XDEBUG_PROFILE"; - } else if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) && (for_mode == XDEBUG_MODE_TRACING)) { - trigger_name = "XDEBUG_TRACE"; - } else if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG) && (for_mode == XDEBUG_MODE_STEP_DEBUG)) { - trigger_name = "XDEBUG_SESSION"; - } - - if (trigger_name) { - xdebug_log(XLOG_CHAN_CONFIG, XLOG_INFO, "Trigger value for 'XDEBUG_TRIGGER' not found, falling back to '%s'", trigger_name); - trigger_value = find_in_globals(trigger_name); - } - } - - if (!trigger_value) { - xdebug_log(XLOG_CHAN_CONFIG, XLOG_INFO, "Trigger value for '%s' not found, so not activating", trigger_name); - - if (found_trigger_value != NULL) { - *found_trigger_value = NULL; - } - return 0; - } - - /* If there is no configured shared secret trigger, always trigger */ - if (!xdebug_lib_has_shared_secret()) { - xdebug_log(XLOG_CHAN_CONFIG, XLOG_INFO, "No shared secret: Activating"); - if (found_trigger_value != NULL) { - *found_trigger_value = xdstrdup(trigger_value); - } - return 1; - } - - /* Check if the configured trigger value matches the one found in the - * trigger element */ - if (does_shared_secret_match(for_mode, trigger_name, trigger_value, found_trigger_value)) { - return 1; - } - - return 0; -} - -static int is_mode_trigger_and_enabled(int for_mode, int force_trigger, char **found_trigger_value) -{ - if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_TRIGGER) { - return force_trigger || trigger_enabled(for_mode, found_trigger_value); - } - - if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_DEFAULT) { - if ( - XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG) || - XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) - ) { - return force_trigger || trigger_enabled(for_mode, found_trigger_value); - } - } - - return 0; -} - -/* Returns 1 if the mode is 'trigger', or 'default', where the default mode for - * a feature is to trigger, and the trigger is present. If found_trigger_value - * is not NULL, then it is set to the found trigger value */ -int xdebug_lib_start_with_trigger(int for_mode, char **found_trigger_value) -{ - return is_mode_trigger_and_enabled(for_mode, 0, found_trigger_value); -} - -/* Returns 1 if the mode is 'trigger', or 'default', where the default mode for - * a feature is to trigger. Does not check whether a trigger is present. */ -int xdebug_lib_start_if_mode_is_trigger(int for_mode) -{ - return is_mode_trigger_and_enabled(for_mode, 1, NULL); -} - - -function_stack_entry *xdebug_get_stack_frame(int nr) -{ - if (!XG_BASE(stack)) { - return NULL; - } - if (nr < 0 || nr >= XDEBUG_VECTOR_COUNT(XG_BASE(stack))) { - return NULL; - } - - return xdebug_vector_element_get(XG_BASE(stack), XDEBUG_VECTOR_COUNT(XG_BASE(stack)) - nr - 1); -} - -static void xdebug_used_var_hash_from_llist_dtor(void *data) -{ - xdebug_str *var_name = (xdebug_str*) data; - - xdebug_str_free(var_name); -} - -static int xdebug_compare_le_xdebug_str(const void *le1, const void *le2) -{ - return strcmp( - ((xdebug_str *) XDEBUG_LLIST_VALP(*(xdebug_llist_element **) le1))->d, - ((xdebug_str *) XDEBUG_LLIST_VALP(*(xdebug_llist_element **) le2))->d - ); -} - -xdebug_hash* xdebug_declared_var_hash_from_llist(xdebug_llist *list) -{ - xdebug_hash *tmp; - xdebug_llist_element *le; - xdebug_str *var_name; - - tmp = xdebug_hash_alloc_with_sort(32, xdebug_used_var_hash_from_llist_dtor, xdebug_compare_le_xdebug_str); - for (le = XDEBUG_LLIST_HEAD(list); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { - var_name = (xdebug_str*) XDEBUG_LLIST_VALP(le); - xdebug_hash_add(tmp, var_name->d, var_name->l, xdebug_str_copy(var_name)); - } - - return tmp; -} - -void xdebug_lib_set_active_data(zend_execute_data *execute_data) -{ - XG_LIB(active_execute_data) = execute_data; - XG_LIB(active_object) = execute_data ? &execute_data->This : NULL; -} - -void xdebug_lib_set_active_stack_entry(function_stack_entry *fse) -{ - XG_LIB(active_stack_entry) = fse; -} - -void xdebug_lib_set_active_symbol_table(HashTable *symbol_table) -{ - XG_LIB(active_symbol_table) = symbol_table; -} - -int xdebug_lib_has_active_data(void) -{ - return !!XG_LIB(active_execute_data); -} - -int xdebug_lib_has_active_function(void) -{ - return !!XG_LIB(active_execute_data)->func; -} - -int xdebug_lib_has_active_object(void) -{ - return !!XG_LIB(active_object); -} - -int xdebug_lib_has_active_symbol_table(void) -{ - return !!XG_LIB(active_symbol_table); -} - -zend_execute_data *xdebug_lib_get_active_data(void) -{ - return XG_LIB(active_execute_data); -} - -zend_op_array *xdebug_lib_get_active_func_oparray(void) -{ - return &XG_LIB(active_execute_data)->func->op_array; -} - -function_stack_entry *xdebug_lib_get_active_stack_entry(void) -{ - return XG_LIB(active_stack_entry); -} - -HashTable *xdebug_lib_get_active_symbol_table(void) -{ - return XG_LIB(active_symbol_table); -} - -zval *xdebug_lib_get_active_object(void) -{ - return XG_LIB(active_object); -} - -int xdebug_isset_opcode_handler(int opcode) -{ - return xdebug_set_in(XG_LIB(opcode_handlers_set), opcode); -} - -void xdebug_set_opcode_handler(int opcode, user_opcode_handler_t handler) -{ - if (xdebug_isset_opcode_handler(opcode)) { - abort(); - } - XG_LIB(original_opcode_handlersopcode) = zend_get_user_opcode_handler(opcode); - xdebug_set_add(XG_LIB(opcode_handlers_set), opcode); - zend_set_user_opcode_handler(opcode, handler); -} - -static int xdebug_opcode_multi_handler(zend_execute_data *execute_data) -{ - const zend_op *cur_opcode = execute_data->opline; - - xdebug_multi_opcode_handler_t *handler_ptr = XG_LIB(opcode_multi_handlerscur_opcode->opcode); - - while (handler_ptr) { - handler_ptr->handler(execute_data); - handler_ptr = handler_ptr->next; - } - - return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); -} - -void xdebug_set_opcode_multi_handler(int opcode) -{ - if (xdebug_isset_opcode_handler(opcode)) { - abort(); - } - XG_LIB(original_opcode_handlersopcode) = zend_get_user_opcode_handler(opcode); - xdebug_set_add(XG_LIB(opcode_handlers_set), opcode); - zend_set_user_opcode_handler(opcode, xdebug_opcode_multi_handler); -} - -void xdebug_register_with_opcode_multi_handler(int opcode, user_opcode_handler_t handler) -{ - xdebug_multi_opcode_handler_t *ptr; - xdebug_multi_opcode_handler_t *tmp = xdmalloc(sizeof(xdebug_multi_opcode_handler_t)); - tmp->handler = handler; - tmp->next = NULL; - - if (!xdebug_isset_opcode_handler(opcode)) { - abort(); - } - - if (XG_LIB(opcode_multi_handlers)opcode == NULL) { - XG_LIB(opcode_multi_handlers)opcode = tmp; - return; - } - - ptr = XG_LIB(opcode_multi_handlers)opcode; - while (ptr->next) { - ptr = ptr->next; - } - - ptr->next = tmp; -} - -void xdebug_unset_opcode_handler(int opcode) -{ - if (xdebug_set_in(XG_LIB(opcode_handlers_set), opcode)) { - zend_set_user_opcode_handler(opcode, XG_LIB(original_opcode_handlersopcode)); - } -} - -int xdebug_call_original_opcode_handler_if_set(int opcode, XDEBUG_OPCODE_HANDLER_ARGS) -{ - if (xdebug_isset_opcode_handler(opcode)) { - user_opcode_handler_t handler = XG_LIB(original_opcode_handlersopcode); - - if (handler) { - return handler(XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); - } - } - - return ZEND_USER_OPCODE_DISPATCH; -} - -/* Does not duplicate the return value, don't free. Return NULL if it's - * not-set, or an empty string */ -char *xdebug_lib_get_output_dir(void) -{ - char *output_dir = XINI_LIB(output_dir); - - if (output_dir == NULL || output_dir0 == '\0') { - return NULL; - } - - return output_dir; -} - -void xdebug_llist_string_dtor(void *dummy, void *elem) -{ - char *s = elem; - - if (s) { - xdfree(s); - } -} - -char* xdebug_wrap_location_around_function_name(const char *prefix, zend_op_array *opa, char *fname) -{ - return xdebug_sprintf( - "%s{%s:%s:%d-%d}", - fname, - prefix, - opa->filename->val, - opa->line_start, - opa->line_end - ); -} - -char* xdebug_wrap_closure_location_around_function_name(zend_op_array *opa, char *fname) -{ - xdebug_str tmp = XDEBUG_STR_INITIALIZER; - char *tmp_loc_info; - - if (fnamestrlen(fname) - 1 != '}') { - xdebug_str_add(&tmp, fname, 0); - - return tmp.d; - } - - xdebug_str_addl(&tmp, fname, strlen(fname) - 1, 0); - - tmp_loc_info = xdebug_sprintf( - ":%s:%d-%d}", - opa->filename->val, - opa->line_start, - opa->line_end - ); - xdebug_str_add(&tmp, tmp_loc_info, 1); - - return tmp.d; -} - -static void xdebug_declared_var_dtor(void *dummy, void *elem) -{ - xdebug_str *s = (xdebug_str*) elem; - - xdebug_str_free(s); -} - -void xdebug_lib_register_compiled_variables(function_stack_entry *fse, zend_op_array *op_array) -{ - unsigned int i = 0; - - if (!fse->declared_vars) { - fse->declared_vars = xdebug_llist_alloc(xdebug_declared_var_dtor); - } - - if (!op_array->vars) { - return; - } - - /* gather used variables from compiled vars information */ - while (i < (unsigned int) op_array->last_var) { - xdebug_llist_insert_next(fse->declared_vars, XDEBUG_LLIST_TAIL(fse->declared_vars), xdebug_str_create(STR_NAME_VAL(op_array->varsi), STR_NAME_LEN(op_array->varsi))); - i++; - } -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/lib.h
Deleted
@@ -1,322 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __XDEBUG_LIBRARY_H__ -#define __XDEBUG_LIBRARY_H__ - -#ifdef ZTS -# include "TSRM.h" -#endif - -#include "zend.h" -#include "zend_API.h" -#include "compat.h" - -typedef struct xdebug_var_name { - zend_string *name; - zval data; - int is_variadic; -} xdebug_var_name; - -#define XFUNC_UNKNOWN 0x00 -#define XFUNC_NORMAL 0x01 -#define XFUNC_STATIC_MEMBER 0x02 -#define XFUNC_MEMBER 0x03 - -#define XFUNC_INCLUDES 0x10 -#define XFUNC_EVAL 0x10 -#define XFUNC_INCLUDE 0x11 -#define XFUNC_INCLUDE_ONCE 0x12 -#define XFUNC_REQUIRE 0x13 -#define XFUNC_REQUIRE_ONCE 0x14 -#define XFUNC_MAIN 0x15 -#if PHP_VERSION_ID >= 80100 -# define XFUNC_FIBER 0x16 -#endif - -#define XFUNC_ZEND_PASS 0x20 - -#define XDEBUG_IS_NORMAL_FUNCTION(f) ((f)->type == XFUNC_NORMAL || (f)->type == XFUNC_STATIC_MEMBER || (f)->type == XFUNC_MEMBER) - -#define XDEBUG_REGISTER_LONG_CONSTANT(__c) REGISTER_LONG_CONSTANT(#__c, __c, CONST_CS|CONST_PERSISTENT) - -#define XDEBUG_NONE 0 -#define XDEBUG_JIT 1 -#define XDEBUG_REQ 2 - -#define XDEBUG_BREAK 1 -#define XDEBUG_STEP 2 - -#define XDEBUG_BUILT_IN 0 -#define XDEBUG_USER_DEFINED 1 - -#define XDEBUG_MAX_FUNCTION_LEN 1024 - -#define XDEBUG_TRACE_OPTION_APPEND 1 -#define XDEBUG_TRACE_OPTION_COMPUTERIZED 2 -#define XDEBUG_TRACE_OPTION_HTML 4 -#define XDEBUG_TRACE_OPTION_NAKED_FILENAME 8 - -#define XDEBUG_CC_OPTION_UNUSED 1 -#define XDEBUG_CC_OPTION_DEAD_CODE 2 -#define XDEBUG_CC_OPTION_BRANCH_CHECK 4 - -#define STATUS_STARTING 0 -#define STATUS_STOPPING 1 -#define STATUS_STOPPED 2 -#define STATUS_RUNNING 3 -#define STATUS_BREAK 4 - -#define REASON_OK 0 -#define REASON_ERROR 1 -#define REASON_ABORTED 2 -#define REASON_EXCEPTION 3 - -#define XDEBUG_CMDLOOP_NONBLOCK 0 -#define XDEBUG_CMDLOOP_BLOCK 1 - -#define XDEBUG_CMDLOOP_NONBAIL 0 -#define XDEBUG_CMDLOOP_BAIL 1 - -#define XDEBUG_ERROR_OK 0 -#define XDEBUG_ERROR_PARSE 1 -#define XDEBUG_ERROR_DUP_ARG 2 -#define XDEBUG_ERROR_INVALID_ARGS 3 -#define XDEBUG_ERROR_UNIMPLEMENTED 4 -#define XDEBUG_ERROR_COMMAND_UNAVAILABLE 5 - -#define XDEBUG_ERROR_CANT_OPEN_FILE 100 -#define XDEBUG_ERROR_STREAM_REDIRECT_FAILED 101 /* unused */ - -#define XDEBUG_ERROR_BREAKPOINT_NOT_SET 200 -#define XDEBUG_ERROR_BREAKPOINT_TYPE_NOT_SUPPORTED 201 -#define XDEBUG_ERROR_BREAKPOINT_INVALID 202 -#define XDEBUG_ERROR_BREAKPOINT_NO_CODE 203 -#define XDEBUG_ERROR_BREAKPOINT_INVALID_STATE 204 -#define XDEBUG_ERROR_NO_SUCH_BREAKPOINT 205 -#define XDEBUG_ERROR_EVALUATING_CODE 206 -#define XDEBUG_ERROR_INVALID_EXPRESSION 207 /* unused */ - -#define XDEBUG_ERROR_PROPERTY_NON_EXISTENT 300 -#define XDEBUG_ERROR_PROPERTY_NON_EXISTANT 300 /* compatibility typo */ -#define XDEBUG_ERROR_STACK_DEPTH_INVALID 301 -#define XDEBUG_ERROR_CONTEXT_INVALID 302 /* unused */ - -#define XDEBUG_ERROR_PROFILING_NOT_STARTED 800 - -#define XDEBUG_ERROR_ENCODING_NOT_SUPPORTED 900 - -typedef struct _xdebug_func { - zend_string *object_class; - zend_string *scope_class; - char *function; - int type; - int internal; -} xdebug_func; - -typedef struct xdebug_profile { - uint64_t nanotime; - uint64_t nanotime_mark; - long memory; - long mem_mark; - xdebug_llist *call_list; -} xdebug_profile; - -typedef struct _function_stack_entry { - /* function properties */ - xdebug_func function; - unsigned int function_nr; - unsigned short user_defined:1; - unsigned short level:15; - - /* argument properties */ - unsigned short varc; - xdebug_var_name *var; - zval *return_value; - xdebug_llist *declared_vars; - HashTable *symbol_table; - zend_execute_data *execute_data; - unsigned char is_variadic; - unsigned char arg_done; - - /* filter properties */ - unsigned char filtered_code_coverage; - unsigned char filtered_stack; - unsigned char filtered_tracing; - - /* location properties */ - int lineno; - zend_string *filename; - zend_string *include_filename; - - /* tracing properties */ - signed long memory; - signed long prev_memory; - uint64_t nanotime; - - /* profiling properties */ - xdebug_profile profile; - struct { - int lineno; - zend_string *filename; - char *funcname; - } profiler; - - /* misc properties */ - zend_op_array *op_array; -} function_stack_entry; - -function_stack_entry *xdebug_get_stack_frame(int nr); - - -xdebug_hash* xdebug_declared_var_hash_from_llist(xdebug_llist *list); -int xdebug_trigger_enabled(int setting, const char *var_name, char *var_value); - -typedef struct _xdebug_multi_opcode_handler_t xdebug_multi_opcode_handler_t; - -struct _xdebug_multi_opcode_handler_t -{ - user_opcode_handler_t handler; - xdebug_multi_opcode_handler_t *next; -}; - -typedef struct _xdebug_library_globals_t { - int mode; - int start_with_request; /* One of the XDEBUG_START_WITH_REQUEST_* constants */ - int start_upon_error; /* One of the XDEBUG_START_UPON_ERROR_* constants */ - int mode_from_environment; /* Keeps track whether the mode was set with XDEBUG_MODE for diagnostics purposes */ - - zend_execute_data *active_execute_data; - function_stack_entry *active_stack_entry; - HashTable *active_symbol_table; - zval *active_object; - - /* Headers */ - xdebug_llist *headers; - - zend_bool dumped; - - /* used for collection errors */ - zend_bool do_collect_errors; - - FILE *log_file; /* File handler for protocol log */ - zend_bool log_opened_message_sent; - char *log_open_timestring; - xdebug_str *diagnosis_buffer; - - user_opcode_handler_t original_opcode_handlers256; - xdebug_multi_opcode_handler_t *opcode_multi_handlers256; - xdebug_set *opcode_handlers_set; -} xdebug_library_globals_t; - -typedef struct _xdebug_library_settings_t { - char *output_dir; - char *trigger_value; - - char *file_link_format; - char *filename_format; - - /* Whether to use zlib compression for profiling and trace files, if ZLIB support - * is enabled */ - zend_bool use_compression; - - /* variable dumping limitation settings */ - zend_long display_max_children; - zend_long display_max_data; - zend_long display_max_depth; - - /* Logging settings */ - char *log; /* Filename to log protocol communication to */ - zend_long log_level; /* Log level XDEBUG_LOG_{ERR,WARN,INFO,DEBUG} */ -} xdebug_library_settings_t; - -void xdebug_init_library_globals(xdebug_library_globals_t *xg); - -void xdebug_library_zend_startup(void); -void xdebug_library_zend_shutdown(void); -void xdebug_library_minit(void); -void xdebug_library_mshutdown(void); -void xdebug_library_rinit(void); -void xdebug_library_post_deactivate(void); - -void xdebug_disable_opcache_optimizer(void); - -#define XDEBUG_MODE_OFF 0 -#define XDEBUG_MODE_DEVELOP 1<<0 -#define XDEBUG_MODE_COVERAGE 1<<1 -#define XDEBUG_MODE_STEP_DEBUG 1<<2 -#define XDEBUG_MODE_GCSTATS 1<<3 -#define XDEBUG_MODE_PROFILING 1<<4 -#define XDEBUG_MODE_TRACING 1<<5 -int xdebug_lib_set_mode(char *mode); - -#define XDEBUG_MODE_IS_OFF() ((XG(globals.library.mode) == XDEBUG_MODE_OFF)) -#define XDEBUG_MODE_IS(v) ((XG(globals.library.mode) & (v)) ? 1 : 0) -#define RETURN_IF_MODE_IS_NOT(m) if (!XDEBUG_MODE_IS((m))) { return; } -#define RETURN_FALSE_IF_MODE_IS_NOT(m) if (!XDEBUG_MODE_IS((m))) { RETURN_FALSE; } -#define WARN_AND_RETURN_IF_MODE_IS_NOT(m) if (!XDEBUG_MODE_IS((m))) { php_error(E_NOTICE, "Functionality is not enabled"); return; } - -#define XDEBUG_START_WITH_REQUEST_DEFAULT 1 -#define XDEBUG_START_WITH_REQUEST_YES 2 -#define XDEBUG_START_WITH_REQUEST_NO 3 -#define XDEBUG_START_WITH_REQUEST_TRIGGER 4 -int xdebug_lib_set_start_with_request(char *value); -int xdebug_lib_start_with_request(int for_mode); -int xdebug_lib_start_with_trigger(int for_mode, char **found_trigger_value); -int xdebug_lib_start_if_mode_is_trigger(int for_mode); -int xdebug_lib_never_start_with_request(void); -int xdebug_lib_get_start_with_request(void); -int xdebug_lib_has_shared_secret(void); - -#define XDEBUG_START_UPON_ERROR_DEFAULT 1 -#define XDEBUG_START_UPON_ERROR_YES 2 -#define XDEBUG_START_UPON_ERROR_NO 3 -int xdebug_lib_set_start_upon_error(char *value); -int xdebug_lib_start_upon_error(void); -int xdebug_lib_get_start_upon_error(void); - -const char *xdebug_lib_mode_from_value(int mode); - -void xdebug_lib_set_active_data(zend_execute_data *execute_data); -void xdebug_lib_set_active_stack_entry(function_stack_entry *fse); -void xdebug_lib_set_active_symbol_table(HashTable *symbol_table); - -int xdebug_lib_has_active_data(void); -int xdebug_lib_has_active_function(void); -int xdebug_lib_has_active_object(void); -int xdebug_lib_has_active_symbol_table(void); - -zend_execute_data *xdebug_lib_get_active_data(void); -zend_op_array *xdebug_lib_get_active_func_oparray(void); -zval *xdebug_lib_get_active_object(void); -function_stack_entry *xdebug_lib_get_active_stack_entry(void); -HashTable *xdebug_lib_get_active_symbol_table(void); - -int xdebug_isset_opcode_handler(int opcode); -void xdebug_set_opcode_handler(int opcode, user_opcode_handler_t handler); -void xdebug_unset_opcode_handler(int opcode); -void xdebug_set_opcode_multi_handler(int opcode); -void xdebug_register_with_opcode_multi_handler(int opcode, user_opcode_handler_t handler); -int xdebug_call_original_opcode_handler_if_set(int opcode, XDEBUG_OPCODE_HANDLER_ARGS); - -char *xdebug_lib_get_output_dir(void); - -void xdebug_llist_string_dtor(void *dummy, void *elem); -char* xdebug_wrap_location_around_function_name(const char *prefix, zend_op_array *opa, char *fname); -char* xdebug_wrap_closure_location_around_function_name(zend_op_array *opa, char *fname); - -void xdebug_lib_register_compiled_variables(function_stack_entry *fse, zend_op_array *op_array); -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/log.c
Deleted
@@ -1,878 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "php_xdebug.h" -#include "ext/standard/info.h" - -#include "headers.h" - -#include "lib_private.h" -#include "log.h" -#include "var.h" - -char* xdebug_lib_docs_base(void) -{ - char *env = getenv("XDEBUG_DOCS_BASE"); - - if (env) { - return env; - } - - return (char*) "https://xdebug.org/docs/"; -} - -extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); - -const char *xdebug_level_msg_prefix11 = { - "C", "E", "", "W", "", "", "", "I", "", "", "D" -}; -const char *xdebug_log_prefix11 = { - "CRIT:", "ERR: ", "", "WARN: ", "", "", "", "INFO: ", "", "", "DEBUG: " -}; -const char *xdebug_log_prefix_emoji11 = { - "☠", "🛑 ", "", "⚠️ ", "", "", "", "🛈 ", "", "", "• " -}; -const char *xdebug_channel_msg_prefix8 = { - "CFG-", "LOG-", "DBG-", "GC-", "PROF-", "TRACE-", "COV-", "BASE-" -}; -const char *xdebug_channel_name8 = { - "Config ", "Log Files ", "Step Debug ", "GC Stats ", "Profiler ", "Tracing ", "Coverage ", "Base " -}; - -static inline int xdebug_internal_log(int channel, int log_level, const char *message) -{ - zend_ulong pid; - - if (!XG_LIB(log_file)) { - return 0; - } - - pid = xdebug_get_pid(); - - if (!XG_LIB(log_opened_message_sent) && XG_LIB(log_open_timestring)) { - XG_LIB(log_opened_message_sent) = 1; - - fprintf(XG_LIB(log_file), "" ZEND_ULONG_FMT " Log opened at %s\n", pid, XG_LIB(log_open_timestring)); - fflush(XG_LIB(log_file)); - xdfree(XG_LIB(log_open_timestring)); - XG_LIB(log_open_timestring) = NULL; - } - - fprintf( - XG_LIB(log_file), - "" ZEND_ULONG_FMT " %s%s%s\n", - pid, - xdebug_channel_namechannel, - xdebug_log_prefixlog_level, - message - ); - - fflush(XG_LIB(log_file)); - - return 1; -} - -#define TR_START "<tr><td class=\"e\">" -#define TR_END "</td></tr>\n" - -static inline void xdebug_diagnostic_log(int channel, int log_level, const char *error_code, const char *message) -{ - if (!XG_LIB(diagnosis_buffer) || log_level > XLOG_WARN) { - return; - } - - if (sapi_module.phpinfo_as_text) { - xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_channel_namechannel, 0); - xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_log_prefixlog_level, 0); - xdebug_str_add(XG_LIB(diagnosis_buffer), message, 0); - } else { - xdebug_str_add_const(XG_LIB(diagnosis_buffer), "<tr><td class=\"i\">"); - xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_log_prefix_emojilog_level, 0); - xdebug_str_add_const(XG_LIB(diagnosis_buffer), "</td><td class=\"v\">"); - xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_channel_namechannel, 0); - xdebug_str_add(XG_LIB(diagnosis_buffer), message, 0); - xdebug_str_add_const(XG_LIB(diagnosis_buffer), "</td><td class=\"d\"><a href=\""); - xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_lib_docs_base(), 0); - xdebug_str_add_const(XG_LIB(diagnosis_buffer), "errors#"); - xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_channel_msg_prefixchannel, 0); - xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_level_msg_prefixlog_level, 0); - if (error_code) { - xdebug_str_addc(XG_LIB(diagnosis_buffer), '-'); - xdebug_str_add(XG_LIB(diagnosis_buffer), error_code, 0); - } - xdebug_str_add_const(XG_LIB(diagnosis_buffer), "\">🖹</a></td></tr>"); - } - - xdebug_str_addc(XG_LIB(diagnosis_buffer), '\n'); -} - -static inline void xdebug_php_log(int channel, int log_level, const char *error_code, const char *message) -{ - xdebug_str formatted_message = XDEBUG_STR_INITIALIZER; - - if (log_level > XLOG_ERR) { - return; - } - - xdebug_str_add_const(&formatted_message, "Xdebug: "); - xdebug_str_add(&formatted_message, xdebug_channel_namechannel, 0); - xdebug_str_add(&formatted_message, message, 0); - - if (error_code && log_level == XLOG_CRIT) { - xdebug_str_add_const(&formatted_message, " (See: "); - xdebug_str_add(&formatted_message, xdebug_lib_docs_base(), 0); - xdebug_str_add_const(&formatted_message, "errors#"); - xdebug_str_add(&formatted_message, xdebug_channel_msg_prefixchannel, 0); - xdebug_str_add(&formatted_message, xdebug_level_msg_prefixlog_level, 0); - xdebug_str_addc(&formatted_message, '-'); - xdebug_str_add(&formatted_message, error_code, 0); - xdebug_str_addc(&formatted_message, ')'); - } - - php_log_err(formatted_message.d); - - xdebug_str_destroy(&formatted_message); -} - -void XDEBUG_ATTRIBUTE_FORMAT(printf, 4, 5) xdebug_log_ex(int channel, int log_level, const char *error_code, const char *fmt, ...) -{ - xdebug_str message = XDEBUG_STR_INITIALIZER; - va_list argv; - int logged_to_xdebug_log = 0; - - if (XINI_LIB(log_level) < log_level) { - return; - } - - va_start(argv, fmt); - xdebug_str_add_va_fmt(&message, fmt, argv); - va_end(argv); - - logged_to_xdebug_log = xdebug_internal_log(channel, log_level, message.d); - - xdebug_diagnostic_log(channel, log_level, error_code, message.d); - - if (!logged_to_xdebug_log || XINI_LIB(log_level) == XLOG_CRIT) { - xdebug_php_log(channel, log_level, error_code, message.d); - } - - xdebug_str_destroy(&message); -} - -static void log_filename_not_opened(int channel, const char *directory, const char *filename) -{ - xdebug_str full_filename = XDEBUG_STR_INITIALIZER; - - if (directory) { - xdebug_str_add(&full_filename, directory, 0); - if (!IS_SLASH(directorystrlen(directory) - 1)) { - xdebug_str_addc(&full_filename, DEFAULT_SLASH); - } - } - xdebug_str_add(&full_filename, filename, 0); - - xdebug_log_ex(channel, XLOG_ERR, "OPEN", "File '%s' could not be opened.", full_filename.d); - - xdebug_str_destroy(&full_filename); -} - -void xdebug_log_diagnose_permissions(int channel, const char *directory, const char *filename) -{ -#ifndef WIN32 - struct stat dir_info; -#endif - - log_filename_not_opened(channel, directory, filename); - -#ifndef WIN32 - if (!directory) { - return; - } - - if (stat(directory, &dir_info) == -1) { - xdebug_log_ex(channel, XLOG_WARN, "STAT", "%s: %s", directory, strerror(errno)); - return; - } - - if (!S_ISDIR(dir_info.st_mode)) { - xdebug_log_ex(channel, XLOG_WARN, "NOTDIR", "The path '%s' is not a directory.", directory); - return; - } - - xdebug_log_ex(channel, XLOG_WARN, "PERM", "The path '%s' has the permissions: 0%03o.", directory, dir_info.st_mode & 0777); -#endif -} - -static int xdebug_info_printf(const char *fmt, ...) /* {{{ */ -{ - char *buf; - size_t len, written; - va_list argv; - - va_start(argv, fmt); - len = vspprintf(&buf, 0, fmt, argv); - va_end(argv); - - written = php_output_write(buf, len); - efree(buf); - return written; -} -/* }}} */ - -static void print_logo(void) -{ - if (!sapi_module.phpinfo_as_text) { - PUTS("<tr><td colspan=\"2\" class=\"l\">"); - PUTS("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"176\" height=\"91\" viewBox=\"0 0 351 181\"><title>Xdebug</title><g fill=\"none\" fill-rule=\"evenodd\" stroke=\"#FFF\"><g transform=\"translate(5 5)\"><path fill=\"#317E1E\" fill-rule=\"nonzero\" stroke-width=\"5\" d=\"M127.9 85.5l68.2 70.7.4 17.3h-38.6l-60.8-59.7-60 59.7h-39v-17.6l69.7-69.8-69.6-71.2V-2.5h38.7l60.2 60 61-60h38.3v16l-68.5 72z\"></path><circle cx=\"75.9\" cy=\"74.6\" r=\"3.5\" stroke-opacity=\".8\" stroke-width=\"4\"></circle><circle cx=\"105.1\" cy=\"85\" r=\"3.5\" stroke-opacity=\".8\" stroke-width=\"4\"></circle><circle cx=\"158.4\" cy=\"15\" r=\"3.5\" stroke-opacity=\".8\" stroke-width=\"4\"></circle><circle cx=\"50.9\" cy=\"140\" r=\"3.5\" stroke-opacity=\".8\" stroke-width=\"4\"></circle><circle cx=\"180.4\" cy=\"158.5\" r=\"3.5\" stroke-opacity=\".8\" stroke-width=\"4\"></circle><path stroke-linecap=\"square\" stroke-linejoin=\"round\" stroke-width=\"4\" d=\"M32.6 158.2L42 149M104.3 69.1l49.4-49.4\"></path><path stroke-linejoin=\"round\" stroke-width=\"4\" d=\"M102.3 82.7L30.3 10H11.2M167.4 10H183M11.2 160.7l79.2-78\"></path><path stroke-linejoin=\"round\" stroke-opacity=\".7\" stroke-width=\"4\" d=\"M116.3 74.6L181 10\"></path><path stroke-linejoin=\"round\" stroke-width=\"4\" d=\"M20.7 19.7l52.7 52.6\"></path><path stroke-linejoin=\"round\" stroke-opacity=\".7\" stroke-width=\"4\" d=\"M116.3 96.7l32 32\"></path><path stroke-linejoin=\"round\" stroke-width=\"4\" d=\"M155.2 133.6l22.1 22M53.6 137.5L97 94.9l67.1 66.6h4.9\"></path></g><g fill=\"#000\" fill-rule=\"nonzero\" stroke-width=\"4\"><path d=\"M158.3 107.7V72.9c0-.5 0-.5-.8-.5-.7 0-.7 0-.7.6v34.7c0 .6 0 .5.7.5.8 0 .7 0 .7-.5zm3.9 11.2a22.5 22.5 0 0 1-20-.7c-3.4-2-5.2-4.8-5.2-8.4V69.6c0-3 1.5-5.6 4.3-7.4a17 17 0 0 1 9.2-2.4c3 0 5.6.3 7.7 1V47H178v73h-15l-.8-1.1zM200.9 84V73.2c0-.8 0-.8-.8-.8s-.8 0-.8.8V84h1.6zm-1.6 12.5v11c0 .7 0 .7.8.7.7 0 .8 0 .8-.8V97.2h19.8v10.4c0 8.9-7.3 13.2-20.7 13.2-13.3 0-20.5-4.5-20.5-13.7V73.6c0-9.2 7.2-13.8 20.5-13.8 13.4 0 20.7 4.4 20.7 13.4v23.3h-21.4zM243.3 107.7V73c0-.6 0-.6-.7-.6-.8 0-.8 0-.8.5v34.8c0 .6 0 .5.8.5.7 0 .7 0 .7-.5zm-5.4 11.1l-.9 1.3h-15V47h19.8v13.8c2.1-.7 4.7-1 7.9-1 3.1 0 6.1.8 8.8 2.3 3 1.6 4.6 4.2 4.6 7.5v40.2c0 3.6-1.8 6.4-5.3 8.4a22.5 22.5 0 0 1-19.9.6zM285.8 119.7c-2.1.8-4.7 1.1-7.8 1.1a17 17 0 0 1-9.1-2.4c-2.8-1.7-4.4-4.2-4.4-7.2v-51h19.8v47.5c0 .6 0 .5.8.5.7 0 .7 0 .7-.4V60h19.8v60h-19.8v-.4zM328.3 108.3V73c0-.6 0-.6-.7-.6-.8 0-.8 0-.8.6V108c0 .6 0 .6.8.6.7 0 .7 0 .7-.4zm-.9 11.8c-2 .5-4.2.7-6.9.7a17 17 0 0 1-9.1-2.4c-2.9-1.7-4.4-4.2-4.4-7.2V71c0-7.4 5.2-11.2 14.6-11.2 2.3 0 5 .7 8.3 2l1.7-1.7H348v57.3c0 4.4-1 9.5-2.8 12-2.1 3.2-7.7 4.5-17 4.5h-18.4v-12h14.9c1.1 0 2-.7 2.7-1.8z\"></path></g></g></svg>"); - PUTS("</td></tr>\n"); - } else { - PUTS("\331m__ __ _ _ \n" - "\331m\\ \\ / / | | | | \n" - "\331m \\ V / __| | ___| |__ _ _ __ _ \n" - "\331m > < / _` |/ _ \\ '_ \\| | | |/ _` |\n" - "\331m / . \\ (_| | __/ |_) | |_| | (_| |\n" - "\331m/_/ \\_\\__,_|\\___|_.__/ \\__,_|\\__, |\n" - "\331m __/ |\n" - "\331m |___/ \n\n\330m"); - - } -} - -static void print_feature_row(const char *name, int flag, const char *doc_name) -{ - if (!sapi_module.phpinfo_as_text) { - PUTS("<tr>"); - PUTS("<td class=\"e\">"); - PUTS(name); - PUTS("</td><td class=\"v\">"); - PUTS(XDEBUG_MODE_IS(flag) ? "✔ enabled" : "✘ disabled"); - PUTS("</td><td class=\"d\"><a href=\""); - PUTS(xdebug_lib_docs_base()); - PUTS(doc_name); - PUTS("\">🖹</a></td></tr>\n"); - } else { - php_info_print_table_row(2, name, XDEBUG_MODE_IS(flag) ? "✔ enabled" : "✘ disabled"); - } -} - -void xdebug_print_info(void) -{ - /* Header block */ - php_info_print_table_start(); - - print_logo(); - - php_info_print_table_row(2, "Version", XDEBUG_VERSION); - - if (!sapi_module.phpinfo_as_text) { - xdebug_info_printf("<tr><td colspan='2' style='background-color: white; text-align: center'>%s</td></tr>\n", "<a style='color: #317E1E; background-color: transparent; font-weight: bold; text-decoration: underline' href='https://xdebug.org/support'>Support Xdebug on Patreon, GitHub, or as a business</a>"); - } else { - xdebug_info_printf("Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support\n"); - } - php_info_print_table_end(); - - /* Modes block */ - php_info_print_table_start(); - - if (!sapi_module.phpinfo_as_text) { - php_info_print_table_colspan_header( - 3, - (char*) (XG_LIB(mode_from_environment) ? "Enabled Features<br/>(through 'XDEBUG_MODE' env variable)" : "Enabled Features<br/>(through 'xdebug.mode' setting)") - ); - } else { - php_info_print_table_colspan_header( - 2, - (char*) (XG_LIB(mode_from_environment) ? "Enabled Features (through 'XDEBUG_MODE' env variable)" : "Enabled Features (through 'xdebug.mode' setting)") - ); - } - - if (!sapi_module.phpinfo_as_text) { - php_info_print_table_header(3, "Feature", "Enabled/Disabled", "Docs"); - } else { - php_info_print_table_header(2, "Feature", "Enabled/Disabled"); - } - - print_feature_row("Development Helpers", XDEBUG_MODE_DEVELOP, "develop"); - print_feature_row("Coverage", XDEBUG_MODE_COVERAGE, "code_coverage"); - print_feature_row("GC Stats", XDEBUG_MODE_GCSTATS, "garbage_collection"); - print_feature_row("Profiler", XDEBUG_MODE_PROFILING, "profiler"); - print_feature_row("Step Debugger", XDEBUG_MODE_STEP_DEBUG, "remote"); - print_feature_row("Tracing", XDEBUG_MODE_TRACING, "trace"); - - php_info_print_table_end(); - - /* Optional compiled in features */ - php_info_print_table_start(); - php_info_print_table_colspan_header(2, (char*) "Optional Features"); - -#if HAVE_XDEBUG_ZLIB - php_info_print_table_row(2, "Compressed File Support", "yes (gzip)"); -#else - php_info_print_table_row(2, "Compressed File Support", "no"); -#endif - -#if WIN32 - php_info_print_table_row(2, "Clock Source", XG_BASE(nanotime_context).use_rel_time ? "QueryPerformanceFrequency" : "GetSystemTimePreciseAsFileTime"); -#else -# if HAVE_XDEBUG_CLOCK_GETTIME_NSEC_NP - php_info_print_table_row(2, "Clock Source", "clock_gettime_nsec_np"); -# elif HAVE_XDEBUG_CLOCK_GETTIME - php_info_print_table_row(2, "Clock Source", "clock_gettime"); -# else - php_info_print_table_row(2, "Clock Source", "gettimeofday"); -# endif -#endif - - - php_info_print_table_end(); -} - -PHPAPI extern char *php_ini_opened_path; -PHPAPI extern char *php_ini_scanned_path; -PHPAPI extern char *php_ini_scanned_files; - -static void xdebug_print_php_section(void) -{ - php_info_print_table_start(); - php_info_print_table_colspan_header(2, (char*) "PHP"); - - php_info_print_table_colspan_header(2, (char*) "Build Configuration"); - php_info_print_table_row(2, "Version (Run Time)", XG_BASE(php_version_run_time)); - php_info_print_table_row(2, "Version (Compile Time)", XG_BASE(php_version_compile_time)); -#if ZEND_DEBUG - php_info_print_table_row(2, "Debug Build", "yes"); -#else - php_info_print_table_row(2, "Debug Build", "no"); -#endif - -#ifdef ZTS - php_info_print_table_row(2, "Thread Safety", "enabled"); -# if PHP_VERSION_ID >= 70300 - php_info_print_table_row(2, "Thread API", tsrm_api_name()); -# endif -#else - php_info_print_table_row(2, "Thread Safety", "disabled"); -#endif - - php_info_print_table_colspan_header(2, (char*) "Settings"); - php_info_print_table_row(2, "Configuration File (php.ini) Path", PHP_CONFIG_FILE_PATH); - php_info_print_table_row(2, "Loaded Configuration File", php_ini_opened_path ? php_ini_opened_path : "(none)"); - php_info_print_table_row(2, "Scan this dir for additional .ini files", php_ini_scanned_path ? php_ini_scanned_path : "(none)"); - php_info_print_table_row(2, "Additional .ini files parsed", php_ini_scanned_files ? php_ini_scanned_files : "(none)"); - php_info_print_table_end(); -} - -static ZEND_COLD void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type) -{ - if (ini_entry->displayer) { - ini_entry->displayer(ini_entry, type); - } else { - const char *display_string; - size_t display_string_length; - int esc_html=0; - - if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { - if (ini_entry->orig_value && ZSTR_VAL(ini_entry->orig_value)0) { - display_string = ZSTR_VAL(ini_entry->orig_value); - display_string_length = ZSTR_LEN(ini_entry->orig_value); - esc_html = !sapi_module.phpinfo_as_text; - } else { - if (!sapi_module.phpinfo_as_text) { - display_string = "<i>no value</i>"; - display_string_length = sizeof("<i>no value</i>") - 1; - } else { - display_string = "no value"; - display_string_length = sizeof("no value") - 1; - } - } - } else if (ini_entry->value && ZSTR_VAL(ini_entry->value)0) { - display_string = ZSTR_VAL(ini_entry->value); - display_string_length = ZSTR_LEN(ini_entry->value); - esc_html = !sapi_module.phpinfo_as_text; - } else { - if (!sapi_module.phpinfo_as_text) { - display_string = "<i>no value</i>"; - display_string_length = sizeof("<i>no value</i>") - 1; - } else { - display_string = "no value"; - display_string_length = sizeof("no value") - 1; - } - } - - if (esc_html) { - zend_html_puts(display_string, display_string_length); - } else { - PHPWRITE(display_string, display_string_length); - } - } -} - -static int if_overridden_xdebug_mode(char *name) -{ - if ((strcmp("xdebug.mode", name) == 0) && XG_LIB(mode_from_environment)) { - return 1; - } - - return 0; -} - -static void xdebug_print_settings(void) -{ - zend_module_entry *module; - zend_ini_entry *ini_entry; - int module_number; - zend_string *name = zend_string_init("xdebug", 6, 0); - - module = zend_hash_find_ptr(&module_registry, name); - zend_string_release(name); - - if (!module) { - return; - } - - module_number = module->module_number; - - php_info_print_table_start(); - if (!sapi_module.phpinfo_as_text) { - php_info_print_table_header(4, "Directive", "Local Value", "Master Value", "Docs"); - } else { - php_info_print_table_header(3, "Directive", "Local Value", "Master Value"); - } - - ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) { - if (ini_entry->module_number != module_number) { - continue; - } - - /* Hack to not show changed and removed settings */ - if (ini_entry->value && strncmp(ZSTR_VAL(ini_entry->value), "This setting has", 16) == 0) { - continue; - } - - if (!sapi_module.phpinfo_as_text) { - PUTS("<tr>"); - PUTS("<td class=\"e\">"); - PHPWRITE(ZSTR_VAL(ini_entry->name), ZSTR_LEN(ini_entry->name)); - if (if_overridden_xdebug_mode(ZSTR_VAL(ini_entry->name))) { - PUTS(" (through XDEBUG_MODE)"); - } - PUTS("</td><td class=\"v\">"); - if (if_overridden_xdebug_mode(ZSTR_VAL(ini_entry->name))) { - PUTS(getenv("XDEBUG_MODE")); - } else { - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); - } - PUTS("</td><td class=\"v\">"); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); - PUTS("</td><td class=\"d\"><a href=\""); - PUTS(xdebug_lib_docs_base()); - PUTS("all_settings#"); - PHPWRITE(ZSTR_VAL(ini_entry->name), ZSTR_LEN(ini_entry->name)); - PUTS("\">🖹</a></td></tr>\n"); - } else { - PHPWRITE(ZSTR_VAL(ini_entry->name), ZSTR_LEN(ini_entry->name)); - if (if_overridden_xdebug_mode(ZSTR_VAL(ini_entry->name))) { - PUTS(" (through XDEBUG_MODE)"); - } - PUTS(" => "); - if (if_overridden_xdebug_mode(ZSTR_VAL(ini_entry->name))) { - PUTS(getenv("XDEBUG_MODE")); - } else { - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); - } - PUTS(" => "); - php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); - PUTS("\n"); - } - } ZEND_HASH_FOREACH_END(); - - php_info_print_table_end(); -} - -static void print_html_header(void) -{ - if (sapi_module.phpinfo_as_text) { - return; - } - - PUTS("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n"); - PUTS("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); - PUTS("<head>\n"); - - PUTS("<style type=\"text/css\">\n"); - PUTS("body {background-color: #fff; color: #222; font-family: sans-serif;}\n"); - PUTS("pre {margin: 0; font-family: monospace;}\n"); - PUTS("a:link, a:hover, a:visited {color: black; text-decoration: underline;}\n"); - PUTS("table {border-collapse: separate; border: 1px solid #666; width: 934px; box-shadow: 1px 2px 3px #ccc; border-bottom: none; border-right: none; border-spacing: 0;}\n"); - PUTS(".center {text-align: center;}\n"); - PUTS(".center table {margin: 1em auto; text-align: left;}\n"); - PUTS(".center th {text-align: center !important;}\n"); - PUTS("td, th {border: 1px solid #666; font-size: 75%; vertical-align: baseline; padding: 4px 5px; border-left: none; border-top: none;}\n"); - PUTS("th {top: 0; background: inherit; position: sticky;}\n"); - PUTS("h1 {font-size: 150%;}\n"); - PUTS("h2 {font-size: 125%;}\n"); - PUTS(".p {text-align: left;}\n"); - PUTS(".e {background-color: #e5f5d5; width: 300px; font-weight: bold;}\n"); - PUTS(".h {background-color: #bbde94; font-weight: bold;}\n"); - PUTS(".v {background-color: #ddd; max-width: 300px; overflow-x: auto; word-wrap: break-word;}\n"); - PUTS(".i {background-color: #ddd; text-align: center; font-size: 1em; font-family: serif; width: 1em;}\n"); - PUTS(".v i {color: #999;}\n"); - PUTS(".d {background-color: #ddd; width: 1em; text-align: center;}\n"); - PUTS(".l {background-color: #bbde94;}\n"); - PUTS("img {float: right; border: 0;}\n"); - PUTS("hr {width: 934px; background-color: #ccc; border: 0; height: 1px;}\n"); - PUTS("</style>\n"); - - PUTS("<title>Xdebug "); - PUTS(XDEBUG_VERSION); - PUTS("</title>"); - PUTS("<meta name=\"ROBOTS\" content=\"NOINDEX,NOFOLLOW,NOARCHIVE\" />"); - PUTS("</head>\n"); - PUTS("<body><div class=\"center\">\n"); -} - -static void print_html_footer(void) -{ - if (sapi_module.phpinfo_as_text) { - return; - } - - php_output_write("</div></body></html>", strlen("</div></body></html>")); -} - -static void print_diagnostic_log(void) -{ - php_info_print_table_start(); - if (!sapi_module.phpinfo_as_text) { - php_info_print_table_colspan_header(3, (char*) "Diagnostic Log"); - } else { - php_info_print_table_colspan_header(2, (char*) "Diagnostic Log"); - } - if (XG_LIB(diagnosis_buffer) && XG_LIB(diagnosis_buffer)->l) { - if (!sapi_module.phpinfo_as_text) { - PUTS("<tr class=\"h\"><th colspan=\"2\">Message</th><th>Docs</th></tr>\n"); - } - php_output_write(XG_LIB(diagnosis_buffer)->d, XG_LIB(diagnosis_buffer)->l); - } else { - if (!sapi_module.phpinfo_as_text) { - PUTS("<tr><td class=\"v\" colspan=\"3\">No messages</td></tr>\n"); - } else { - PUTS("No messages\n"); - } - } - php_info_print_table_end(); -} - -static void print_profile_information(void) -{ - char *file_name; - - if (!XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - return; - } - - file_name = xdebug_get_profiler_filename(); - - php_info_print_table_start(); - if (!sapi_module.phpinfo_as_text) { - PUTS("<tr class=\"h\"><th colspan=\"2\">Profiler</th><th>Docs</th></tr>\n"); - if (file_name) { - xdebug_info_printf("<tr><td class=\"e\">Profile File</td><td class=\"v\">%s</td><td class=\"d\"><a href=\"%sprofiler\">🖹</a></td></tr>\n", - file_name, xdebug_lib_docs_base()); - } else { - xdebug_info_printf("<tr><td colspan=\"2\" class=\"d\">Profiler is not active</td><td class=\"d\"><a href=\"%sprofiler\">🖹</a></td></tr>\n", - xdebug_lib_docs_base()); - } - } else { - php_info_print_table_colspan_header(2, (char*) "Profiler"); - if (file_name) { - php_info_print_table_row(2, "Profile File", file_name); - } else { - PUTS("Profiler is not active\n"); - } - } - php_info_print_table_end(); -} - -static void print_step_debug_information(void) -{ - int is_active; - - if (!XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - return; - } - - is_active = xdebug_is_debug_connection_active(); - - php_info_print_table_start(); - if (!sapi_module.phpinfo_as_text) { - PUTS("<tr class=\"h\"><th colspan=\"2\">Step Debugging</th><th>Docs</th></tr>\n"); - xdebug_info_printf( - "<tr><td class=\"e\">Debugger</td><td class=\"v\">%s</td>" - "<td class=\"d\"><a href=\"%sstep_debug\">🖹</a></td></tr>\n", - is_active ? "Active" : (XG_DBG(detached) ? "Detached" : "Not Active"), xdebug_lib_docs_base()); - if (XG_DBG(context).connected_hostname) { - if (strcmp(XINI_DBG(cloud_id), "") == 0) { - xdebug_info_printf( - "<tr><td class=\"e\">Connected Client</td><td class=\"v\">%s:%d</td><td class=\"d\"> </td></tr>\n", - XG_DBG(context).connected_hostname, XG_DBG(context).connected_port - ); - } else { - xdebug_info_printf( - "<tr><td class=\"e\">Xdebug Cloud Host</td><td class=\"v\">%s:%d</td><td class=\"d\"> </td></tr>\n", - XG_DBG(context).connected_hostname, XG_DBG(context).connected_port - ); - xdebug_info_printf( - "<tr><td class=\"e\">Xdebug Cloud ID</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", - XINI_DBG(cloud_id) - ); - } - } - if (XG_DBG(detached)) { - xdebug_info_printf( - "<tr><td class=\"e\">Detached</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", - XG_DBG(context).detached_message ? XG_DBG(context).detached_message : "Yes" - ); - } else if (XG_DBG(context).options) { - xdebug_var_export_options *options; - PUTS("<tr class=\"h\"><th colspan=\"3\">DBGp Settings</th></tr>\n"); - - options = (xdebug_var_export_options*) XG_DBG(context).options; - xdebug_info_printf( - "<tr><td class=\"e\">Max Children</td><td class=\"v\">%d</td><td class=\"d\"> </td></tr>\n", - options->max_children - ); - xdebug_info_printf( - "<tr><td class=\"e\">Max Data</td><td class=\"v\">%d</td><td class=\"d\"> </td></tr>\n", - options->max_data - ); - xdebug_info_printf( - "<tr><td class=\"e\">Max Depth</td><td class=\"v\">%d</td><td class=\"d\"> </td></tr>\n", - options->max_depth - ); - xdebug_info_printf( - "<tr><td class=\"e\">Show Hidden Properties</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", - options->show_hidden ? "Yes" : "No" - ); - xdebug_info_printf( - "<tr><td class=\"e\">Extended Properties</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", - options->extended_properties ? "Yes" : "No" - ); - xdebug_info_printf( - "<tr><td class=\"e\">Notifications</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", - XG_DBG(context).send_notifications ? "Yes" : "No" - ); - xdebug_info_printf( - "<tr><td class=\"e\">Resolved Breakpoints</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", - XG_DBG(context).resolved_breakpoints ? "Yes" : "No" - ); - xdebug_info_printf( - "<tr><td class=\"e\">Breakpoint Details</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", - XG_DBG(context).breakpoint_details ? "Yes" : "No" - ); - } - } else { - php_info_print_table_colspan_header(2, (char*) "Step Debugging"); - if (is_active) { - PUTS("Debugger is active\n"); - } else { - PUTS("Debugger is not active\n"); - } - if (XG_DBG(context).connected_hostname) { - if (strcmp(XINI_DBG(cloud_id), "") == 0) { - xdebug_info_printf("Connected Client => %s:%d\n", - XG_DBG(context).connected_hostname, XG_DBG(context).connected_port - ); - } else { - xdebug_info_printf( - "Xdebug Cloud Host => %s:%d\n", - XG_DBG(context).connected_hostname, XG_DBG(context).connected_port - ); - xdebug_info_printf("Xdebug Cloud ID => %s\n", XINI_DBG(cloud_id)); - } - } - if (XG_DBG(detached)) { - xdebug_info_printf("Detached => %s\n", XG_DBG(context).detached_message ? XG_DBG(context).detached_message : "Yes"); - } else if (XG_DBG(context).options) { - xdebug_var_export_options *options = (xdebug_var_export_options*) XG_DBG(context).options; - - PUTS("\nDBGp Settings\n"); - xdebug_info_printf("Max Children => %d\n", options->max_children); - xdebug_info_printf("Max Data => %d\n", options->max_data); - xdebug_info_printf("Max Depth => %d\n", options->max_depth); - xdebug_info_printf("Show Hidden Properties => %s\n", options->show_hidden ? "Yes" : "No"); - xdebug_info_printf("Extended Properties => %s\n", options->extended_properties ? "Yes" : "No"); - xdebug_info_printf("Notifications => %s\n", XG_DBG(context).send_notifications ? "Yes" : "No"); - xdebug_info_printf("Resolved Breakpoints => %s\n", XG_DBG(context).resolved_breakpoints ? "Yes" : "No"); - xdebug_info_printf("Breakpoint Details => %s\n", XG_DBG(context).breakpoint_details ? "Yes" : "No"); - } - } - php_info_print_table_end(); -} - -static void print_trace_information(void) -{ - char *file_name; - - if (!XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { - return; - } - - file_name = xdebug_get_trace_filename(); - - php_info_print_table_start(); - if (!sapi_module.phpinfo_as_text) { - PUTS("<tr class=\"h\"><th colspan=\"2\">Function Tracing</th><th>Docs</th></tr>\n"); - if (file_name) { - xdebug_info_printf("<tr><td class=\"e\">Trace File</td><td class=\"v\">%s</td><td class=\"d\"><a href=\"%strace\">🖹</a></td></tr>\n", - file_name, xdebug_lib_docs_base()); - } else { - xdebug_info_printf("<tr><td colspan=\"2\" class=\"d\">Function tracing is not active</td><td class=\"d\"><a href=\"%strace\">🖹</a></td></tr>\n", - xdebug_lib_docs_base()); - } - } else { - php_info_print_table_colspan_header(2, (char*) "Function Tracing"); - if (file_name) { - php_info_print_table_row(2, "Trace File", file_name); - } else { - PUTS("Function tracing is not active\n"); - } - } - php_info_print_table_end(); -} - -static void xdebug_display_all_info(void) -{ - print_html_header(); - - xdebug_print_info(); - - print_diagnostic_log(); - print_step_debug_information(); - print_profile_information(); - print_trace_information(); - - xdebug_print_php_section(); - - xdebug_print_settings(); - - print_html_footer(); -} - -static void info_modes_set(INTERNAL_FUNCTION_PARAMETERS) -{ - array_init_size(return_value, 6); - - if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { - add_next_index_stringl(return_value, "coverage", 8); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - add_next_index_stringl(return_value, "debug", 5); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - add_next_index_stringl(return_value, "develop", 7); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { - add_next_index_stringl(return_value, "gcstats", 7); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - add_next_index_stringl(return_value, "profile", 7); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { - add_next_index_stringl(return_value, "trace", 5); - } -} - -static void info_extension_flags_set(INTERNAL_FUNCTION_PARAMETERS) -{ - array_init_size(return_value, 1); - -#if HAVE_XDEBUG_ZLIB - add_next_index_stringl(return_value, "compression", 11); -#endif -} - - -PHP_FUNCTION(xdebug_info) -{ - zend_string *group = NULL; - - ZEND_PARSE_PARAMETERS_START(0, 1) - Z_PARAM_OPTIONAL - Z_PARAM_STR(group) - ZEND_PARSE_PARAMETERS_END(); - - if (group == NULL) { - xdebug_display_all_info(); - return; - } - - if (zend_string_equals_literal(group, "mode")) { - info_modes_set(INTERNAL_FUNCTION_PARAM_PASSTHRU); - return; - } - if (zend_string_equals_literal(group, "extension-flags")) { - info_extension_flags_set(INTERNAL_FUNCTION_PARAM_PASSTHRU); - return; - } - - php_error_docref(NULL, E_WARNING, "The information group '%s' is not available", ZSTR_VAL(group)); -} - -void xdebug_open_log(void) -{ - /* initialize remote log file */ - XG_LIB(log_file) = NULL; - XG_LIB(log_opened_message_sent) = 0; - XG_LIB(log_open_timestring) = NULL; - - if (XINI_LIB(log) && strlen(XINI_LIB(log))) { - XG_LIB(log_file) = xdebug_fopen(XINI_LIB(log), "a", NULL, NULL); - } - if (XG_LIB(log_file)) { - XG_LIB(log_open_timestring) = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6); - } else if (strlen(XINI_LIB(log))) { - xdebug_log_diagnose_permissions(XLOG_CHAN_LOGFILE, NULL, XINI_LIB(log)); - } -} - -void xdebug_close_log() -{ - char *timestr; - - if (!XG_LIB(log_file)) { - return; - } - - if (XG_LIB(log_opened_message_sent)) { - zend_ulong pid; - - pid = xdebug_get_pid(); - timestr = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6); - - fprintf(XG_LIB(log_file), "" ZEND_ULONG_FMT " Log closed at %s\n\n", pid, timestr); - fflush(XG_LIB(log_file)); - xdfree(timestr); - } - - if (XG_LIB(log_open_timestring)) { - xdfree(XG_LIB(log_open_timestring)); - XG_LIB(log_open_timestring) = NULL; - } - - fclose(XG_LIB(log_file)); - XG_LIB(log_file) = NULL; -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/str.c
Deleted
@@ -1,257 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <locale.h> - -#include "php.h" -#include "ext/standard/php_string.h" - -#include "mm.h" -#include "str.h" - -inline static void realloc_if_needed(xdebug_str *xs, int size_to_fit) -{ - if (!xs->a || !xs->l || xs->l + size_to_fit > xs->a - 1) { - xs->d = xdrealloc(xs->d, xs->a + size_to_fit + XDEBUG_STR_PREALLOC); - xs->a = xs->a + size_to_fit + XDEBUG_STR_PREALLOC; - } - if (!xs->l) { - xs->d0 = '\0'; - } -} - -inline static void xdebug_str_internal_addl(xdebug_str *xs, const char *str, int le, int f) -{ - realloc_if_needed(xs, le); - - memcpy(xs->d + xs->l, str, le); - xs->dxs->l + le = '\0'; - xs->l = xs->l + le; - - if (f) { - xdfree((char*) str); - } -} - -void xdebug_str_add(xdebug_str *xs, const char *str, int f) -{ - xdebug_str_internal_addl(xs, str, strlen(str), f); -} - -void xdebug_str_addl(xdebug_str *xs, const char *str, int le, int f) -{ - xdebug_str_internal_addl(xs, str, le, f); -} - -void xdebug_str_add_str(xdebug_str *xs, const xdebug_str *str) -{ - xdebug_str_internal_addl(xs, str->d, str->l, 0); -} - -void xdebug_str_add_zstr(xdebug_str *xs, const zend_string *str) -{ - xdebug_str_internal_addl(xs, ZSTR_VAL(str), ZSTR_LEN(str), 0); -} - -void xdebug_str_addc(xdebug_str *xs, char letter) -{ - realloc_if_needed(xs, 1); - - xs->dxs->l = letter; - xs->dxs->l + 1 = '\0'; - xs->l = xs->l + 1; -} - -void xdebug_str_add_uint64(xdebug_str *xs, uint64_t num) -{ - char buffer21; - char *pos; - int digit; - - pos = &buffer20; - *pos = '\0'; - - do { - digit = num % 10; - num = num / 10; - if (digit < 10) { - *--pos = '0' + digit; - } else { - *--pos = 'a' + digit - 10; - } - } while (num != 0L); - - xdebug_str_internal_addl(xs, pos, &buffer20 - pos, 0); -} - -void xdebug_str_add_va_fmt(xdebug_str *xs, const char *fmt, va_list argv) -{ - int size; - int n; - va_list argv_size, argv_copy; - - realloc_if_needed(xs, 1); - size = xs->a - xs->l; - - va_copy(argv_size, argv); - n = vsnprintf(xs->d + xs->l, size, fmt, argv_size); - va_end(argv_size); - if (n > -1 && n < size) { - xs->l += n; - return; - } - - realloc_if_needed(xs, n + 1); - size = xs->a - xs->l; - - va_copy(argv_copy, argv); - n = vsnprintf(xs->d + xs->l, size, fmt, argv_copy); - va_end(argv_copy); - - if (n > -1 && n < size) { - xs->l += n; - return; - } - - assert(0); -} - -void xdebug_str_add_fmt(xdebug_str *xs, const char *fmt, ...) -{ - va_list args; - - va_start(args, fmt); - xdebug_str_add_va_fmt(xs, fmt, args); - va_end(args); -} - -void xdebug_str_chop(xdebug_str *xs, size_t c) -{ - if (c > xs->l) { - /* Do nothing if the chop amount is larger than the buffer size */ - } else { - xs->l -= c; - xs->dxs->l = '\0'; - } -} - -xdebug_str *xdebug_str_new(void) -{ - xdebug_str *tmp = xdmalloc(sizeof(xdebug_str)); - - tmp->l = 0; - tmp->a = 0; - tmp->d = NULL; - - return tmp; -} - -xdebug_str *xdebug_str_create(const char *c, size_t len) -{ - xdebug_str *tmp = xdebug_str_new(); - - tmp->l = tmp->a = len; - tmp->a++; - tmp->d = xdmalloc(tmp->a); - memcpy(tmp->d, c, tmp->l); - tmp->dtmp->l = '\0'; - - return tmp; -} - -xdebug_str *xdebug_str_create_from_char(char *c) -{ - return xdebug_str_create(c, strlen(c)); -} - -xdebug_str *xdebug_str_copy(xdebug_str *orig) -{ - xdebug_str *tmp = xdebug_str_new(); - - tmp->l = tmp->a = orig->l; - tmp->a++; - tmp->d = xdmalloc(tmp->a); - memcpy(tmp->d, orig->d, tmp->l); - tmp->dorig->l = '\0'; - - return tmp; -} - -void xdebug_str_destroy(xdebug_str *s) -{ - if (s->d) { - xdfree(s->d); - } -} - -void xdebug_str_free(xdebug_str *s) -{ - xdebug_str_destroy(s); - xdfree(s); -} - -char *xdebug_sprintf(const char* fmt, ...) -{ - char *new_str; - int size = 32; - va_list args; - - new_str = (char *) xdmalloc(size); - - for (;;) { - int n; - - va_start(args, fmt); - n = vsnprintf(new_str, size, fmt, args); - va_end(args); - - if (n > -1 && n < size) { - break; - } - if (n < 0) { - size *= 2; - } else { - size = n + 1; - } - new_str = (char *) xdrealloc(new_str, size); - } - - return new_str; -} - -/** - * Duplicate zend_strndup in core to avoid mismatches - * in C-runtime libraries when xdebug and core are built - * with different run-time libraries. - */ -char *xdebug_strndup(const char *s, int length) -{ - char *p; - - p = (char *) xdmalloc(length + 1); - if (p == NULL) { - return p; - } - if (length) { - memcpy(p, s, length); - } - plength = 0; - return p; -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/str.h
Deleted
@@ -1,61 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __HAVE_XDEBUG_STR_H__ -#define __HAVE_XDEBUG_STR_H__ - -#include <stddef.h> - -#include "php.h" - -#include "mm.h" - -#define XDEBUG_STR_INITIALIZER { 0, 0, NULL } -#define XDEBUG_STR_PREALLOC 1024 -#define xdebug_str_dtor(str) xdfree(str.d) - -#define XDEBUG_STR_WRAP_CHAR(v) (&((xdebug_str){strlen(v), strlen(v)+1, ((char*)(v))})) - -typedef struct xdebug_str { - size_t l; - size_t a; - char *d; -} xdebug_str; - -void xdebug_str_add(xdebug_str *xs, const char *str, int f); -void xdebug_str_addl(xdebug_str *xs, const char *str, int le, int f); -void xdebug_str_add_str(xdebug_str *xs, const xdebug_str *str); -void xdebug_str_add_zstr(xdebug_str *xs, const zend_string *str); -void xdebug_str_addc(xdebug_str *xs, char letter); -void xdebug_str_add_uint64(xdebug_str *xs, uint64_t num); -void xdebug_str_add_fmt(xdebug_str *xs, const char *fmt, ...); -void xdebug_str_add_va_fmt(xdebug_str *xs, const char *fmt, va_list argv); -#define xdebug_str_add_literal(s,l) xdebug_str_addl((s), (l), sizeof(l)-1, 0) -#define xdebug_str_add_const(s,l) xdebug_str_addl((s), (l), strlen(l), 0) - -void xdebug_str_chop(xdebug_str *xs, size_t c); - -xdebug_str *xdebug_str_new(void); -xdebug_str *xdebug_str_create_from_char(char *c); -xdebug_str *xdebug_str_create(const char *c, size_t len); -xdebug_str *xdebug_str_copy(xdebug_str *orig); -void xdebug_str_destroy(xdebug_str *s); -void xdebug_str_free(xdebug_str *s); - -char* xdebug_sprintf(const char* fmt, ...); -char* xdebug_strndup(const char *s, int length); - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/usefulstuff.c
Deleted
@@ -1,722 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include <stdlib.h> -#include <string.h> -#ifndef WIN32 -#include <unistd.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <sys/resource.h> -#include <sys/file.h> -#else -#define PATH_MAX MAX_PATH -#include <winsock2.h> -#include <io.h> -#include <process.h> -#endif -#include "php_xdebug.h" - -#include "mm.h" -#include "crc32.h" -#include "str.h" - -#include "lib_private.h" -#include "usefulstuff.h" -#include "log.h" - -#include "ext/standard/php_lcg.h" -#include "ext/standard/flock_compat.h" -#include "main/php_ini.h" - -#ifndef NAME_MAX -# ifdef _AIX -# include <unistd.h> -# define NAME_MAX pathconf("/dev/null",_PC_NAME_MAX) -# else -# define NAME_MAX (MAXNAMELEN-1) -# endif -#endif - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -xdebug_arg *xdebug_arg_ctor(void) -{ - xdebug_arg *tmp = /*(xdebug_arg*)*/ xdmalloc(sizeof(xdebug_arg)); - - tmp->args = NULL; - tmp->c = 0; - - return tmp; -} - -void xdebug_arg_dtor(xdebug_arg *arg) -{ - int i; - - for (i = 0; i < arg->c; i++) { - xdfree(arg->argsi); - } - if (arg->args) { - xdfree(arg->args); - } - xdfree(arg); -} - -xdebug_str* xdebug_join(const char *delim, xdebug_arg *args, int begin, int end) -{ - int i; - xdebug_str *ret = xdebug_str_new(); - - if (begin < 0) { - begin = 0; - } - if (end > args->c - 1) { - end = args->c - 1; - } - for (i = begin; i < end; i++) { - xdebug_str_add(ret, args->argsi, 0); - xdebug_str_add(ret, delim, 0); - } - xdebug_str_add(ret, args->argsend, 0); - return ret; -} - -void xdebug_explode(const char *delim, const char *str, xdebug_arg *args, int limit) -{ - const char *p1, *p2, *endp; - - endp = str + strlen(str); - - p1 = str; - p2 = xdebug_memnstr(str, delim, strlen(delim), endp); - - if (p2 == NULL) { - args->c++; - args->args = (char**) xdrealloc(args->args, sizeof(char*) * args->c); - args->argsargs->c - 1 = (char*) xdmalloc(strlen(str) + 1); - memcpy(args->argsargs->c - 1, p1, strlen(str)); - args->argsargs->c - 1strlen(str) = '\0'; - } else { - do { - args->c++; - args->args = (char**) xdrealloc(args->args, sizeof(char*) * args->c); - args->argsargs->c - 1 = (char*) xdmalloc(p2 - p1 + 1); - memcpy(args->argsargs->c - 1, p1, p2 - p1); - args->argsargs->c - 1p2 - p1 = '\0'; - p1 = p2 + strlen(delim); - } while ((p2 = xdebug_memnstr(p1, delim, strlen(delim), endp)) != NULL && (limit == -1 || --limit > 1)); - - if (p1 <= endp) { - args->c++; - args->args = (char**) xdrealloc(args->args, sizeof(char*) * args->c); - args->argsargs->c - 1 = (char*) xdmalloc(endp - p1 + 1); - memcpy(args->argsargs->c - 1, p1, endp - p1); - args->argsargs->c - 1endp - p1 = '\0'; - } - } -} - -const char* xdebug_memnstr(const char *haystack, const char *needle, int needle_len, const char *end) -{ - const char *p = haystack; - char first = *needle; - - /* let end point to the last character where needle may start */ - end -= needle_len; - - while (p <= end) { - while (*p != first) - if (++p > end) - return NULL; - if (memcmp(p, needle, needle_len) == 0) - return p; - p++; - } - return NULL; -} - -char* xdebug_strrstr(const char* haystack, const char* needle) -{ - char *loc = NULL; - char *found = NULL; - size_t pos = 0; - - while ((found = strstr(haystack + pos, needle)) != 0) { - loc = found; - pos = (found - haystack) + 1; - } - - return loc; -} - -char *xdebug_trim(const char *str) -{ - char *trimmed = NULL, *begin = (char *) str, *end = NULL; - - /* trim leading space */ - while (isspace((unsigned char) *begin)) { - ++begin; - } - - /* All spaces */ - if (*begin == '\0') { - return xdstrdup(""); - } - - /* trim trailing space */ - end = begin + strlen(begin) - 1; - while (end > begin && isspace((unsigned char) *end)) { - --end; - } - end++; - - trimmed = xdmalloc(end - begin + 1); - memcpy(trimmed, begin, (end - begin)); - trimmed(end - begin) = '\0'; - - return trimmed; -} - -/* not all versions of php export this */ -static int xdebug_htoi(char *s) -{ - int value; - int c; - - c = s0; - if (isupper(c)) { - c = tolower(c); - } - value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16; - - c = s1; - if (isupper(c)) { - c = tolower(c); - } - value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10; - - return value; -} - -/* not all versions of php export this */ -int xdebug_raw_url_decode(char *str, int len) -{ - char *dest = str; - char *data = str; - - while (len--) { - if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) { - *dest = (char) xdebug_htoi(data + 1); - data += 2; - len -= 2; - } else { - *dest = *data; - } - data++; - dest++; - } - *dest = '\0'; - return dest - str; -} - -static unsigned char hexchars = "0123456789ABCDEF"; - -char *xdebug_raw_url_encode(char const *s, int len, int *new_length, int skip_slash) -{ - register int x, y; - unsigned char *str; - - str = (unsigned char *) xdmalloc(3 * len + 1); - for (x = 0, y = 0; len--; x++, y++) { - stry = (unsigned char) sx; - if ((stry < '0' && stry != '-' && stry != '.' && (stry != '/' || !skip_slash)) || - (stry < 'A' && stry > '9' && stry != ':') || - (stry > 'Z' && stry < 'a' && stry != '_' && (stry != '\\' || !skip_slash)) || - (stry > 'z')) - { - stry++ = '%'; - stry++ = hexchars(unsigned char) sx >> 4; - stry = hexchars(unsigned char) sx & 15; - } - } - stry = '\0'; - if (new_length) { - *new_length = y; - } - return ((char *) str); -} - -/* fake URI's per IETF RFC 1738 and 2396 format */ -char *xdebug_path_from_url(zend_string *fileurl) -{ - /* deal with file: url's */ - char *dfp = NULL; - const char *fp = NULL, *efp = ZSTR_VAL(fileurl); -#ifdef PHP_WIN32 - int l = 0; - int i; -#endif - char *tmp = NULL, *ret = NULL; - - dfp = xdstrdup(efp); - fp = dfp; - xdebug_raw_url_decode(dfp, strlen(dfp)); - tmp = strstr(fp, "file://"); - - if (tmp) { - fp = tmp + 7; - if (fp0 == '/' && fp2 == ':') { - fp++; - } - ret = xdstrdup(fp); -#ifdef PHP_WIN32 - l = strlen(ret); - /* convert '/' to '\' */ - for (i = 0; i < l; i++) { - if (reti == '/') { - reti = '\\'; - } - } -#endif - } else { - ret = xdstrdup(ZSTR_VAL(fileurl)); - } - - free(dfp); - return ret; -} - -/* fake URI's per IETF RFC 1738 and 2396 format */ -char *xdebug_path_to_url(zend_string *fileurl) -{ - int l, i, new_len; - char *tmp = NULL; - char *encoded_fileurl; - - /* encode the url */ - encoded_fileurl = xdebug_raw_url_encode(ZSTR_VAL(fileurl), ZSTR_LEN(fileurl), &new_len, 1); - - if (strncmp(ZSTR_VAL(fileurl), "phar://", 7) == 0) { - /* ignore, phar is cool */ - tmp = xdstrdup(ZSTR_VAL(fileurl)); - } else if (ZSTR_VAL(fileurl)0 != '/' && ZSTR_VAL(fileurl)0 != '\\' && ZSTR_VAL(fileurl)1 != ':') { - /* convert relative paths */ - cwd_state new_state; - char cwdMAXPATHLEN; - char *result; - - result = VCWD_GETCWD(cwd, MAXPATHLEN); - if (!result) { - cwd0 = '\0'; - } - - new_state.cwd = estrdup(cwd); - new_state.cwd_length = strlen(cwd); - - if (!virtual_file_ex(&new_state, ZSTR_VAL(fileurl), NULL, 1)) { - char *s = estrndup(new_state.cwd, new_state.cwd_length); - tmp = xdebug_sprintf("file://%s",s); - efree(s); - } - efree(new_state.cwd); - - } else if (ZSTR_VAL(fileurl)1 == '/' || ZSTR_VAL(fileurl)1 == '\\') { - /* convert UNC paths (eg. \\server\sharepath) */ - /* See https://docs.microsoft.com/en-us/archive/blogs/ie/file-uris-in-windows */ - tmp = xdebug_sprintf("file:%s", encoded_fileurl); - } else if (ZSTR_VAL(fileurl)0 == '/' || ZSTR_VAL(fileurl)0 == '\\') { - /* convert *nix paths (eg. /path) */ - tmp = xdebug_sprintf("file://%s", encoded_fileurl); - } else if (ZSTR_VAL(fileurl)1 == ':') { - /* convert windows drive paths (eg. c:\path) */ - tmp = xdebug_sprintf("file:///%s", encoded_fileurl); - } else { - /* no clue about it, use it raw */ - tmp = xdstrdup(encoded_fileurl); - } - l = strlen(tmp); - /* convert '\' to '/' */ - for (i = 0; i < l; i++) { - if (tmpi == '\\') { - tmpi='/'; - } - } - xdfree(encoded_fileurl); - return tmp; -} - -#ifndef PHP_WIN32 -static FILE *xdebug_open_file(char *fname, const char *mode, const char *extension, char **new_fname) -{ - FILE *fh; - char *tmp_fname; - - if (extension) { - tmp_fname = xdebug_sprintf("%s.%s", fname, extension); - } else { - tmp_fname = xdstrdup(fname); - } - fh = fopen(tmp_fname, mode); - if (fh && new_fname) { - *new_fname = tmp_fname; - } else { - xdfree(tmp_fname); - } - return fh; -} - -static FILE *xdebug_open_file_with_random_ext(char *fname, const char *mode, const char *extension, char **new_fname) -{ - FILE *fh; - char *tmp_fname; - - if (extension) { - tmp_fname = xdebug_sprintf("%s.%06x.%s", fname, (long) (1000000 * php_combined_lcg()), extension); - } else { - tmp_fname = xdebug_sprintf("%s.%06x", fname, (long) (1000000 * php_combined_lcg()), extension); - } - fh = fopen(tmp_fname, mode); - if (fh && new_fname) { - *new_fname = tmp_fname; - } else { - xdfree(tmp_fname); - } - return fh; -} - -FILE *xdebug_fopen(char *fname, const char *mode, const char *extension, char **new_fname) -{ - int r; - FILE *fh; - struct stat buf; - char *tmp_fname = NULL; - int filename_len = 0; - - /* We're not doing any tricks for append mode... as that has atomic writes - * anyway. And we ignore read mode as well. */ - if (mode0 == 'a' || mode0 == 'r') { - return xdebug_open_file(fname, mode, extension, new_fname); - } - - /* Make sure we don't open a file with a path that's too long */ - filename_len += (fname ? strlen(fname) : 0); /* filename */ - filename_len += (extension ? strlen(extension) : 0) + 1; /* extension (+ ".") */ - filename_len += 8; /* possible random extension (+ ".") */ - if (filename_len > NAME_MAX) { - fnameNAME_MAX - (extension ? strlen(extension) : 0 ) = '\0'; - } - - /* In write mode however we do have to do some stuff. */ - /* 1. Check if the file exists */ - if (extension) { - tmp_fname = xdebug_sprintf("%s.%s", fname, extension); - } else { - tmp_fname = xdstrdup(fname); - } - r = stat(tmp_fname, &buf); - /* We're not freeing "tmp_fname" as that is used in the freopen as well. */ - - if (r == -1) { - /* 2. Cool, the file doesn't exist so we can open it without probs now. */ - fh = xdebug_open_file(fname, "w", extension, new_fname); - goto lock; - } - - /* 3. It exists, check if we can open it. */ - fh = xdebug_open_file(fname, "r+", extension, new_fname); - if (!fh) { - /* 4. If fh == null we couldn't even open the file, so open a new one with a new name */ - fh = xdebug_open_file_with_random_ext(fname, "w", extension, new_fname); - goto lock; - } - - /* 5. It exists and we can open it, check if we can exclusively lock it. */ - r = flock(fileno(fh), LOCK_EX | LOCK_NB); - if (r == -1) { - if (errno == EWOULDBLOCK) { - fclose(fh); - /* 6. The file is in use, so we open one with a new name. */ - fh = xdebug_open_file_with_random_ext(fname, "w", extension, new_fname); - goto lock; - } - } - - /* 7. We established a lock, now we truncate and return the handle */ - fh = freopen(tmp_fname, "w", fh); - -lock: /* Yes yes, an evil goto label here!!! */ - if (fh) { - /* 8. We have to lock again after the reopen as that basically closes - * the file and opens it again. There is a small race condition here... - */ - flock(fileno(fh), LOCK_EX | LOCK_NB); - } - xdfree(tmp_fname); - return fh; -} -#else -FILE *xdebug_fopen(char *fname, const char *mode, const char *extension, char **new_fname) -{ - char *tmp_fname; - FILE *ret; - - if (extension) { - tmp_fname = xdebug_sprintf("%s.%s", fname, extension); - } else { - tmp_fname = xdstrdup(fname); - } - ret = fopen(tmp_fname, mode); - if (new_fname) { - *new_fname = tmp_fname; - } else { - xdfree(tmp_fname); - } - return ret; -} -#endif - - -int xdebug_format_output_filename(char **filename, char *format, char *script_name) -{ - xdebug_str fname = XDEBUG_STR_INITIALIZER; - char cwd128; - - while (*format) - { - if (*format != '%') { - xdebug_str_addc(&fname, *format); - } else { - format++; - switch (*format) - { - case 'c': /* crc32 of the current working directory */ - if (VCWD_GETCWD(cwd, 127)) { - xdebug_str_add_fmt(&fname, "%lu", xdebug_crc32(cwd, strlen(cwd))); - } - break; - - case 'p': /* pid */ - xdebug_str_add_fmt(&fname, ZEND_ULONG_FMT, xdebug_get_pid()); - break; - - case 'r': /* random number */ - xdebug_str_add_fmt(&fname, "%06x", (long) (1000000 * php_combined_lcg())); - break; - - case 's': { /* script fname */ - char *char_ptr, *script_name_tmp; - - /* we do not always have script_name available, so if we - * don't have it and this format specifier is used then we - * simple do nothing for this specifier */ - if (!script_name) { - break; - } - - /* create a copy to work on */ - script_name_tmp = xdstrdup(script_name); - - /* replace slashes, whitespace and colons with underscores */ - while ((char_ptr = strpbrk(script_name_tmp, "/\\: ")) != NULL) { - char_ptr0 = '_'; - } - /* replace .php with _php */ - char_ptr = strrchr(script_name_tmp, '.'); - if (char_ptr) { - char_ptr0 = '_'; - } - xdebug_str_add(&fname, script_name_tmp, 0); - xdfree(script_name_tmp); - } break; - - case 't': { /* timestamp (in seconds) */ - xdebug_str_add_fmt(&fname, "%lu", xdebug_get_nanotime() / NANOS_IN_SEC); - } break; - - case 'u': { /* timestamp (in microseconds) */ - uint64_t nanotime = xdebug_get_nanotime(); - - xdebug_str_add_fmt(&fname, "%lu.%06d", - nanotime / NANOS_IN_SEC, - (nanotime % NANOS_IN_SEC) / NANOS_IN_MICROSEC - ); - } break; - - case 'H': /* $_SERVER'HTTP_HOST' */ - case 'U': /* $_SERVER'UNIQUE_ID' */ - case 'R': { /* $_SERVER'REQUEST_URI' */ - char *char_ptr, *strval; - zval *data = NULL; - - if (Z_TYPE(PG(http_globals)TRACK_VARS_SERVER) == IS_ARRAY) { - switch (*format) { - case 'H': - data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_SERVER), "HTTP_HOST", sizeof("HTTP_HOST") - 1); - break; - case 'R': - data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_SERVER), "REQUEST_URI", sizeof("REQUEST_URI") - 1); - break; - case 'U': - data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_SERVER), "UNIQUE_ID", sizeof("UNIQUE_ID") - 1); - break; - } - - if (data) { - strval = estrdup(Z_STRVAL_P(data)); - /* replace slashes, dots, question marks, plus - * signs, ampersands, spaces and other evil chars - * with underscores */ - while ((char_ptr = strpbrk(strval, "/\\.?&+:*\"<>| ")) != NULL) { - char_ptr0 = '_'; - } - xdebug_str_add(&fname, strval, 0); - efree(strval); - } - } - } break; - - case 'S': { /* session id */ - zval *data; - char *char_ptr, *strval; - char *sess_name; - - sess_name = zend_ini_string((char*) "session.name", sizeof("session.name"), 0); - - if (sess_name && Z_TYPE(PG(http_globals)TRACK_VARS_COOKIE) == IS_ARRAY && - ((data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_COOKIE), sess_name, strlen(sess_name))) != NULL) && - Z_STRLEN_P(data) < 100 /* Prevent any unrealistically long data being set as filename */ - ) { - strval = estrdup(Z_STRVAL_P(data)); - /* replace slashes, dots, question marks, plus signs, - * ampersands and spaces with underscores */ - while ((char_ptr = strpbrk(strval, "/\\.?&+ ")) != NULL) { - char_ptr0 = '_'; - } - xdebug_str_add(&fname, strval, 0); - efree(strval); - } - } break; - - case '%': /* literal % */ - xdebug_str_addc(&fname, '%'); - break; - } - } - format++; - } - - *filename = fname.d; - - return fname.l; -} - -int xdebug_format_file_link(char **filename, const char *error_filename, int error_lineno) -{ - xdebug_str fname = XDEBUG_STR_INITIALIZER; - char *format = XINI_LIB(file_link_format); - - while (*format) - { - if (*format != '%') { - xdebug_str_addc(&fname, *format); - } else { - format++; - switch (*format) - { - case 'f': /* filename */ - xdebug_str_add(&fname, error_filename, 0); - break; - - case 'l': /* line number */ - xdebug_str_add_fmt(&fname, "%d", error_lineno); - break; - - case '%': /* literal % */ - xdebug_str_addc(&fname, '%'); - break; - } - } - format++; - } - - *filename = fname.d; - - return fname.l; -} - -int xdebug_format_filename(char **formatted_name, const char *default_fmt, zend_string *filename) -{ - xdebug_str fname = XDEBUG_STR_INITIALIZER; - char *name; - xdebug_str *parent, *ancester; - const char *full_filename = ZSTR_VAL(filename); - xdebug_arg *parts; - char *slash = xdebug_sprintf("%c", DEFAULT_SLASH); - char *fmt = XINI_LIB(filename_format); - const char *format = fmt && fmt0 ? fmt : default_fmt; /* If the format is empty, we use the default */ - - /* Create pointers for the format chars */ - parts = xdebug_arg_ctor(); - xdebug_explode(slash, full_filename, parts, -1); - name = parts->argsparts->c - 1; - parent = parts->c > 1 ? - xdebug_join(slash, parts, parts->c - 2, parts->c - 1) : - xdebug_str_create_from_char(name); - ancester = parts->c > 2 ? - xdebug_join(slash, parts, parts->c - 3, parts->c - 1) : - xdebug_str_copy(parent); - - while (*format) - { - if (*format != '%') { - xdebug_str_addc(&fname, *format); - } else { - format++; - switch (*format) - { - case 'n': /* filename */ - xdebug_str_add(&fname, name, 0); - break; - case 'p': /* parent */ - xdebug_str_add_str(&fname, parent); - break; - case 'a': /* ancester */ - xdebug_str_add_str(&fname, ancester); - break; - case 'f': /* full path */ - xdebug_str_add(&fname, full_filename, 0); - break; - case 's': /* slash */ - xdebug_str_addc(&fname, DEFAULT_SLASH); - break; - case '%': /* literal % */ - xdebug_str_addc(&fname, '%'); - break; - } - } - format++; - } - - xdfree(slash); - xdebug_str_free(ancester); - xdebug_str_free(parent); - xdebug_arg_dtor(parts); - - *formatted_name = fname.d; - - return fname.l; -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/var.c
Deleted
@@ -1,1267 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "ext/standard/php_string.h" -#include "ext/standard/url.h" -#include "zend.h" -#include "zend_exceptions.h" -#include "zend_extensions.h" -#include "ext/standard/php_smart_string.h" -#include "zend_smart_str.h" -#if PHP_VERSION_ID >= 80000 -#include "zend_closures.h" -#endif - -#include "php_xdebug.h" - -#include "lib/compat.h" -#include "lib/lib_private.h" -#include "lib/mm.h" -#include "lib/var.h" -#include "lib/var_export_html.h" -#include "lib/var_export_line.h" -#include "lib/xml.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -static inline int object_or_ancestor_is_internal(zval dzval) -{ - zend_class_entry *tmp_ce = Z_OBJCE(dzval); - - do { - if (tmp_ce->type == ZEND_INTERNAL_CLASS) { - return 1; - } - tmp_ce = tmp_ce->parent; - } while (tmp_ce); - - return 0; -} - -#if PHP_VERSION_ID >= 80000 -typedef struct _xdebug_zend_closure_copy { - zend_object std; - zend_function func; - zval this_ptr; - zend_class_entry *called_scope; - zif_handler orig_internal_handler; -} xdebug_zend_closure_copy; - -static int object_with_missing_closure_variables(zval dzval) -{ - zend_class_entry *tmp_ce = NULL; - xdebug_zend_closure_copy *closure = NULL; - - if (Z_TYPE(dzval) != IS_OBJECT) { - return 0; - } - - tmp_ce = Z_OBJCE(dzval); - if (tmp_ce != zend_ce_closure) { - return 0; - } - - closure = (xdebug_zend_closure_copy *) Z_OBJ(dzval); - - if (closure->func.type == ZEND_USER_FUNCTION && closure->func.op_array.static_variables) { - HashTable *static_variables = ZEND_MAP_PTR_GET(closure->func.op_array.static_variables_ptr); - - if (!static_variables) { - return 1; - } - } - - return 0; -} -#endif - -#if PHP_VERSION_ID >= 70400 -HashTable *xdebug_objdebug_pp(zval **zval_pp, int flags) -#else -HashTable *xdebug_objdebug_pp(zval **zval_pp, int *is_tmp, int flags) -#endif -{ - zval dzval = **zval_pp; - HashTable *tmp; - - if ( - !XG_BASE(in_debug_info) && - (object_or_ancestor_is_internal(dzval) || (flags & XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO)) && -#if PHP_VERSION_ID >= 80000 - !object_with_missing_closure_variables(dzval) && -#endif - Z_OBJ_HANDLER(dzval, get_debug_info) - ) { - void *original_trace_context; - zend_object *orig_exception; - - xdebug_tracing_save_trace_context(&original_trace_context); - XG_BASE(in_debug_info) = 1; - orig_exception = EG(exception); - EG(exception) = NULL; - -#if PHP_VERSION_ID >= 70400 - tmp = zend_get_properties_for(&dzval, ZEND_PROP_PURPOSE_DEBUG); -#else - tmp = Z_OBJ_HANDLER(dzval, get_debug_info)(&dzval, is_tmp); -#endif - XG_BASE(in_debug_info) = 0; - xdebug_tracing_restore_trace_context(original_trace_context); - EG(exception) = orig_exception; - - return tmp; - } else { -#if PHP_VERSION_ID >= 70400 - return zend_get_properties_for(&dzval, ZEND_PROP_PURPOSE_VAR_EXPORT); -#else - *is_tmp = 0; - if (Z_OBJ_HANDLER(dzval, get_properties)) { - return Z_OBJPROP(dzval); - } -#endif - } - return NULL; -} - -char* xdebug_error_type_simple(int type) -{ - switch (type) { - case E_ERROR: - case E_CORE_ERROR: - case E_COMPILE_ERROR: - case E_USER_ERROR: - return xdstrdup("fatal-error"); - break; - case E_RECOVERABLE_ERROR: - return xdstrdup("recoverable-fatal-error"); - break; - case E_WARNING: - case E_CORE_WARNING: - case E_COMPILE_WARNING: - case E_USER_WARNING: - return xdstrdup("warning"); - break; - case E_PARSE: - return xdstrdup("parse-error"); - break; - case E_NOTICE: - case E_USER_NOTICE: - return xdstrdup("notice"); - break; - case E_STRICT: - return xdstrdup("strict-standards"); - break; - case E_DEPRECATED: - case E_USER_DEPRECATED: - return xdstrdup("deprecated"); - break; - case 0: - return xdstrdup("xdebug"); - break; - default: - return xdstrdup("unknown-error"); - break; - } -} - -char* xdebug_error_type(int type) -{ - switch (type) { - case E_ERROR: - case E_CORE_ERROR: - case E_COMPILE_ERROR: - case E_USER_ERROR: - return xdstrdup("Fatal error"); - break; - case E_RECOVERABLE_ERROR: - return xdstrdup("Recoverable fatal error"); - break; - case E_WARNING: - case E_CORE_WARNING: - case E_COMPILE_WARNING: - case E_USER_WARNING: - return xdstrdup("Warning"); - break; - case E_PARSE: - return xdstrdup("Parse error"); - break; - case E_NOTICE: - case E_USER_NOTICE: - return xdstrdup("Notice"); - break; - case E_STRICT: - return xdstrdup("Strict standards"); - break; - case E_DEPRECATED: - case E_USER_DEPRECATED: - return xdstrdup("Deprecated"); - break; - case 0: - return xdstrdup("Xdebug"); - break; - default: - return xdstrdup("Unknown error"); - break; - } -} - -/*************************************************************************************************************************************/ -#define T(offset) (*(union _temp_variable *)((char*)zdata->current_execute_data->Ts + offset)) - -zval *xdebug_get_zval_with_opline(zend_execute_data *zdata, const zend_op *opline, int node_type, const znode_op *node, int *is_var) -{ -#if PHP_VERSION_ID >= 80000 - return zend_get_zval_ptr(opline, node_type, node, zdata); -#else - zend_free_op should_free; - -# if PHP_VERSION_ID >= 70300 - return zend_get_zval_ptr(opline, node_type, node, zdata, &should_free, BP_VAR_IS); -# else - return zend_get_zval_ptr(node_type, node, zdata, &should_free, BP_VAR_IS); -# endif -#endif -} - -zval *xdebug_get_zval(zend_execute_data *zdata, int node_type, const znode_op *node, int *is_var) -{ - return xdebug_get_zval_with_opline(zdata, zdata->opline, node_type, node, is_var); -} - - -/***************************************************************************** -** PHP Variable related utility functions -*/ - -/***************************************************************************** -** Data returning functions -*/ -#define XF_ST_ROOT 0 -#define XF_ST_ARRAY_INDEX_NUM 1 -#define XF_ST_ARRAY_INDEX_ASSOC 2 -#define XF_ST_OBJ_PROPERTY 3 -#define XF_ST_STATIC_ROOT 4 -#define XF_ST_STATIC_PROPERTY 5 -#define XF_ST_ESCAPED_OBJ_PROPERTY 6 - -inline static HashTable *fetch_ht_from_zval(zval *z) -{ - switch (Z_TYPE_P(z)) { - case IS_ARRAY: - return Z_ARRVAL_P(z); - break; - case IS_OBJECT: - return Z_OBJPROP_P(z); - break; - } - return NULL; -} - -inline static char *fetch_classname_from_zval(zval *z, int *length, zend_class_entry **ce) -{ - zend_string *class_name; - - if (Z_TYPE_P(z) == IS_INDIRECT) { - z = z->value.zv; - } - if (Z_TYPE_P(z) == IS_REFERENCE) { - z = &z->value.ref->val; - } - - if (Z_TYPE_P(z) != IS_OBJECT) { - return NULL; - } - - class_name = Z_OBJ_HANDLER_P(z, get_class_name)(Z_OBJ_P(z)); - - *ce = Z_OBJCE_P(z); - *length = class_name->len; - - return estrdup(class_name->val); -} - -static char* prepare_search_key(char *name, unsigned int *name_length, const char *prefix, int prefix_length) -{ - char *element; - int extra_length = 0; - - if (prefix_length) { - if (prefix0 == '*') { - extra_length = 3; - } else { - extra_length = 2 + prefix_length; - } - } - - element = malloc(*name_length + 1 + extra_length); - memset(element, 0, *name_length + 1 + extra_length); - if (extra_length) { - memcpy(element + 1, prefix, extra_length - 2); - } - memcpy(element + extra_length, name, *name_length); - *name_length += extra_length; - - return element; -} - -char *replace_star_by_null(const char *name, int name_length) -{ - char *tmp = xdstrdup(name); - int i; - - for (i = 0; i < name_length; i++) { - if (tmpi == '*') { - tmpi = '\0'; - } - } - - return tmp; -} - -#if PHP_VERSION_ID >= 70400 -static zval *get_arrayobject_storage(zval *parent, HashTable **properties) -{ - *properties = zend_get_properties_for(parent, ZEND_PROP_PURPOSE_DEBUG); - return zend_hash_str_find(*properties, "\0ArrayObject\0storage", sizeof("*ArrayObject*storage") - 1); -} - -static zval *get_splobjectstorage_storage(zval *parent, HashTable **properties) -{ - *properties = zend_get_properties_for(parent, ZEND_PROP_PURPOSE_DEBUG); - return zend_hash_str_find(*properties, "\0SplObjectStorage\0storage", sizeof("*SplObjectStorage*storage") - 1); -} -#else -static zval *get_arrayobject_storage(zval *parent, HashTable **properties, int *is_temp) -{ - *properties = Z_OBJDEBUG_P(parent, *is_temp); - return zend_hash_str_find(*properties, "\0ArrayObject\0storage", sizeof("*ArrayObject*storage") - 1); -} - -static zval *get_splobjectstorage_storage(zval *parent, HashTable **properties, int *is_temp) -{ - *properties = Z_OBJDEBUG_P(parent, *is_temp); - return zend_hash_str_find(*properties, "\0SplObjectStorage\0storage", sizeof("*SplObjectStorage*storage") - 1); -} -#endif - -#if PHP_VERSION_ID < 70400 -void xdebug_var_maybe_destroy_ht(HashTable *ht, int is_temp) -{ - if (ht && is_temp) { - zend_hash_destroy(ht); - FREE_HASHTABLE(ht); - } -} -#endif - -static void fetch_zval_from_symbol_table( - zval *value_in, char *name, unsigned int name_length, - int type, char* ccn, int ccnl, zend_class_entry *cce) -{ - HashTable *ht = NULL; - char *element = NULL; - unsigned int element_length = name_length; - zend_property_info *zpp; -#if PHP_VERSION_ID < 70400 - int is_temp = 0; -#endif - int free_duplicated_name = 0; - HashTable *myht = NULL; - zval *orig_value_in = value_in; - zval tmp_retval; - - ZVAL_UNDEF(&tmp_retval); - - if (Z_TYPE_P(value_in) == IS_INDIRECT) { - value_in = Z_INDIRECT_P(value_in); - } - ZVAL_DEREF(value_in); - - ht = fetch_ht_from_zval(value_in); - - switch (type) { - case XF_ST_STATIC_ROOT: - case XF_ST_STATIC_PROPERTY: - /* First we try a public,private,protected property */ -#if PHP_VERSION_ID >= 70400 - if (cce && (cce->type == ZEND_INTERNAL_CLASS || (cce->ce_flags & ZEND_ACC_IMMUTABLE))) { - zend_class_init_statics(cce); - } -#endif - element = prepare_search_key(name, &element_length, "", 0); - if (cce && ((zpp = zend_hash_str_find_ptr(&cce->properties_info, element, element_length)) != NULL) && cce->default_static_members_count && CE_STATIC_MEMBERS(cce)) { - ZVAL_COPY(&tmp_retval, &CE_STATIC_MEMBERS(cce)zpp->offset); - goto cleanup; - } - element_length = name_length; - - /* Then we try to see whether the first char is * and use the part between * and * as class name for the private property */ - if (name0 == '*') { - char *secondStar; - - secondStar = strstr(name + 1, "*"); - if (secondStar) { - free(element); - element_length = name_length - (secondStar + 1 - name); - element = prepare_search_key(secondStar + 1, &element_length, "", 0); - if (cce && ((zpp = zend_hash_str_find_ptr(&cce->properties_info, element, element_length)) != NULL)) { - ZVAL_COPY(&tmp_retval, &CE_STATIC_MEMBERS(cce)zpp->offset); - goto cleanup; - } - } - } - - break; - - case XF_ST_ROOT: - /* Check for compiled vars */ - element = prepare_search_key(name, &element_length, "", 0); - if (xdebug_lib_has_active_data() && xdebug_lib_has_active_function()) { - int i = 0; - zend_ulong hash_value = zend_inline_hash_func(element, element_length); - zend_op_array *opa = xdebug_lib_get_active_func_oparray(); - zval **CV; - - while (i < opa->last_var) { - if (ZSTR_H(opa->varsi) == hash_value && - ZSTR_LEN(opa->varsi) == element_length && - strncmp(STR_NAME_VAL(opa->varsi), element, element_length) == 0) - { - zval *CV_z = ZEND_CALL_VAR_NUM(xdebug_lib_get_active_data(), i); - CV = &CV_z; - if (CV) { - ZVAL_COPY(&tmp_retval, *CV); - goto cleanup; - } - } - i++; - } - } - free(element); - ht = xdebug_lib_get_active_symbol_table(); - - XDEBUG_BREAK_INTENTIONALLY_MISSING - - case XF_ST_ARRAY_INDEX_ASSOC: - element = prepare_search_key(name, &name_length, "", 0); - xdebug_stripcslashes(element, (int *) &name_length); - - /* Handle "this" in a different way */ - if (type == XF_ST_ROOT && strcmp("this", element) == 0) { - if (xdebug_lib_has_active_object()) { - ZVAL_COPY(&tmp_retval, xdebug_lib_get_active_object()); - } else { - ZVAL_NULL(&tmp_retval); - } - goto cleanup; - } - - if (ht) { - zval *tmp = zend_hash_str_find(ht, element, name_length); - if (tmp != NULL) { - ZVAL_COPY(&tmp_retval, tmp); - goto cleanup; - } - } - break; - - case XF_ST_ARRAY_INDEX_NUM: - element = prepare_search_key(name, &name_length, "", 0); - if (ht) { - zval *tmp = zend_hash_index_find(ht, strtoull(element, NULL, 10)); - if (tmp != NULL) { - ZVAL_COPY(&tmp_retval, tmp); - goto cleanup; - } - } - break; - - case XF_ST_ESCAPED_OBJ_PROPERTY: - name = xdstrndup(name, name_length); - free_duplicated_name = 1; - xdebug_stripcslashes(name, (int *) &name_length); - - XDEBUG_BREAK_INTENTIONALLY_MISSING - - case XF_ST_OBJ_PROPERTY: - /* Let's see if there is a debug handler */ - if (value_in && Z_TYPE_P(value_in) == IS_OBJECT) { -#if PHP_VERSION_ID >= 70400 - myht = xdebug_objdebug_pp(&value_in, XDEBUG_VAR_OBJDEBUG_DEFAULT); -#else - myht = xdebug_objdebug_pp(&value_in, &is_temp, XDEBUG_VAR_OBJDEBUG_DEFAULT); -#endif - if (myht) { - /* As a normal (public) property */ - zval *tmp = zend_symtable_str_find(myht, name, name_length); - if (tmp != NULL) { - ZVAL_COPY(&tmp_retval, tmp); -#if PHP_VERSION_ID >= 70400 - zend_release_properties(myht); -#else - xdebug_var_maybe_destroy_ht(myht, is_temp); -#endif - goto cleanup; - } - - /* As a private property */ - { - char *unmangled = replace_star_by_null(name, name_length); - zval *tmp = zend_symtable_str_find(myht, unmangled, name_length); - if (tmp != NULL) { - ZVAL_COPY(&tmp_retval, tmp); -#if PHP_VERSION_ID >= 70400 - zend_release_properties(myht); -#else - xdebug_var_maybe_destroy_ht(myht, is_temp); -#endif - xdfree(unmangled); - goto cleanup; - } - xdfree(unmangled); - } - -#if PHP_VERSION_ID >= 70400 - zend_release_properties(myht); -#else - xdebug_var_maybe_destroy_ht(myht, is_temp); -#endif - } - } - /* First we try an object handler */ - if (cce) { - zval *tmp_val; -#if PHP_VERSION_ID >= 80000 - tmp_val = zend_read_property(cce, Z_OBJ_P(value_in), name, name_length, 1, &tmp_retval); -#else - tmp_val = zend_read_property(cce, value_in, name, name_length, 1, &tmp_retval); -#endif - if (tmp_val != &tmp_retval && tmp_val != &EG(uninitialized_zval)) { - ZVAL_COPY(&tmp_retval, tmp_val); - goto cleanup; - } - - if (EG(exception)) { - zend_clear_exception(); - } - } - - /* Then we try a public property */ - element = prepare_search_key(name, &element_length, "", 0); - if (ht) { - zval *tmp = zend_symtable_str_find(ht, element, element_length); - if (tmp != NULL) { - ZVAL_COPY(&tmp_retval, tmp); - goto cleanup; - } - } - element_length = name_length; - - /* Then we try it again as protected property */ - free(element); - element = prepare_search_key(name, &element_length, "*", 1); - if (ht) { - zval *tmp = zend_hash_str_find(ht, element, element_length); - if (tmp != NULL) { - ZVAL_COPY(&tmp_retval, tmp); - goto cleanup; - } - } - element_length = name_length; - - /* Then we try it again as private property */ - free(element); - element = prepare_search_key(name, &element_length, ccn, ccnl); - if (ht) { - zval *tmp = zend_hash_str_find(ht, element, element_length); - if (tmp != NULL) { - ZVAL_COPY(&tmp_retval, tmp); - goto cleanup; - } - } - element_length = name_length; - - if (strncmp(ccn, "ArrayObject", ccnl) == 0 && strncmp(name, "storage", name_length) == 0) { -#if PHP_VERSION_ID >= 70400 - zval *tmp = get_arrayobject_storage(value_in, &myht); -#else - zval *tmp = get_arrayobject_storage(value_in, &myht, &is_temp); -#endif - element = NULL; - if (tmp != NULL) { - ZVAL_COPY(&tmp_retval, tmp); -#if PHP_VERSION_ID >= 70400 - zend_release_properties(myht); -#else - xdebug_var_maybe_destroy_ht(myht, is_temp); -#endif - goto cleanup; - } -#if PHP_VERSION_ID >= 70400 - zend_release_properties(myht); -#else - xdebug_var_maybe_destroy_ht(myht, is_temp); -#endif - } - - /* All right, time for a mega hack. It's SplObjectStorage access time! */ - if (strncmp(ccn, "SplObjectStorage", ccnl) == 0 && strncmp(name, "storage", name_length) == 0) { -#if PHP_VERSION_ID >= 70400 - zval *tmp = get_splobjectstorage_storage(value_in, &myht); -#else - zval *tmp = get_splobjectstorage_storage(value_in, &myht, &is_temp); -#endif - element = NULL; - if (tmp != NULL) { - ZVAL_COPY(&tmp_retval, tmp); -#if PHP_VERSION_ID >= 70400 - zend_release_properties(myht); -#else - xdebug_var_maybe_destroy_ht(myht, is_temp); -#endif - goto cleanup; - } -#if PHP_VERSION_ID >= 70400 - zend_release_properties(myht); -#else - xdebug_var_maybe_destroy_ht(myht, is_temp); -#endif - } - - break; - } - -cleanup: - if (element) { - free(element); - } - if (free_duplicated_name && name) { - xdfree(name); - } - - zval_ptr_dtor_nogc(orig_value_in); - ZVAL_COPY_VALUE(orig_value_in, &tmp_retval); -} - -inline static int is_objectish(zval *value) -{ - switch (Z_TYPE_P(value)) { - case IS_OBJECT: - return 1; - - case IS_INDIRECT: - if (Z_TYPE_P(Z_INDIRECT_P(value)) == IS_OBJECT) { - return 1; - } - break; - - case IS_REFERENCE: - if (Z_TYPE_P(Z_REFVAL_P(value)) == IS_OBJECT) { - return 1; - } - break; - } - - return 0; -} - -void xdebug_get_php_symbol(zval *retval, xdebug_str* name) -{ - int found = -1; - int state = 0; - char *ptr = name->d; - size_t ctr = 0; - char *keyword = NULL, *keyword_end = NULL; - int type = XF_ST_ROOT; - char *current_classname = NULL; - zend_class_entry *current_ce = NULL; - int cc_length = 0; - char quotechar = 0; - - ZVAL_UNDEF(retval); - - do { - if (ctr == name->l) { - found = 0; - } else { - switch (state) { - case 0: - if (ptrctr == '$') { - keyword = &ptrctr + 1; - break; - } - if (ptrctr == ':') { /* special tricks */ - keyword = &ptrctr; - state = 7; - break; - } - keyword = &ptrctr; - state = 1; - - XDEBUG_BREAK_INTENTIONALLY_MISSING - - case 1: - if (ptrctr == '') { - keyword_end = &ptrctr; - if (keyword) { - fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); - if (current_classname) { - efree(current_classname); - } - current_classname = NULL; - cc_length = 0; - current_ce = NULL; - keyword = NULL; - } - state = 3; - } else if (ptrctr == '-') { - keyword_end = &ptrctr; - if (keyword) { - fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); - if (current_classname) { - efree(current_classname); - } - current_classname = NULL; - cc_length = 0; - current_ce = NULL; - if (is_objectish(retval)) { - current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce); - } - keyword = NULL; - } - state = 2; - type = XF_ST_OBJ_PROPERTY; - } else if (ptrctr == ':') { - keyword_end = &ptrctr; - if (keyword) { - fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); - if (current_classname) { - efree(current_classname); - } - current_classname = NULL; - cc_length = 0; - if (is_objectish(retval)) { - current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce); - } - keyword = NULL; - } - state = 8; - type = XF_ST_STATIC_PROPERTY; - } - break; - case 2: - if (ptrctr != '>') { - if (ptrctr == '{') { - state = 11; - } else { - keyword = &ptrctr; - state = 1; - } - } - break; - case 8: - if (ptrctr != ':') { - keyword = &ptrctr; - state = 1; - } - break; - case 3: /* Parsing in ... */ - /* Associative arrays */ - if (ptrctr == '\'' || ptrctr == '"') { - state = 4; - keyword = &ptrctr + 1; - quotechar = ptrctr; - type = XF_ST_ARRAY_INDEX_ASSOC; - } - /* Numerical index */ - if (ptrctr >= '0' && ptrctr <= '9') { - cc_length = 0; - state = 6; - keyword = &ptrctr; - type = XF_ST_ARRAY_INDEX_NUM; - } - /* Numerical index starting with a - */ - if (ptrctr == '-') { - state = 9; - keyword = &ptrctr; - } - break; - case 9: - /* Numerical index starting with a - */ - if (ptrctr >= '0' && ptrctr <= '9') { - state = 6; - type = XF_ST_ARRAY_INDEX_NUM; - } - break; - case 4: - if (ptrctr == '\\') { - state = 10; /* Escaped character */ - } else if (ptrctr == quotechar) { - quotechar = 0; - state = 5; - keyword_end = &ptrctr; - fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); - if (current_classname) { - efree(current_classname); - } - current_classname = NULL; - cc_length = 0; - if (is_objectish(retval)) { - current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce); - } - keyword = NULL; - } - break; - case 10: /* Escaped character */ - state = 4; - break; - case 5: - if (ptrctr == '') { - state = 1; - } - break; - case 6: - if (ptrctr == '') { - state = 1; - keyword_end = &ptrctr; - fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); - if (current_classname) { - efree(current_classname); - } - current_classname = NULL; - cc_length = 0; - if (is_objectish(retval)) { - current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce); - } - keyword = NULL; - } - break; - case 7: /* special cases, started with a ":" */ - if (ptrctr == ':') { - function_stack_entry *active_fse = xdebug_lib_get_active_stack_entry(); - state = 1; - keyword_end = &ptrctr; - - if (strncmp(keyword, "::", 2) == 0 && active_fse->function.object_class) { /* static class properties */ - zend_class_entry *ce = zend_fetch_class(active_fse->function.object_class, ZEND_FETCH_CLASS_SELF); - - current_classname = estrdup(STR_NAME_VAL(ce->name)); - cc_length = strlen(STR_NAME_VAL(ce->name)); - current_ce = ce; - keyword = &ptrctr + 1; - - type = XF_ST_STATIC_ROOT; - } else { - keyword = NULL; - } - } - break; - - case 11: - if (ptrctr == '\'' || ptrctr == '"') { - state = 12; - keyword = &ptrctr + 1; - quotechar = ptrctr; - type = XF_ST_ESCAPED_OBJ_PROPERTY; - } - break; - - case 12: /* Inside {" */ - if (ptrctr == '\\') { - state = 13; /* Escaped character */ - } else if (ptrctr == quotechar) { - quotechar = 0; - state = 14; - keyword_end = &ptrctr; - fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); - if (current_classname) { - efree(current_classname); - } - current_classname = NULL; - cc_length = 0; - if (is_objectish(retval)) { - current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce); - } - keyword = NULL; - } - break; - case 13: /* Escaped character */ - state = 12; - break; - case 14: - if (ptrctr == '}') { - state = 1; - } - break; - } - ctr++; - } - } while (found < 0); - if (keyword != NULL) { - fetch_zval_from_symbol_table(retval, keyword, &ptrctr - keyword, type, current_classname, cc_length, current_ce); - } - if (current_classname) { - efree(current_classname); - } -} - - -#if PHP_VERSION_ID >= 70400 -xdebug_str* xdebug_get_property_type(zval* object, zval *val) -{ - xdebug_str *type_str = NULL; - zend_property_info *info; - - if (Z_TYPE_P(val) != IS_INDIRECT) { - return NULL; - } - val = Z_INDIRECT_P(val); - - info = zend_get_typed_property_info_for_slot(Z_OBJ_P(object), val); - - if (info) { -#if PHP_VERSION_ID >= 80000 - zend_string *type_info = zend_type_to_string(info->type); - type_str = xdebug_str_new(); - -# if PHP_VERSION_ID >= 80100 - if (info->flags & ZEND_ACC_READONLY) { - xdebug_str_add_literal(type_str, "readonly "); - } -# endif - - xdebug_str_add_zstr(type_str, type_info); - - zend_string_release(type_info); - -#else - type_str = xdebug_str_new(); - - if (ZEND_TYPE_ALLOW_NULL(info->type)) { - xdebug_str_addc(type_str, '?'); - } - if (ZEND_TYPE_IS_CLASS(info->type)) { - xdebug_str_add( - type_str, - ZSTR_VAL( - ZEND_TYPE_IS_CE(info->type) ? ZEND_TYPE_CE(info->type)->name : ZEND_TYPE_NAME(info->type) - ), - 0 - ); - } else { - xdebug_str_add(type_str, zend_get_type_by_const(ZEND_TYPE_CODE(info->type)), 0); - } -#endif - } - - return type_str; -} -#endif - -xdebug_str* xdebug_get_property_info(char *mangled_property, int mangled_len, const char **modifier, char **class_name) -{ - const char *cls_name, *tmp_prop_name; - size_t tmp_prop_name_len; - xdebug_str *property_name; - - zend_string *i_mangled = zend_string_init(mangled_property, mangled_len - 1, 0); - zend_unmangle_property_name_ex(i_mangled, &cls_name, &tmp_prop_name, &tmp_prop_name_len); - property_name = xdebug_str_create((char*) tmp_prop_name, tmp_prop_name_len); - *class_name = cls_name ? xdstrdup(cls_name) : NULL; - zend_string_release(i_mangled); - - if (*class_name) { - if (*class_name0 == '*') { - *modifier = "protected"; - } else { - *modifier = "private"; - } - } else { - *modifier = "public"; - } - - return property_name; -} - -#define XDEBUG_MAX_INT 2147483647 - -xdebug_var_export_options* xdebug_var_export_options_from_ini(void) -{ - xdebug_var_export_options *options; - options = xdmalloc(sizeof(xdebug_var_export_options)); - - options->max_children = XINI_LIB(display_max_children); - options->max_data = XINI_LIB(display_max_data); - options->max_depth = XINI_LIB(display_max_depth); - options->show_hidden = 0; - options->show_location = 1; - options->extended_properties = 0; - options->encode_as_extended_property = 0; - - if (options->max_children == -1 || options->max_children > XDEBUG_MAX_INT) { - options->max_children = XDEBUG_MAX_INT; - } else if (options->max_children < 1) { - options->max_children = 0; - } - - if (options->max_data == -1 || options->max_data > XDEBUG_MAX_INT) { - options->max_data = XDEBUG_MAX_INT; - } else if (options->max_data < 1) { - options->max_data = 0; - } - - if (options->max_depth == -1 || options->max_depth > 1023) { - options->max_depth = 1023; - } else if (options->max_depth < 1) { - options->max_depth = 0; - } - - options->runtime = (xdebug_var_runtime_page*) xdmalloc((options->max_depth + 1) * sizeof(xdebug_var_runtime_page)); - options->no_decoration = 0; - - return options; -} - -xdebug_var_export_options xdebug_var_nolimit_options = { XDEBUG_MAX_INT, XDEBUG_MAX_INT, 1023, 1, 0, 0, 0, NULL, 0 }; - -xdebug_var_export_options* xdebug_var_get_nolimit_options(void) -{ - return &xdebug_var_nolimit_options; -} - -/***************************************************************************** -** Normal variable printing routines -*/ - -#define XDEBUG_VAR_ATTR_TEXT 0 -#define XDEBUG_VAR_ATTR_FANCY 1 - -void xdebug_add_variable_attributes(xdebug_str *str, zval *struc, zend_bool html) -{ - if (html) { - xdebug_str_add_literal(str, "<i>("); - } else { - xdebug_str_add_literal(str, "("); - } - - if (Z_TYPE_P(struc) >= IS_STRING && Z_TYPE_P(struc) != IS_INDIRECT) { - if (Z_TYPE_P(struc) == IS_STRING && ZSTR_IS_INTERNED(Z_STR_P(struc))) { - xdebug_str_add_literal(str, "interned"); - } else if (Z_TYPE_P(struc) == IS_ARRAY && (GC_FLAGS(Z_ARRVAL_P(struc)) & IS_ARRAY_IMMUTABLE)) { - xdebug_str_add_literal(str, "immutable"); - } else { - xdebug_str_add_fmt(str, "refcount=%d", Z_REFCOUNT_P(struc)); - } - xdebug_str_add_fmt(str, ", is_ref=%d", Z_TYPE_P(struc) == IS_REFERENCE); - } else { - xdebug_str_add_literal(str, "refcount=0, is_ref=0"); - } - - if (html) { - xdebug_str_add_literal(str, ")</i>"); - } else { - xdebug_str_add_literal(str, ")="); - } -} - - -/***************************************************************************** -** XML encoding function -*/ -static const char xml_encode_count256 = { - 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 5, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 6, 1, 1, 1, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 4, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -}; - -static const char* xml_encode_map64 = { - "�", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, " ", NULL, NULL, " ", NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, """, NULL, NULL, NULL, "&", "'", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "<", NULL, ">", NULL, -}; - -char* xdebug_xmlize(char *s_string, size_t len, size_t *newlen) -{ - int i, w_pos; - int encoded_string_length = 0; - char *new_string; - const unsigned char *string = (unsigned char*) s_string; - - /* Quick bailout for empty strings */ - if (!len) { - *newlen = 0; - return estrdup(""); - } - - /* Calculate new memory requirement */ - for (i = 0; i < len; i++) { - encoded_string_length += xml_encode_countstringi; - } - - /* No characters need to be encoded, so just duplicate and return */ - if (encoded_string_length == len) { - *newlen = len; - return estrdup(s_string); - } - - new_string = emalloc(encoded_string_length + 1); - w_pos = 0; - for (i = 0; i < len; i++) { - int replacement_length = xml_encode_countstringi; - - if (replacement_length != 1) { - int j; - - for (j = 0; j < replacement_length; j++) { - new_stringw_pos = xml_encode_mapstringij; - w_pos++; - } - continue; - } - - new_stringw_pos = stringi; - w_pos++; - } - - new_stringw_pos = '\0'; - *newlen = encoded_string_length; /* remove one for null byte */ - - return new_string; -} - -/***************************************************************************** -** Function name printing function -*/ -static char* xdebug_create_doc_link(xdebug_func f) -{ - char *tmp_target = NULL, *p, *retval; - - switch (f.type) { - case XFUNC_NORMAL: { - tmp_target = xdebug_sprintf("function.%s", f.function); - break; - } - - case XFUNC_STATIC_MEMBER: - case XFUNC_MEMBER: { - if (strcmp(f.function, "__construct") == 0) { - tmp_target = xdebug_sprintf("%s.construct", ZSTR_VAL(f.object_class)); - } else { - tmp_target = xdebug_sprintf("%s.%s", ZSTR_VAL(f.object_class), f.function); - } - break; - } - } - - while ((p = strchr(tmp_target, '_')) != NULL) { - *p = '-'; - } - - retval = xdebug_sprintf("<a href='%s%s%s' target='_new'>%s</a>", - (PG(docref_root) && PG(docref_root)0) ? PG(docref_root) : "http://www.php.net/", - tmp_target, PG(docref_ext), f.function); - - xdfree(tmp_target); - - return retval; -} - -char* xdebug_show_fname(xdebug_func f, int flags) -{ - switch (f.type) { - case XFUNC_NORMAL: { - if (PG(html_errors) && (flags & XDEBUG_SHOW_FNAME_ALLOW_HTML) && f.internal) { - return xdebug_create_doc_link(f); - } else { - return xdstrdup(f.function); - } - break; - } - - case XFUNC_STATIC_MEMBER: - case XFUNC_MEMBER: { - if (PG(html_errors) && (flags & XDEBUG_SHOW_FNAME_ALLOW_HTML) && f.internal) { - return xdebug_create_doc_link(f); - } else { - if (f.scope_class && !(flags & XDEBUG_SHOW_FNAME_IGNORE_SCOPE)) { - return xdebug_sprintf("%s%s%s", - ZSTR_VAL(f.scope_class), - f.type == XFUNC_STATIC_MEMBER ? "::" : "->", - f.function ? f.function : "?" - ); - } - - return xdebug_sprintf("%s%s%s", - f.object_class ? ZSTR_VAL(f.object_class) : "?", - f.type == XFUNC_STATIC_MEMBER ? "::" : "->", - f.function ? f.function : "?" - ); - } - break; - } - - case XFUNC_EVAL: - return xdstrdup("eval"); - break; - - case XFUNC_INCLUDE: - return xdstrdup("include"); - break; - - case XFUNC_INCLUDE_ONCE: - return xdstrdup("include_once"); - break; - - case XFUNC_REQUIRE: - return xdstrdup("require"); - break; - - case XFUNC_REQUIRE_ONCE: - return xdstrdup("require_once"); - break; - - case XFUNC_MAIN: - return xdstrdup("{main}"); - break; - - case XFUNC_ZEND_PASS: - return xdstrdup("{zend_pass}"); - break; - -#if PHP_VERSION_ID >= 80100 - case XFUNC_FIBER: - return xdstrdup(f.function); - break; -#endif - - default: - return xdstrdup("{unknown}"); - } -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/var.h
Deleted
@@ -1,96 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "zend.h" -#include "php_xdebug.h" - -#include "lib/compat.h" -#include "lib/lib.h" -#include "lib/str.h" -#include "lib/xml.h" - -#ifndef __HAVE_XDEBUG_VAR_H__ -#define __HAVE_XDEBUG_VAR_H__ - -/* Set correct int format to use */ -#include "Zend/zend_long.h" -#if SIZEOF_ZEND_LONG == 4 -# define XDEBUG_INT_FMT "%ld" -#else -# define XDEBUG_INT_FMT "%lld" -#endif - -typedef struct -{ - int page; /* The number of the page to retrieve */ - int current_element_nr; - int start_element_nr; - int end_element_nr; -} xdebug_var_runtime_page; - -typedef struct xdebug_var_export_options { - int max_children; - int max_data; - int max_depth; - int show_hidden; - int extended_properties; /* Whether the feature is enabled */ - int encode_as_extended_property; /* Whether the current node's elements need to be encoded */ - int show_location; - xdebug_var_runtime_page *runtime; - int no_decoration; -} xdebug_var_export_options; - -#define XDEBUG_VAR_TYPE_NORMAL 0x00 -#define XDEBUG_VAR_TYPE_STATIC 0x01 -#define XDEBUG_VAR_TYPE_CONSTANT 0x02 - -void xdebug_get_php_symbol(zval *retval, xdebug_str* name); - -xdebug_var_export_options* xdebug_var_export_options_from_ini(void); -xdebug_var_export_options* xdebug_var_get_nolimit_options(void); - -#if PHP_VERSION_ID >= 70400 -xdebug_str* xdebug_get_property_type(zval* object, zval *val); -#endif -xdebug_str* xdebug_get_property_info(char *mangled_property, int mangled_len, const char **modifier, char **class_name); - -#define XDEBUG_VAR_OBJDEBUG_DEFAULT 0x00 -#define XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO 0x01 -#if PHP_VERSION_ID >= 70400 -HashTable *xdebug_objdebug_pp(zval **zval_pp, int flags); -#else -HashTable *xdebug_objdebug_pp(zval **zval_pp, int *is_tmp, int flags); -void xdebug_var_maybe_destroy_ht(HashTable *ht, int is_temp); -#endif - - -#define XDEBUG_VAR_ATTR_TEXT 0 -#define XDEBUG_VAR_ATTR_HTML 1 -void xdebug_add_variable_attributes(xdebug_str *str, zval *struc, zend_bool fancy); - - -char* xdebug_xmlize(char *s_string, size_t len, size_t *newlen); -char* xdebug_error_type_simple(int type); -char* xdebug_error_type(int type); -zval *xdebug_get_zval(zend_execute_data *zdata, int node_type, const znode_op *node, int *is_var); -zval *xdebug_get_zval_with_opline(zend_execute_data *zdata, const zend_op *opline, int node_type, const znode_op *node, int *is_var); - -#define XDEBUG_SHOW_FNAME_DEFAULT 0 -#define XDEBUG_SHOW_FNAME_ALLOW_HTML 1<<1 -#define XDEBUG_SHOW_FNAME_IGNORE_SCOPE 1<<2 -char* xdebug_show_fname(xdebug_func t, int flags); - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/var_export_html.c
Deleted
@@ -1,479 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "var_export_html.h" -#include "lib_private.h" -#include "Zend/zend_closures.h" -#if PHP_VERSION_ID >= 80100 -# include "zend_enum.h" -#endif - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -/***************************************************************************** -** Fancy variable printing routines -*/ - -#define COLOR_POINTER "#888a85" -#define COLOR_BOOL "#75507b" -#define COLOR_LONG "#4e9a06" -#define COLOR_NULL "#3465a4" -#define COLOR_DOUBLE "#f57900" -#define COLOR_STRING "#cc0000" -#define COLOR_EMPTY "#888a85" -#define COLOR_ARRAY "#ce5c00" -#define COLOR_OBJECT "#8f5902" -#define COLOR_RESOURCE "#2e3436" - -static int xdebug_array_element_export_html(zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, xdebug_str *str, int debug_zval, xdebug_var_export_options *options) -{ - zval **zv = &zv_nptr; - size_t newlen; - char *tmp_str; - - if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && - options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) - { - xdebug_str_add_fmt(str, "%*s", (level * 4) - 2, ""); - - if (HASH_KEY_IS_NUMERIC(hash_key)) { /* numeric key */ - xdebug_str_add_fmt(str, XDEBUG_INT_FMT " <font color='%s'>=></font> ", index_key, COLOR_POINTER); - } else { /* string key */ - xdebug_str_addc(str, '\''); - tmp_str = xdebug_xmlize((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key) - 1, &newlen); - xdebug_str_addl(str, tmp_str, newlen, 0); - efree(tmp_str); - xdebug_str_add_fmt(str, "' <font color='%s'>=></font> ", COLOR_POINTER); - } - xdebug_var_export_html(zv, str, level + 1, debug_zval, options); - } - if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { - xdebug_str_add_fmt(str, "%*s", (level * 4) - 2, ""); - xdebug_str_add_literal(str, "<i>more elements...</i>\n"); - } - options->runtimelevel.current_element_nr++; - return 0; -} - -static int xdebug_object_element_export_html(zval *object, zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, xdebug_str *str, int debug_zval, xdebug_var_export_options *options, char *class_name) -{ - zval **zv = &zv_nptr; - - if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && - options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) - { - xdebug_str_add_fmt(str, "%*s", (level * 4) - 2, ""); - - if (!HASH_KEY_IS_NUMERIC(hash_key)) { - char *prop_class_name; - xdebug_str *property_name; - xdebug_str *property_type = NULL; - const char *modifier; - -#if PHP_VERSION_ID >= 70400 - property_type = xdebug_get_property_type(object, zv_nptr); -#endif - property_name = xdebug_get_property_info((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key), &modifier, &prop_class_name); - - xdebug_str_add_fmt(str, "<i>%s</i> ", modifier); - if (property_type) { - xdebug_str_add_fmt(str, "<i>%s</i> ", property_type->d); - } - xdebug_str_addc(str, '\''); - xdebug_str_add_str(str, property_name); - if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) { - xdebug_str_add_fmt(str, "' <font color='%s'>=></font> ", COLOR_POINTER); - } else { - xdebug_str_add_fmt(str, "' <small>(%s)</small> <font color='%s'>=></font> ", prop_class_name, COLOR_POINTER); - } - - if (property_type) { - xdebug_str_free(property_type); - } - xdebug_str_free(property_name); - xdfree(prop_class_name); - } else { - xdebug_str_add_fmt(str, "<i>public</i> " XDEBUG_INT_FMT " <font color='%s'>=></font> ", index_key, COLOR_POINTER); - } - xdebug_var_export_html(zv, str, level + 1, debug_zval, options); - } - if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { - xdebug_str_add_fmt(str, "%*s", (level * 4) - 2, ""); - xdebug_str_add_literal(str, "<i>more elements...</i>\n"); - } - options->runtimelevel.current_element_nr++; - return 0; -} - -static void handle_closure(xdebug_str *str, zval *obj, int level) -{ - const zend_function *closure_function; - - if (Z_TYPE_P(obj) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(obj), zend_ce_closure)) { - return; - } - -#if PHP_VERSION_ID >= 80000 - closure_function = zend_get_closure_method_def(Z_OBJ_P(obj)); -#else - closure_function = zend_get_closure_method_def(obj); -#endif - - xdebug_str_add_fmt(str, "%*s<i>virtual</i> 'closure' <font color='%s'>'", (level * 4) - 2, "", COLOR_STRING); - - if (closure_function->common.scope) { - if (closure_function->common.fn_flags & ZEND_ACC_STATIC) { - xdebug_str_add_zstr(str, closure_function->common.scope->name); - xdebug_str_add_literal(str, "::"); - } else { - xdebug_str_add_literal(str, "$this->"); - } - } - xdebug_str_add_zstr(str, closure_function->common.function_name); - - xdebug_str_add_literal(str, "'</font>\n"); -} - - -void xdebug_var_export_html(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options) -{ - HashTable *myht; - char* tmp_str; - size_t newlen; -#if PHP_VERSION_ID < 70400 - int is_temp; -#endif - zend_ulong num; - zend_string *key; - zval *val; - zval *tmpz; - int z_type; - - z_type = Z_TYPE_P(*struc); - - if (debug_zval) { - xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_HTML); - } - if (z_type == IS_INDIRECT) { - tmpz = Z_INDIRECT_P(*struc); - struc = &tmpz; - z_type = Z_TYPE_P(*struc); - } - if (z_type == IS_REFERENCE) { - tmpz = &((*struc)->value.ref->val); - struc = &tmpz; - z_type = Z_TYPE_P(*struc); - } - - switch (z_type) { - case IS_TRUE: - xdebug_str_add_fmt(str, "<small>boolean</small> <font color='%s'>true</font>", COLOR_BOOL); - break; - - case IS_FALSE: - xdebug_str_add_fmt(str, "<small>boolean</small> <font color='%s'>false</font>", COLOR_BOOL); - break; - - case IS_NULL: - xdebug_str_add_fmt(str, "<font color='%s'>null</font>", COLOR_NULL); - break; - - case IS_LONG: - xdebug_str_add_fmt(str, "<small>int</small> <font color='%s'>" XDEBUG_INT_FMT "</font>", COLOR_LONG, Z_LVAL_P(*struc)); - break; - - case IS_DOUBLE: - xdebug_str_add_fmt(str, "<small>float</small> <font color='%s'>%.*G</font>", COLOR_DOUBLE, (int) EG(precision), Z_DVAL_P(*struc)); - break; - - case IS_STRING: - xdebug_str_add_fmt(str, "<small>string</small> <font color='%s'>'", COLOR_STRING); - if ((size_t) Z_STRLEN_P(*struc) > (size_t) options->max_data) { - tmp_str = xdebug_xmlize(Z_STRVAL_P(*struc), options->max_data, &newlen); - xdebug_str_addl(str, tmp_str, newlen, 0); - efree(tmp_str); - xdebug_str_add_literal(str, "'...</font>"); - } else { - tmp_str = xdebug_xmlize(Z_STRVAL_P(*struc), Z_STRLEN_P(*struc), &newlen); - xdebug_str_addl(str, tmp_str, newlen, 0); - efree(tmp_str); - xdebug_str_add_literal(str, "'</font>"); - } - xdebug_str_add_fmt(str, " <i>(length=%d)</i>", Z_STRLEN_P(*struc)); - break; - - case IS_ARRAY: - myht = Z_ARRVAL_P(*struc); - xdebug_str_add_fmt(str, "\n%*s", (level - 1) * 4, ""); - - if (!xdebug_zend_hash_is_recursive(myht)) { - xdebug_str_add_fmt(str, "<b>array</b> <i>(size=%d)</i>\n", myht->nNumOfElements); - if (level <= options->max_depth) { - if (myht->nNumOfElements) { - options->runtimelevel.current_element_nr = 0; - options->runtimelevel.start_element_nr = 0; - options->runtimelevel.end_element_nr = options->max_children; - - xdebug_zend_hash_apply_protection_begin(myht); - - ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { - xdebug_array_element_export_html(val, num, key, level, str, debug_zval, options); - } ZEND_HASH_FOREACH_END(); - - xdebug_zend_hash_apply_protection_end(myht); - } else { - xdebug_str_add_fmt(str, "%*s", (level * 4) - 2, ""); - xdebug_str_add_fmt(str, "<i><font color='%s'>empty</font></i>\n", COLOR_EMPTY); - } - } else { - xdebug_str_add_fmt(str, "%*s...\n", (level * 4) - 2, ""); - } - } else { - xdebug_str_add_literal(str, "<i>&</i><b>array</b>\n"); - } - break; - - case IS_OBJECT: { -#if PHP_VERSION_ID >= 80100 - zend_class_entry *ce = Z_OBJCE_P(*struc); - if (ce->ce_flags & ZEND_ACC_ENUM) { - zval *case_name_zval = zend_enum_fetch_case_name(Z_OBJ_P(*struc)); - xdebug_str_add_fmt( - str, "<b>enum</b>(<i>%s::%s</i>)", - ZSTR_VAL(ce->name), - Z_STRVAL_P(case_name_zval) - ); - if (ce->enum_backing_type != IS_UNDEF) { - zval *value = zend_enum_fetch_case_value(Z_OBJ_P(*struc)); - - if (ce->enum_backing_type == IS_LONG) { - xdebug_str_add_fmt( - str, " : <small>int</small> <font color='%s'>" XDEBUG_INT_FMT "</font>", - COLOR_LONG, Z_LVAL_P(value) - ); - } - - if (ce->enum_backing_type == IS_STRING) { - xdebug_str_add_fmt( - str, " : <small>string</small> <font color='%s'>'%s'</font> <i>(length=%d)</i>", - COLOR_STRING, Z_STRVAL_P(value), Z_STRLEN_P(value) - ); - } - } - xdebug_str_addc(str, '\n'); - break; - } -#endif - -#if PHP_VERSION_ID >= 70400 - myht = xdebug_objdebug_pp(struc, XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO); -#else - myht = xdebug_objdebug_pp(struc, &is_temp, XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO); -#endif - xdebug_str_add_fmt(str, "\n%*s", (level - 1) * 4, ""); - - if (!myht || !xdebug_zend_hash_is_recursive(myht)) { - xdebug_str_add_literal(str, "<b>object</b>(<i>"); - xdebug_str_add(str, ZSTR_VAL(Z_OBJCE_P(*struc)->name), 0); - xdebug_str_add_literal(str, "</i>)"); - xdebug_str_add_fmt(str, "<i>%d</i>\n", Z_OBJ_HANDLE_P(*struc)); - - handle_closure(str, *struc, level); - - if (myht && (level <= options->max_depth)) { - options->runtimelevel.current_element_nr = 0; - options->runtimelevel.start_element_nr = 0; - options->runtimelevel.end_element_nr = options->max_children; - - xdebug_zend_hash_apply_protection_begin(myht); - - ZEND_HASH_FOREACH_KEY_VAL(myht, num, key, val) { - xdebug_object_element_export_html(*struc, val, num, key, level, str, debug_zval, options, ZSTR_VAL(Z_OBJCE_P(*struc)->name)); - } ZEND_HASH_FOREACH_END(); - - xdebug_zend_hash_apply_protection_end(myht); - } else { - xdebug_str_add_fmt(str, "%*s...\n", (level * 4) - 2, ""); - } - } else { - xdebug_str_add_literal(str, "<i>&</i><b>object</b>(<i>"); - xdebug_str_add(str, ZSTR_VAL(Z_OBJCE_P(*struc)->name), 0); - xdebug_str_add_literal(str, "</i>)"); - xdebug_str_add_fmt(str, "<i>%d</i>\n", Z_OBJ_HANDLE_P(*struc)); - } -#if PHP_VERSION_ID >= 70400 - zend_release_properties(myht); -#else - xdebug_var_maybe_destroy_ht(myht, is_temp); -#endif - break; - } - - case IS_RESOURCE: { - char *type_name; - - type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); - xdebug_str_add_fmt(str, "<b>resource</b>(<i>%ld</i><font color='%s'>,</font> <i>%s</i>)", Z_RES_P(*struc)->handle, COLOR_RESOURCE, type_name ? type_name : "Unknown"); - break; - } - - case IS_UNDEF: - xdebug_str_add_fmt(str, "<font color='%s'>*uninitialized*</font>", COLOR_NULL); - break; - - default: - xdebug_str_add_fmt(str, "<font color='%s'>NFC</font>", COLOR_NULL); - break; - } - if (z_type != IS_ARRAY && z_type != IS_OBJECT) { - xdebug_str_addc(str, '\n'); - } -} - -xdebug_str* xdebug_get_zval_value_html(char *name, zval *val, int debug_zval, xdebug_var_export_options *options) -{ - xdebug_str *str = xdebug_str_new(); - int default_options = 0; - - if (!options) { - options = xdebug_var_export_options_from_ini(); - default_options = 1; - } - - xdebug_str_add_literal(str, "<pre class='xdebug-var-dump' dir='ltr'>"); - if (options->show_location && !debug_zval) { - char *formatted_filename; - xdebug_format_filename(&formatted_filename, "%f", zend_get_executed_filename_ex()); - - if (strlen(XINI_LIB(file_link_format)) > 0 && strcmp(zend_get_executed_filename(), "Unknown") != 0) { - char *file_link; - - xdebug_format_file_link(&file_link, zend_get_executed_filename(), zend_get_executed_lineno()); - xdebug_str_add_fmt(str, "\n<small><a href='%s'>%s:%d</a>:</small>", file_link, formatted_filename, zend_get_executed_lineno()); - xdfree(file_link); - } else { - xdebug_str_add_fmt(str, "\n<small>%s:%d:</small>", formatted_filename, zend_get_executed_lineno()); - } - - xdfree(formatted_filename); - } - xdebug_var_export_html(&val, str, 1, debug_zval, options); - xdebug_str_add_literal(str, "</pre>"); - - if (default_options) { - xdfree(options->runtime); - xdfree(options); - } - - return str; -} - -static void xdebug_var_synopsis_html(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options) -{ - HashTable *myht; - zval *tmpz; - int z_type; - - z_type = Z_TYPE_P(*struc); - - if (debug_zval) { - xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_HTML); - } - if (z_type == IS_REFERENCE) { - tmpz = &((*struc)->value.ref->val); - struc = &tmpz; - } - - switch (z_type) { - case IS_TRUE: - xdebug_str_add_fmt(str, "<font color='%s'>true</font>", COLOR_BOOL); - break; - - case IS_FALSE: - xdebug_str_add_fmt(str, "<font color='%s'>false</font>", COLOR_BOOL); - break; - - case IS_NULL: - xdebug_str_add_fmt(str, "<font color='%s'>null</font>", COLOR_NULL); - break; - - case IS_LONG: - xdebug_str_add_fmt(str, "<font color='%s'>long</font>", COLOR_LONG); - break; - - case IS_DOUBLE: - xdebug_str_add_fmt(str, "<font color='%s'>double</font>", COLOR_DOUBLE); - break; - - case IS_STRING: - xdebug_str_add_fmt(str, "<font color='%s'>string(%d)</font>", COLOR_STRING, Z_STRLEN_P(*struc)); - break; - - case IS_ARRAY: - myht = Z_ARRVAL_P(*struc); - xdebug_str_add_fmt(str, "<font color='%s'>array(%d)</font>", COLOR_ARRAY, myht->nNumOfElements); - break; - - case IS_OBJECT: { -#if PHP_VERSION_ID >= 80100 - zend_class_entry *ce = Z_OBJCE_P(*struc); - if (ce->ce_flags & ZEND_ACC_ENUM) { - zval *case_name_zval = zend_enum_fetch_case_name(Z_OBJ_P(*struc)); - xdebug_str_add_fmt( str, "<font color='%s'>enum(%s::%s)</font>", COLOR_OBJECT, ZSTR_VAL(ce->name), Z_STRVAL_P(case_name_zval)); - break; - } -#endif - - xdebug_str_add_fmt(str, "<font color='%s'>object(%s)%d</font>", COLOR_OBJECT, ZSTR_VAL(Z_OBJCE_P(*struc)->name), Z_OBJ_HANDLE_P(*struc)); - } break; - - case IS_RESOURCE: { - char *type_name; - - type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); - xdebug_str_add_fmt(str, "<font color='%s'>resource(%ld, %s)</font>", COLOR_RESOURCE, Z_RES_P(*struc)->handle, type_name ? type_name : "Unknown"); - break; - } - - case IS_UNDEF: - xdebug_str_add_fmt(str, "<font color='%s'>*uninitialized*</font>", COLOR_NULL); - break; - - default: - xdebug_str_add_fmt(str, "<font color='%s'>NFC</font>", COLOR_NULL); - break; - } -} - -xdebug_str* xdebug_get_zval_synopsis_html(const char *name, zval *val, int debug_zval, xdebug_var_export_options *options) -{ - xdebug_str *str = xdebug_str_new(); - int default_options = 0; - - if (!options) { - options = xdebug_var_export_options_from_ini(); - default_options = 1; - } - - xdebug_var_synopsis_html(&val, str, 1, debug_zval, options); - - if (default_options) { - xdfree(options->runtime); - xdfree(options); - } - - return str; -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/var_export_line.c
Deleted
@@ -1,474 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "ext/standard/php_string.h" -#include "Zend/zend_closures.h" -#if PHP_VERSION_ID >= 80100 -# include "zend_enum.h" -#endif - -#include "var_export_line.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -static int xdebug_array_element_export(zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, xdebug_str *str, int debug_zval, xdebug_var_export_options *options) -{ - zval **zv = &zv_nptr; - - if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && - options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) - { - if (HASH_KEY_IS_NUMERIC(hash_key)) { /* numeric key */ - xdebug_str_add_fmt(str, XDEBUG_INT_FMT " => ", index_key); - } else { /* string key */ - zend_string *tmp, *tmp2; - - tmp = php_str_to_str(ZSTR_VAL(hash_key), ZSTR_LEN(hash_key), (char*) "'", 1, (char*) "\\'", 2); - tmp2 = php_str_to_str(ZSTR_VAL(tmp), ZSTR_LEN(tmp), (char*) "\0", 1, (char*) "\\0", 2); - if (tmp) { - zend_string_release(tmp); - } - xdebug_str_addc(str, '\''); - if (tmp2) { - xdebug_str_add_zstr(str, tmp2); - zend_string_release(tmp2); - } - xdebug_str_add_literal(str, "' => "); - } - xdebug_var_export_line(zv, str, level + 2, debug_zval, options); - xdebug_str_add_literal(str, ", "); - } - if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { - xdebug_str_add_literal(str, "..., "); - } - options->runtimelevel.current_element_nr++; - return 0; -} - -static int xdebug_object_element_export(zval *object, zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, xdebug_str *str, int debug_zval, xdebug_var_export_options *options, char *class_name) -{ - zval **zv = &zv_nptr; - - if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && - options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) - { - if (!HASH_KEY_IS_NUMERIC(hash_key)) { - xdebug_str *property_name; - xdebug_str *property_type = NULL; - char *prop_class_name; - const char *modifier; - -#if PHP_VERSION_ID >= 70400 - property_type = xdebug_get_property_type(object, zv_nptr); -#endif - property_name = xdebug_get_property_info((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key), &modifier, &prop_class_name); - xdebug_str_add(str, modifier, 0); - if (property_type) { - xdebug_str_addc(str, ' '); - xdebug_str_add_str(str, property_type); - } - xdebug_str_add_literal(str, " $"); - if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) { - xdebug_str_add_str(str, property_name); - xdebug_str_add_literal(str, " = "); - } else { - xdebug_str_addc(str, '{'); - xdebug_str_add(str, prop_class_name, 0); - xdebug_str_addc(str, '}'); - xdebug_str_add_str(str, property_name); - xdebug_str_add_literal(str, " = "); - } - - if (property_type) { - xdebug_str_free(property_type); - } - xdebug_str_free(property_name); - xdfree(prop_class_name); - } else { - xdebug_str_add_fmt(str, "public $%d = ", index_key); - } - xdebug_var_export_line(zv, str, level + 2, debug_zval, options); - xdebug_str_add_literal(str, "; "); - } - if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { - xdebug_str_add_literal(str, "...; "); - } - options->runtimelevel.current_element_nr++; - return 0; -} - -static void handle_closure(xdebug_str *str, zval *obj) -{ - const zend_function *closure_function; - - if (Z_TYPE_P(obj) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(obj), zend_ce_closure)) { - return; - } - -#if PHP_VERSION_ID >= 80000 - closure_function = zend_get_closure_method_def(Z_OBJ_P(obj)); -#else - closure_function = zend_get_closure_method_def(obj); -#endif - - xdebug_str_add_literal(str, "virtual $closure = \""); - - if (closure_function->common.scope) { - if (closure_function->common.fn_flags & ZEND_ACC_STATIC) { - xdebug_str_add_zstr(str, closure_function->common.scope->name); - xdebug_str_add_literal(str, "::"); - } else { - xdebug_str_add_literal(str, "$this->"); - } - } - xdebug_str_add_zstr(str, closure_function->common.function_name); - - xdebug_str_add_literal(str, "\", "); -} - -void xdebug_var_export_line(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options) -{ - HashTable *myht; -#if PHP_VERSION_ID < 70400 - int is_temp; -#endif - zend_ulong num; - zend_string *key; - zval *val; - zval *tmpz; - int z_type; - - if (!struc || !(*struc)) { - return; - } - - z_type = Z_TYPE_P(*struc); - - if (debug_zval) { - xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_TEXT); - } - if (z_type == IS_INDIRECT) { - tmpz = Z_INDIRECT_P(*struc); - struc = &tmpz; - z_type = Z_TYPE_P(*struc); - } - if (z_type == IS_REFERENCE) { - tmpz = &((*struc)->value.ref->val); - struc = &tmpz; - z_type = Z_TYPE_P(*struc); - } - - switch (z_type) { - case IS_TRUE: - xdebug_str_add_literal(str, "TRUE"); - break; - - case IS_FALSE: - xdebug_str_add_literal(str, "FALSE"); - break; - - case IS_NULL: - xdebug_str_add_literal(str, "NULL"); - break; - - case IS_LONG: - xdebug_str_add_fmt(str, XDEBUG_INT_FMT, Z_LVAL_P(*struc)); - break; - - case IS_DOUBLE: - xdebug_str_add_fmt(str, "%.*G", (int) EG(precision), Z_DVAL_P(*struc)); - break; - - case IS_STRING: { - if (options->no_decoration) { - xdebug_str_add_zstr(str, Z_STR_P(*struc)); - } else if ((size_t) Z_STRLEN_P(*struc) <= (size_t) options->max_data) { - zend_string *tmp_zstr; - -#if PHP_VERSION_ID >= 70300 - tmp_zstr = php_addcslashes(Z_STR_P(*struc), (char*) "'\\\0..\37", 7); -#else - tmp_zstr = php_addcslashes(Z_STR_P(*struc), 0, (char*) "'\\\0..\37", 7); -#endif - xdebug_str_addc(str, '\''); - xdebug_str_add_zstr(str, tmp_zstr); - xdebug_str_addc(str, '\''); - - zend_string_release(tmp_zstr); - } else { -#if PHP_VERSION_ID >= 70300 - zend_string *tmp_zstr = php_addcslashes_str(ZSTR_VAL(Z_STR_P(*struc)), options->max_data, (char*) "'\\\0..\37", 7); -#else - zend_string *tmp_zstr = NULL; - zend_string *truncated_zstr = zend_string_copy(Z_STR_P(*struc)); - - truncated_zstr = zend_string_truncate(truncated_zstr, options->max_data, 0); - tmp_zstr = php_addcslashes(truncated_zstr, 0, (char*) "'\\\0..\37", 7); - - zend_string_release(truncated_zstr); -#endif - xdebug_str_addc(str, '\''); - xdebug_str_add_zstr(str, tmp_zstr); - xdebug_str_add_literal(str, "\'..."); - - zend_string_release(tmp_zstr); - } - } break; - - case IS_ARRAY: - myht = Z_ARRVAL_P(*struc); - - if (!xdebug_zend_hash_is_recursive(myht)) { - if (debug_zval) { - xdebug_str_add_literal(str, "array ("); - } else { - xdebug_str_addc(str, ''); - } - if (level <= options->max_depth) { - options->runtimelevel.current_element_nr = 0; - options->runtimelevel.start_element_nr = 0; - options->runtimelevel.end_element_nr = options->max_children; - - xdebug_zend_hash_apply_protection_begin(myht); - - ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { - xdebug_array_element_export(val, num, key, level, str, debug_zval, options); - } ZEND_HASH_FOREACH_END(); - - xdebug_zend_hash_apply_protection_end(myht); - - /* Remove the ", " at the end of the string */ - if (myht->nNumOfElements > 0) { - xdebug_str_chop(str, 2); - } - } else { - xdebug_str_add_literal(str, "..."); - } - xdebug_str_addc(str, debug_zval ? ')' : ''); - } else { - xdebug_str_add_literal(str, "..."); - } - break; - - case IS_OBJECT: { -#if PHP_VERSION_ID >= 80100 - zend_class_entry *ce = Z_OBJCE_P(*struc); - if (ce->ce_flags & ZEND_ACC_ENUM) { - zval *case_name_zval = zend_enum_fetch_case_name(Z_OBJ_P(*struc)); - xdebug_str_add_fmt(str, "enum %s::%s", ZSTR_VAL(ce->name), Z_STRVAL_P(case_name_zval)); - - if (ce->enum_backing_type != IS_UNDEF) { - zval *value = zend_enum_fetch_case_value(Z_OBJ_P(*struc)); - - if (ce->enum_backing_type == IS_LONG) { - xdebug_str_add_fmt(str, "(" XDEBUG_INT_FMT ")", Z_LVAL_P(value)); - } - - if (ce->enum_backing_type == IS_STRING) { - zend_string *tmp_zstr = php_addcslashes(Z_STR_P(value), (char*) "'\\\0..\37", 7); - - xdebug_str_add_literal(str, "('"); - xdebug_str_add_zstr(str, tmp_zstr); - xdebug_str_add_literal(str, "')"); - - zend_string_release(tmp_zstr); - } - } - - break; - } -#endif - -#if PHP_VERSION_ID >= 70400 - myht = xdebug_objdebug_pp(struc, XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO); -#else - myht = xdebug_objdebug_pp(struc, &is_temp, XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO); -#endif - - if (!myht || !xdebug_zend_hash_is_recursive(myht)) { - xdebug_str_add_literal(str, "class "); - xdebug_str_add(str, ZSTR_VAL(Z_OBJCE_P(*struc)->name), 0); - xdebug_str_add_literal(str, " { "); - - handle_closure(str, *struc); - - if (myht && (level <= options->max_depth)) { - options->runtimelevel.current_element_nr = 0; - options->runtimelevel.start_element_nr = 0; - options->runtimelevel.end_element_nr = options->max_children; - - xdebug_zend_hash_apply_protection_begin(myht); - - ZEND_HASH_FOREACH_KEY_VAL(myht, num, key, val) { - xdebug_object_element_export(*struc, val, num, key, level, str, debug_zval, options, ZSTR_VAL(Z_OBJCE_P(*struc)->name)); - } ZEND_HASH_FOREACH_END(); - - xdebug_zend_hash_apply_protection_end(myht); - } else { - xdebug_str_add_literal(str, "..."); - } - /* Remove the ", " and "; " at the end of the string */ - if ( - str->l > 2 && - ((str->dstr->l - 2 == ',') || (str->dstr->l - 2 == ';' )) && - (str->dstr->l - 1 == ' ') - ) { - xdebug_str_chop(str, 2); - } - - xdebug_str_add_literal(str, " }"); - } else { - xdebug_str_add_literal(str, "..."); - } -#if PHP_VERSION_ID >= 70400 - zend_release_properties(myht); -#else - xdebug_var_maybe_destroy_ht(myht, is_temp); -#endif - break; - } - - case IS_RESOURCE: { - char *type_name; - - type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); - xdebug_str_add_fmt(str, "resource(%ld) of type (%s)", Z_RES_P(*struc)->handle, type_name ? type_name : "Unknown"); - break; - } - - case IS_UNDEF: - xdebug_str_add_literal(str, "*uninitialized*"); - break; - - default: - xdebug_str_add_literal(str, "NFC"); - break; - } -} - -xdebug_str* xdebug_get_zval_value_line(zval *val, int debug_zval, xdebug_var_export_options *options) -{ - xdebug_str *str = xdebug_str_new(); - int default_options = 0; - - if (!options) { - options = xdebug_var_export_options_from_ini(); - default_options = 1; - } - - xdebug_var_export_line(&val, str, 1, debug_zval, options); - - if (default_options) { - xdfree(options->runtime); - xdfree(options); - } - - return str; -} - -static void xdebug_var_synopsis(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options) -{ - HashTable *myht; - zval *tmpz; - - if (!struc || !(*struc)) { - return; - } - - if (debug_zval) { - xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_TEXT); - } - if (Z_TYPE_P(*struc) == IS_REFERENCE) { - tmpz = &((*struc)->value.ref->val); - struc = &tmpz; - } - - switch (Z_TYPE_P(*struc)) { - case IS_TRUE: - xdebug_str_add_literal(str, "true"); - break; - - case IS_FALSE: - xdebug_str_add_literal(str, "false"); - break; - - case IS_NULL: - xdebug_str_add_literal(str, "null"); - break; - - case IS_LONG: - xdebug_str_add_literal(str, "long"); - break; - - case IS_DOUBLE: - xdebug_str_add_literal(str, "double"); - break; - - case IS_STRING: - xdebug_str_add_fmt(str, "string(%d)", Z_STRLEN_P(*struc)); - break; - - case IS_ARRAY: - myht = Z_ARRVAL_P(*struc); - xdebug_str_add_fmt(str, "array(%d)", myht->nNumOfElements); - break; - - case IS_OBJECT: { - xdebug_str_add_literal(str, "class "); - xdebug_str_add(str, ZSTR_VAL(Z_OBJCE_P(*struc)->name), 0); - break; - } - - case IS_RESOURCE: { - char *type_name; - - type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); - xdebug_str_add_fmt(str, "resource(%ld) of type (%s)", Z_RES_P(*struc)->handle, type_name ? type_name : "Unknown"); - break; - } - - case IS_UNDEF: - xdebug_str_add_literal(str, "*uninitialized*"); - break; - - default: - xdebug_str_add_literal(str, "NFC"); - break; - - } -} - -xdebug_str* xdebug_get_zval_synopsis_line(zval *val, int debug_zval, xdebug_var_export_options *options) -{ - xdebug_str *str = xdebug_str_new(); - int default_options = 0; - - if (!options) { - options = xdebug_var_export_options_from_ini(); - default_options = 1; - } - - xdebug_var_synopsis(&val, str, 1, debug_zval, options); - - if (default_options) { - xdfree(options->runtime); - xdfree(options); - } - - return str; -} -
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/var_export_text.c
Deleted
@@ -1,523 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "php.h" -#include "ext/standard/php_string.h" -#include "Zend/zend_closures.h" -#if PHP_VERSION_ID >= 80100 -# include "zend_enum.h" -#endif - - -#include "php_xdebug.h" - -#include "var_export_text.h" - -static void xdebug_var_export_text_ansi(zval **struc, xdebug_str *str, int mode, int level, int debug_zval, xdebug_var_export_options *options); -#define xdebug_var_export_text(struc, str, level, debug_zval, options) xdebug_var_export_text_ansi(struc, str, 0, level, debug_zval, options); -#define xdebug_var_export_ansi(struc, str, level, debug_zval, options) xdebug_var_export_text_ansi(struc, str, 1, level, debug_zval, options); - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - - -/***************************************************************************** -** Plain text/ANSI coloured variable printing routines -*/ - -#define ANSI_COLOR_POINTER (mode == 1 ? "0m" : "") -#define ANSI_COLOR_BOOL (mode == 1 ? "35m" : "") -#define ANSI_COLOR_LONG (mode == 1 ? "32m" : "") -#define ANSI_COLOR_NULL (mode == 1 ? "34m" : "") -#define ANSI_COLOR_DOUBLE (mode == 1 ? "33m" : "") -#define ANSI_COLOR_STRING (mode == 1 ? "31m" : "") -#define ANSI_COLOR_EMPTY (mode == 1 ? "30m" : "") -#define ANSI_COLOR_ARRAY (mode == 1 ? "33m" : "") -#define ANSI_COLOR_OBJECT (mode == 1 ? "31m" : "") -#define ANSI_COLOR_RESOURCE (mode == 1 ? "36m" : "") -#define ANSI_COLOR_MODIFIER (mode == 1 ? "32m" : "") -#define ANSI_COLOR_RESET (mode == 1 ? "0m" : "") -#define ANSI_COLOR_BOLD (mode == 1 ? "1m" : "") -#define ANSI_COLOR_BOLD_OFF (mode == 1 ? "22m" : "") - -static int xdebug_array_element_export_text_ansi(zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, int mode, xdebug_str *str, int debug_zval, xdebug_var_export_options *options) -{ - zval **zv = &zv_nptr; - - if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && - options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) - { - xdebug_str_add_fmt(str, "%*s", (level * 2), ""); - - if (HASH_KEY_IS_NUMERIC(hash_key)) { /* numeric key */ - xdebug_str_add_fmt(str, "" XDEBUG_INT_FMT " %s=>%s\n", index_key, ANSI_COLOR_POINTER, ANSI_COLOR_RESET); - } else { /* string key */ - zend_string *tmp, *tmp2; - - tmp = php_str_to_str(ZSTR_VAL(hash_key), ZSTR_LEN(hash_key), (char*) "'", 1, (char*) "\\'", 2); - tmp2 = php_str_to_str(ZSTR_VAL(tmp), ZSTR_LEN(tmp), (char*) "\0", 1, (char*) "\\0", 2); - if (tmp) { - zend_string_release(tmp); - } - xdebug_str_addc(str, '\''); - if (tmp2) { - xdebug_str_add_zstr(str, tmp2); - zend_string_release(tmp2); - } - xdebug_str_add_literal(str, "' =>\n"); - } - xdebug_var_export_text_ansi(zv, str, mode, level + 1, debug_zval, options); - } - if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { - xdebug_str_add_fmt(str, "\n%*s(more elements)...\n", (level * 2), ""); - } - options->runtimelevel.current_element_nr++; - return 0; -} - -static int xdebug_object_element_export_text_ansi(zval *object, zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, int mode, xdebug_str *str, int debug_zval, xdebug_var_export_options *options) -{ - zval **zv = &zv_nptr; - - if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && - options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) - { - xdebug_str_add_fmt(str, "%*s", (level * 2), ""); - - if (!HASH_KEY_IS_NUMERIC(hash_key)) { - char *class_name; - xdebug_str *property_name; - const char *modifier; - xdebug_str *property_type = NULL; - -#if PHP_VERSION_ID >= 70400 - property_type = xdebug_get_property_type(object, zv_nptr); -#endif - - property_name = xdebug_get_property_info((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key), &modifier, &class_name); - xdebug_str_add_fmt( - str, "%s%s%s%s%s%s%s $", - ANSI_COLOR_MODIFIER, ANSI_COLOR_BOLD, modifier, ANSI_COLOR_BOLD_OFF, property_type ? " " : "", property_type ? property_type->d : "", ANSI_COLOR_RESET - ); - xdebug_str_add_str(str, property_name); - xdebug_str_add_fmt(str, " %s=>%s\n", ANSI_COLOR_POINTER, ANSI_COLOR_RESET); - - if (property_type) { - xdebug_str_free(property_type); - } - xdebug_str_free(property_name); - xdfree(class_name); - } else { - xdebug_str_add_fmt(str, "%s%spublic%s%s ${" XDEBUG_INT_FMT "} %s=>%s\n", - ANSI_COLOR_MODIFIER, ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_RESET, - index_key, ANSI_COLOR_POINTER, ANSI_COLOR_RESET - ); - } - xdebug_var_export_text_ansi(zv, str, mode, level + 1, debug_zval, options); - } - if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { - xdebug_str_add_fmt(str, "\n%*s(more elements)...\n", (level * 2), ""); - } - options->runtimelevel.current_element_nr++; - return 0; -} - -static void handle_closure(xdebug_str *str, zval *obj, int level, int mode) -{ - const zend_function *closure_function; - - if (Z_TYPE_P(obj) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(obj), zend_ce_closure)) { - return; - } - -#if PHP_VERSION_ID >= 80000 - closure_function = zend_get_closure_method_def(Z_OBJ_P(obj)); -#else - closure_function = zend_get_closure_method_def(obj); -#endif - - xdebug_str_add_fmt( - str, "%*s%s%svirtual%s $closure =>\n%*s\"", - (level * 4) - 2, "", - ANSI_COLOR_MODIFIER, ANSI_COLOR_BOLD, ANSI_COLOR_RESET, - (level * 4) - 2, "" - ); - - if (closure_function->common.scope) { - if (closure_function->common.fn_flags & ZEND_ACC_STATIC) { - xdebug_str_add_fmt(str, "%s", ANSI_COLOR_OBJECT); - xdebug_str_add_zstr(str, closure_function->common.scope->name); - xdebug_str_add_fmt(str, "%s::", ANSI_COLOR_RESET); - } else { - xdebug_str_add_fmt(str, "%s$this%s->", ANSI_COLOR_OBJECT, ANSI_COLOR_RESET); - } - } - - xdebug_str_add_fmt(str, "%s", ANSI_COLOR_STRING); - xdebug_str_add_zstr(str, closure_function->common.function_name); - xdebug_str_add_fmt(str, "%s\"\n", ANSI_COLOR_RESET); -} - - -static void xdebug_var_export_text_ansi(zval **struc, xdebug_str *str, int mode, int level, int debug_zval, xdebug_var_export_options *options) -{ - HashTable *myht; - char* tmp_str; - int tmp_len; -#if PHP_VERSION_ID < 70400 - int is_temp; -#endif - zend_ulong num; - zend_string *key; - zval *val; - zval *tmpz; - int z_type; - - if (!struc || !(*struc)) { - return; - } - - xdebug_str_add_fmt(str, "%*s", (level * 2) - 2, ""); - - z_type = Z_TYPE_P(*struc); - - if (debug_zval) { - xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_TEXT); - } - if (z_type == IS_INDIRECT) { - tmpz = Z_INDIRECT_P(*struc); - struc = &tmpz; - z_type = Z_TYPE_P(*struc); - } - if (z_type == IS_REFERENCE) { - tmpz = &((*struc)->value.ref->val); - struc = &tmpz; - z_type = Z_TYPE_P(*struc); - } - - switch (z_type) { - case IS_TRUE: - xdebug_str_add_fmt(str, "%sbool%s(%s%s%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_BOOL, "true", ANSI_COLOR_RESET); - break; - - case IS_FALSE: - xdebug_str_add_fmt(str, "%sbool%s(%s%s%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_BOOL, "false", ANSI_COLOR_RESET); - break; - - case IS_NULL: - xdebug_str_add_fmt(str, "%s%sNULL%s%s", ANSI_COLOR_BOLD, ANSI_COLOR_NULL, ANSI_COLOR_RESET, ANSI_COLOR_BOLD_OFF); - break; - - case IS_LONG: - xdebug_str_add_fmt(str, "%sint%s(%s" XDEBUG_INT_FMT "%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_LONG, Z_LVAL_P(*struc), ANSI_COLOR_RESET); - break; - - case IS_DOUBLE: - xdebug_str_add_fmt(str, "%sdouble%s(%s%.*G%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_DOUBLE, (int) EG(precision), Z_DVAL_P(*struc), ANSI_COLOR_RESET); - break; - - case IS_STRING: { - const char *pattern = (mode == 1) ? "'\\\0..\37" : "\0"; - size_t pattern_len = (mode == 1) ? 7 : 1; - - zend_string *i_string = zend_string_init(Z_STRVAL_P(*struc), Z_STRLEN_P(*struc), 0); - zend_string *tmp_zstr; - -#if PHP_VERSION_ID >= 70300 - tmp_zstr = php_addcslashes(i_string, (char*) pattern, pattern_len); -#else - tmp_zstr = php_addcslashes(i_string, 0, (char*) pattern, pattern_len); -#endif - - tmp_str = estrndup(tmp_zstr->val, tmp_zstr->len); - tmp_len = tmp_zstr->len; - zend_string_release(tmp_zstr); - zend_string_release(i_string); - - if (options->no_decoration) { - xdebug_str_addl(str, tmp_str, tmp_len, 0); - } else if ((size_t) Z_STRLEN_P(*struc) <= (size_t) options->max_data) { - xdebug_str_add_fmt( - str, "%sstring%s(%s%ld%s) \"%s%s%s\"", - ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, - ANSI_COLOR_LONG, Z_STRLEN_P(*struc), ANSI_COLOR_RESET, - ANSI_COLOR_STRING, tmp_str, ANSI_COLOR_RESET - ); - } else { - xdebug_str_add_fmt( - str, "%sstring%s(%s%ld%s) \"%s", - ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, - ANSI_COLOR_LONG, Z_STRLEN_P(*struc), ANSI_COLOR_RESET, ANSI_COLOR_STRING - ); - xdebug_str_addl(str, tmp_str, options->max_data, 0); - xdebug_str_add_fmt(str, "%s\"...", ANSI_COLOR_RESET); - } - efree(tmp_str); - } break; - - case IS_ARRAY: - myht = Z_ARRVAL_P(*struc); - - if (!xdebug_zend_hash_is_recursive(myht)) { - xdebug_str_add_fmt(str, "%sarray%s(%s%d%s) {\n", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_LONG, myht->nNumOfElements, ANSI_COLOR_RESET); - if (level <= options->max_depth) { - options->runtimelevel.current_element_nr = 0; - options->runtimelevel.start_element_nr = 0; - options->runtimelevel.end_element_nr = options->max_children; - - xdebug_zend_hash_apply_protection_begin(myht); - - ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { - xdebug_array_element_export_text_ansi(val, num, key, level, mode, str, debug_zval, options); - } ZEND_HASH_FOREACH_END(); - - xdebug_zend_hash_apply_protection_end(myht); - } else { - xdebug_str_add_fmt(str, "%*s...\n", (level * 2), ""); - } - xdebug_str_add_fmt(str, "%*s}", (level * 2) - 2 , ""); - } else { - xdebug_str_add_fmt(str, "&%sarray%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); - } - break; - - case IS_OBJECT: { -#if PHP_VERSION_ID >= 80100 - zend_class_entry *ce = Z_OBJCE_P(*struc); - if (ce->ce_flags & ZEND_ACC_ENUM) { - zval *case_name_zval = zend_enum_fetch_case_name(Z_OBJ_P(*struc)); - xdebug_str_add_fmt( - str, "%senum%s %s%s%s::%s%s%s", - ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, - ANSI_COLOR_OBJECT, ZSTR_VAL(ce->name), ANSI_COLOR_RESET, - ANSI_COLOR_STRING, Z_STRVAL_P(case_name_zval), ANSI_COLOR_RESET - ); - if (ce->enum_backing_type != IS_UNDEF) { - zval *value = zend_enum_fetch_case_value(Z_OBJ_P(*struc)); - - if (ce->enum_backing_type == IS_LONG) { - xdebug_str_add_fmt( - str, " : %s%s%s(%s%d%s)", - ANSI_COLOR_BOLD, "int", ANSI_COLOR_RESET, - ANSI_COLOR_LONG, Z_LVAL_P(value), ANSI_COLOR_RESET - ); - } - - if (ce->enum_backing_type == IS_STRING) { - xdebug_str_add_fmt( - str, " : %s%s%s(%s\"%s\"%s)", - ANSI_COLOR_BOLD, "string", ANSI_COLOR_RESET, - ANSI_COLOR_STRING, Z_STRVAL_P(value), ANSI_COLOR_RESET - ); - } - } - xdebug_str_addc(str, ';'); - break; - } -#endif - -#if PHP_VERSION_ID >= 70400 - myht = xdebug_objdebug_pp(struc, XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO); -#else - myht = xdebug_objdebug_pp(struc, &is_temp, XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO); -#endif - - if (!myht || !xdebug_zend_hash_is_recursive(myht)) { - xdebug_str_add_fmt( - str, "%sclass%s %s%s%s#%d (%s%d%s) {\n", - ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, - ANSI_COLOR_OBJECT, STR_NAME_VAL(Z_OBJCE_P(*struc)->name), ANSI_COLOR_RESET, - Z_OBJ_HANDLE_P(*struc), - ANSI_COLOR_LONG, myht ? myht->nNumOfElements : 0, ANSI_COLOR_RESET - ); - - handle_closure(str, *struc, level, mode); - - if (myht && (level <= options->max_depth)) { - options->runtimelevel.current_element_nr = 0; - options->runtimelevel.start_element_nr = 0; - options->runtimelevel.end_element_nr = options->max_children; - - xdebug_zend_hash_apply_protection_begin(myht); - - ZEND_HASH_FOREACH_KEY_VAL(myht, num, key, val) { - xdebug_object_element_export_text_ansi(*struc, val, num, key, level, mode, str, debug_zval, options); - } ZEND_HASH_FOREACH_END(); - - xdebug_zend_hash_apply_protection_end(myht); - } else { - xdebug_str_add_fmt(str, "%*s...\n", (level * 2), ""); - } - xdebug_str_add_fmt(str, "%*s}", (level * 2) - 2, ""); - } else { - xdebug_str_add_fmt(str, "%*s...\n", (level * 2), ""); - } -#if PHP_VERSION_ID >= 70400 - zend_release_properties(myht); -#else - xdebug_var_maybe_destroy_ht(myht, is_temp); -#endif - break; - } - - case IS_RESOURCE: { - char *type_name; - - type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); - xdebug_str_add_fmt( - str, "%sresource%s(%s%ld%s) of type (%s)", - ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, - ANSI_COLOR_RESOURCE, Z_RES_P(*struc)->handle, ANSI_COLOR_RESET, type_name ? type_name : "Unknown" - ); - break; - } - - case IS_UNDEF: - xdebug_str_add_fmt(str, "%s*uninitialized*%s", ANSI_COLOR_NULL, ANSI_COLOR_RESET); - break; - - default: - xdebug_str_add_fmt(str, "%sNFC%s", ANSI_COLOR_NULL, ANSI_COLOR_RESET); - break; - } - - xdebug_str_addc(str, '\n'); -} - -xdebug_str* xdebug_get_zval_value_text_ansi(zval *val, int mode, int debug_zval, xdebug_var_export_options *options) -{ - xdebug_str *str = xdebug_str_new(); - int default_options = 0; - - if (!options) { - options = xdebug_var_export_options_from_ini(); - default_options = 1; - } - - if (options->show_location && !debug_zval) { - char *formatted_filename; - - xdebug_format_filename(&formatted_filename, "%f", zend_get_executed_filename_ex()); - xdebug_str_add_fmt(str, "%s%s%s:%s%d%s:\n", ANSI_COLOR_BOLD, formatted_filename, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_BOLD, zend_get_executed_lineno(), ANSI_COLOR_BOLD_OFF); - xdfree(formatted_filename); - } - - xdebug_var_export_text_ansi(&val, str, mode, 1, debug_zval, options); - - if (default_options) { - xdfree(options->runtime); - xdfree(options); - } - - return str; -} - -static void xdebug_var_synopsis_text_ansi(zval **struc, xdebug_str *str, int mode, int level, int debug_zval, xdebug_var_export_options *options) -{ - HashTable *myht; - zval *tmpz; - int z_type; - - if (!struc || !(*struc)) { - return; - } - - z_type = Z_TYPE_P(*struc); - - if (debug_zval) { - xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_TEXT); - } - if (z_type == IS_REFERENCE) { - tmpz = &((*struc)->value.ref->val); - struc = &tmpz; - z_type = Z_TYPE_P(*struc); - } - - switch (z_type) { - case IS_TRUE: - xdebug_str_add_fmt(str, "%strue%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); - break; - - case IS_FALSE: - xdebug_str_add_fmt(str, "%sfalse%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); - break; - - case IS_NULL: - xdebug_str_add_fmt(str, "%snull%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); - break; - - case IS_LONG: - xdebug_str_add_fmt(str, "%sint%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); - break; - - case IS_DOUBLE: - xdebug_str_add_fmt(str, "%sdouble%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); - break; - - case IS_STRING: - xdebug_str_add_fmt(str, "%sstring%s(%s%d%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_LONG, Z_STRLEN_P(*struc), ANSI_COLOR_RESET); - break; - - case IS_ARRAY: - myht = Z_ARRVAL_P(*struc); - xdebug_str_add_fmt(str, "array(%s%d%s)", ANSI_COLOR_LONG, myht->nNumOfElements, ANSI_COLOR_RESET); - break; - - case IS_OBJECT: - xdebug_str_add_fmt(str, "class %s", ZSTR_VAL(Z_OBJCE_P(*struc)->name)); - break; - - case IS_RESOURCE: { - char *type_name; - - type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); - xdebug_str_add_fmt(str, "resource(%s%ld%s) of type (%s)", ANSI_COLOR_LONG, Z_RES_P(*struc)->handle, ANSI_COLOR_RESET, type_name ? type_name : "Unknown"); - break; - } - - case IS_UNDEF: - xdebug_str_add_fmt(str, "%s*uninitialized*%s", ANSI_COLOR_NULL, ANSI_COLOR_RESET); - break; - - default: - xdebug_str_add_fmt(str, "%sNFC%s", ANSI_COLOR_NULL, ANSI_COLOR_RESET); - break; - } -} - -xdebug_str* xdebug_get_zval_synopsis_text_ansi(zval *val, int mode, int debug_zval, xdebug_var_export_options *options) -{ - xdebug_str *str = xdebug_str_new(); - int default_options = 0; - - if (!options) { - options = xdebug_var_export_options_from_ini(); - default_options = 1; - } - - if (options->show_location && !debug_zval) { - xdebug_str_add_fmt(str, "%s%s: %d%s\n", ANSI_COLOR_BOLD, zend_get_executed_filename(), zend_get_executed_lineno(), ANSI_COLOR_BOLD_OFF); - } - - xdebug_var_synopsis_text_ansi(&val, str, mode, 1, debug_zval, options); - - if (default_options) { - xdfree(options->runtime); - xdfree(options); - } - - return str; -} -
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/lib/var_export_xml.c
Deleted
@@ -1,846 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#include "var_export_xml.h" -#include "Zend/zend_closures.h" - -static xdebug_str *prepare_variable_name(xdebug_str *name) -{ - xdebug_str *tmp_name; - - if (name->d0 == '$' || name->d0 == ':') { - tmp_name = xdebug_str_copy(name); - } else { - tmp_name = xdebug_str_new(); - xdebug_str_addc(tmp_name, '$'); - xdebug_str_add_str(tmp_name, name); - } - if (tmp_name->dtmp_name->l - 2 == ':' && tmp_name->dtmp_name->l - 1 == ':') { - xdebug_str_chop(tmp_name, 2); - } - return tmp_name; -} - -/* - * Returns whether we should attempt to encode name, fullname, and value as XML - * elements instead of attribute values, because XML doesn't support nearly all - * characters under ASCII 0x32. - */ -static int encoding_requested(char *value, size_t value_len) -{ - size_t i; - - for (i = 0; i < value_len; i++) { - if (valuei < 0x20) { - return 1; - } - } - return 0; -} - -static void check_if_extended_properties_are_needed(xdebug_var_export_options *options, xdebug_str *name, xdebug_str *fullname, zval *value) -{ - if (!options->extended_properties || options->encode_as_extended_property) { - return; - } - - /* Checking name */ - if (name && encoding_requested(name->d, name->l)) { - options->encode_as_extended_property = 1; - return; - } - - /* Checking full name */ - if (fullname && encoding_requested(fullname->d, fullname->l)) { - options->encode_as_extended_property = 1; - return; - } - - /* Checking for the value portion */ - if (!value) { - return; - } - if (Z_TYPE_P(value) == IS_STRING) { - if (encoding_requested(Z_STRVAL_P(value), Z_STRLEN_P(value))) { - options->encode_as_extended_property = 1; - return; - } - } - if (Z_TYPE_P(value) == IS_OBJECT) { - if (encoding_requested(STR_NAME_VAL(Z_OBJCE_P(value)->name), STR_NAME_LEN(Z_OBJCE_P(value)->name))) { - options->encode_as_extended_property = 1; - return; - } - } -} - -static void add_xml_attribute_or_element(xdebug_var_export_options *options, xdebug_xml_node *node, const char *field, int field_len, xdebug_str *value) -{ - if (options->encode_as_extended_property || (encoding_requested(value->d, value->l) && options->extended_properties)) { - xdebug_xml_node *element; - unsigned char *tmp_base64; - size_t new_len; - - options->encode_as_extended_property = 1; - - element = xdebug_xml_node_init(field); - xdebug_xml_add_attribute(element, "encoding", "base64"); - - tmp_base64 = xdebug_base64_encode((unsigned char*) value->d, value->l, &new_len); - xdebug_xml_add_text_ex(element, (char*) tmp_base64, new_len, 1, 0); - - xdebug_xml_add_child(node, element); - } else { - xdebug_xml_add_attribute_exl(node, field, field_len, xdstrndup(value->d, value->l), value->l, 0, 1); - } -} - -void xdebug_var_xml_attach_uninitialized_var(xdebug_var_export_options *options, xdebug_xml_node *node, xdebug_str *name) -{ - xdebug_xml_node *contents = NULL; - xdebug_str *tmp_name; - - contents = xdebug_xml_node_init("property"); - options->encode_as_extended_property = 0; - - tmp_name = prepare_variable_name(name); - add_xml_attribute_or_element(options, contents, "name", 4, tmp_name); - add_xml_attribute_or_element(options, contents, "fullname", 8, tmp_name); - xdebug_str_free(tmp_name); - - xdebug_xml_add_attribute(contents, "type", "uninitialized"); - xdebug_xml_add_child(node, contents); -} - -/***************************************************************************** -** XML node printing routines -*/ - -#define XDEBUG_OBJECT_ITEM_TYPE_PROPERTY 0 -#define XDEBUG_OBJECT_ITEM_TYPE_STATIC_PROPERTY 1<<0 -#define XDEBUG_OBJECT_ITEM_TYPE_READONLY 1<<1 - - -typedef struct -{ - char type; - char *name; - int name_len; - unsigned long index_key; - zval *zv; -} xdebug_object_item; - -static void merged_hash_object_item_dtor(zval *data) -{ - xdebug_object_item *item = Z_PTR_P(data); - - xdfree(item); -} - -static int object_item_add_to_merged_hash(zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, HashTable *merged, int object_type) -{ - zval **zv = &zv_nptr; - xdebug_object_item *item; - - item = xdcalloc(1, sizeof(xdebug_object_item)); - item->type = object_type; - item->zv = *zv; - - if (hash_key) { - item->name = (char*) HASH_APPLY_KEY_VAL(hash_key); - item->name_len = HASH_APPLY_KEY_LEN(hash_key) - 1; - item->index_key = hash_key->h; - } else { - item->name = xdebug_sprintf(XDEBUG_INT_FMT, index_key); - item->name_len = strlen(item->name); - } - - zend_hash_next_index_insert_ptr(merged, item); - - return 0; -} - -static int object_item_add_zend_prop_to_merged_hash(zend_property_info *zpp, HashTable *merged, int object_type, zend_class_entry *ce) -{ - xdebug_object_item *item; - - if ((zpp->flags & ZEND_ACC_STATIC) == 0) { - return 0; - } - - item = xdmalloc(sizeof(xdebug_object_item)); - item->type = object_type; -#if ZTS && PHP_VERSION_ID < 70400 - if (ce->type == 1) { - item->zv = &CG(static_members_table)(zend_intptr_t) CE_STATIC_MEMBERS(ce)zpp->offset; - } else { - item->zv = &CE_STATIC_MEMBERS(ce)zpp->offset; - } -#else - item->zv = &CE_STATIC_MEMBERS(ce)zpp->offset; -#endif - item->name = (char*) STR_NAME_VAL(zpp->name); - item->name_len = STR_NAME_LEN(zpp->name); - - zend_hash_next_index_insert_ptr(merged, item); - - return 0; -} - -static void add_unencoded_text_value_attribute_or_element(xdebug_var_export_options *options, xdebug_xml_node *node, char *value) -{ - if (options->encode_as_extended_property) { - xdebug_xml_node *element; - unsigned char *tmp_base64; - size_t new_len; - - element = xdebug_xml_node_init("value"); - xdebug_xml_add_attribute(element, "encoding", "base64"); - - tmp_base64 = xdebug_base64_encode((unsigned char*) value, strlen(value), &new_len); - xdebug_xml_add_text_ex(element, (char*) tmp_base64, new_len, 1, 0); - - xdebug_xml_add_child(node, element); - } else { - xdebug_xml_add_text(node, value); - } -} - -static void add_encoded_text_value_attribute_or_element(xdebug_var_export_options *options, xdebug_xml_node *node, char *value, size_t value_len) -{ - if (options->encode_as_extended_property) { - xdebug_xml_node *element; - unsigned char *tmp_base64; - size_t new_len; - - element = xdebug_xml_node_init("value"); - xdebug_xml_add_attribute(element, "encoding", "base64"); - - tmp_base64 = xdebug_base64_encode((unsigned char*) value, value_len, &new_len); - xdebug_xml_add_text_ex(element, (char*) tmp_base64, new_len, 1, 0); - - xdebug_xml_add_child(node, element); - - xdfree(value); - } else { - xdebug_xml_add_text_encodel(node, value, value_len); - } -} - - -static int xdebug_array_element_export_xml_node(zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, xdebug_xml_node *parent, xdebug_str *parent_name, xdebug_var_export_options *options) -{ - zval **zv = &zv_nptr; - xdebug_xml_node *node; - xdebug_str *name; - xdebug_str full_name = XDEBUG_STR_INITIALIZER; - - if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && - options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) - { - node = xdebug_xml_node_init("property"); - options->encode_as_extended_property = 0; - - if (!HASH_KEY_IS_NUMERIC(hash_key)) { /* string key */ - zend_string *i_string = zend_string_init(HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key) - 1, 0); - zend_string *tmp_fullname_zstr; - - tmp_fullname_zstr = xdebug_addslashes(i_string); - - name = xdebug_str_create(HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key) - 1); - - if (parent_name) { - xdebug_str_add_str(&full_name, parent_name); - xdebug_str_add_literal(&full_name, "\""); - xdebug_str_addl(&full_name, tmp_fullname_zstr->val, tmp_fullname_zstr->len, 0); - xdebug_str_add_literal(&full_name, "\""); - } - - zend_string_release(tmp_fullname_zstr); - zend_string_release(i_string); - } else { - char *tmp_idx = xdebug_sprintf(XDEBUG_INT_FMT, index_key); - - name = xdebug_str_create(tmp_idx, strlen(tmp_idx)); - if (parent_name) { - xdebug_str_add_str(&full_name, parent_name); - xdebug_str_addc(&full_name, ''); - xdebug_str_add_str(&full_name, name); - xdebug_str_addc(&full_name, ''); - } - - xdfree(tmp_idx); - } - - check_if_extended_properties_are_needed(options, name, full_name.l ? &full_name : NULL, *zv); - add_xml_attribute_or_element(options, node, "name", 4, name); - if (full_name.l) { - add_xml_attribute_or_element(options, node, "fullname", 8, &full_name); - } - - xdebug_xml_add_child(parent, node); - xdebug_var_export_xml_node(zv, &full_name, node, options, level + 1); - - xdebug_str_destroy(&full_name); - xdebug_str_free(name); - } - options->runtimelevel.current_element_nr++; - return 0; -} - -static int xdebug_object_element_export_xml_node(xdebug_object_item *item_nptr, int level, xdebug_xml_node *parent, xdebug_str *parent_name, xdebug_var_export_options *options, char *class_name) -{ - xdebug_object_item **item = &item_nptr; - xdebug_xml_node *node; - - if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && - options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) - { - const char *modifier; - xdebug_str *tmp_name = NULL; - xdebug_str *tmp_fullname = NULL; - - node = xdebug_xml_node_init("property"); - options->encode_as_extended_property = 0; - - if ((*item)->name != NULL) { - char *prop_class_name; - xdebug_str *property_name; - - property_name = xdebug_get_property_info((*item)->name, (*item)->name_len + 1, &modifier, &prop_class_name); - - if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) { - tmp_name = xdebug_str_copy(property_name); - } else { - tmp_name = xdebug_str_new(); - - xdebug_str_addc(tmp_name, '*'); - xdebug_str_add(tmp_name, prop_class_name, 0); - xdebug_str_addc(tmp_name, '*'); - xdebug_str_add_str(tmp_name, property_name); - } - - if (parent_name) { - tmp_fullname = xdebug_str_new(); - - xdebug_str_add_str(tmp_fullname, parent_name); - if ((*item)->type & XDEBUG_OBJECT_ITEM_TYPE_STATIC_PROPERTY) { - xdebug_str_add_literal(tmp_fullname, "::"); - } else { - xdebug_str_add_literal(tmp_fullname, "->"); - } - - /* Only in dynamic and *public* properties can we have non-standard characters */ - if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) { - if (property_name->l == 0) { - xdebug_str_add_literal(tmp_fullname, "{\"\"}"); - } else { - if (memchr(property_name->d, '-', property_name->l) == NULL && memchr(property_name->d, '', property_name->l) == NULL && memchr(property_name->d, '{', property_name->l) == NULL) { - xdebug_str_add_str(tmp_fullname, property_name); - } else { - zend_string *tmp_string = zend_string_init(property_name->d, property_name->l, 0); - zend_string *tmp_slashed_string; - - tmp_slashed_string = xdebug_addslashes(tmp_string); - - xdebug_str_add_literal(tmp_fullname, "{\""); - xdebug_str_add_zstr(tmp_fullname, tmp_slashed_string); - xdebug_str_add_literal(tmp_fullname, "\"}"); - - zend_string_release(tmp_slashed_string); - zend_string_release(tmp_string); - } - } - } else { - xdebug_str_addc(tmp_fullname, '*'); - xdebug_str_add(tmp_fullname, prop_class_name, 0); - xdebug_str_addc(tmp_fullname, '*'); - xdebug_str_add_str(tmp_fullname, property_name); - } - } - - xdebug_str_free(property_name); - xdfree(prop_class_name); - } else { /* Numerical property name */ - modifier = "public"; - - { - char *tmp_formatted_prop; - - tmp_formatted_prop = xdebug_sprintf(XDEBUG_INT_FMT, (*item)->index_key); - tmp_name = xdebug_str_create_from_char(tmp_formatted_prop); - - add_xml_attribute_or_element(options, node, "name", 4, tmp_name); - - xdfree(tmp_formatted_prop); - } - - if (parent_name) { - char *tmp_formatted_prop; - - tmp_formatted_prop = xdebug_sprintf("%s%s" XDEBUG_INT_FMT, parent_name, (*item)->type & XDEBUG_OBJECT_ITEM_TYPE_STATIC_PROPERTY ? "::" : "->", (*item)->index_key); - tmp_fullname = xdebug_str_create_from_char(tmp_formatted_prop); - - xdfree(tmp_formatted_prop); - } - } - - check_if_extended_properties_are_needed(options, tmp_name, tmp_fullname, (*item)->zv); - add_xml_attribute_or_element(options, node, "name", 4, tmp_name); - if (tmp_fullname) { - add_xml_attribute_or_element(options, node, "fullname", 8, tmp_fullname); - } - - - if ((*item)->type & XDEBUG_OBJECT_ITEM_TYPE_STATIC_PROPERTY) { - xdebug_xml_expand_attribute_value(node, "facet", "static"); - } - xdebug_xml_expand_attribute_value(node, "facet", modifier); - if ((*item)->type & XDEBUG_OBJECT_ITEM_TYPE_READONLY) { - xdebug_xml_expand_attribute_value(node, "facet", "readonly"); - } - - xdebug_xml_add_child(parent, node); - xdebug_var_export_xml_node(&((*item)->zv), tmp_fullname ? tmp_fullname : NULL, node, options, level + 1); - - if (tmp_name) { - xdebug_str_free(tmp_name); - } - if (tmp_fullname) { - xdebug_str_free(tmp_fullname); - } - } - options->runtimelevel.current_element_nr++; - return 0; -} - -static void xdebug_var_xml_attach_property_with_contents(zend_property_info *prop_info, xdebug_xml_node *node, xdebug_var_export_options *options, zend_class_entry *class_entry, char *class_name, int *children_count) -{ - const char *modifier; - xdebug_xml_node *contents = NULL; - char *prop_class_name; - xdebug_str *property_name; - - if ((prop_info->flags & ZEND_ACC_STATIC) == 0) { - return; - } - - (*children_count)++; - property_name = xdebug_get_property_info(STR_NAME_VAL(prop_info->name), STR_NAME_LEN(prop_info->name) + 1, &modifier, &prop_class_name); - - if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) { - contents = xdebug_get_zval_value_xml_node_ex(property_name, &CE_STATIC_MEMBERS(class_entry)prop_info->offset, XDEBUG_VAR_TYPE_STATIC, options); - } else{ - xdebug_str *priv_name = xdebug_str_new(); - - xdebug_str_addc(priv_name, '*'); - xdebug_str_add(priv_name, prop_class_name, 0); - xdebug_str_addc(priv_name, '*'); - xdebug_str_add_str(priv_name, property_name); - - contents = xdebug_get_zval_value_xml_node_ex(priv_name, &CE_STATIC_MEMBERS(class_entry)prop_info->offset, XDEBUG_VAR_TYPE_STATIC, options); - - xdebug_str_free(priv_name); - } - - xdebug_str_free(property_name); - xdfree(prop_class_name); - - if (contents) { - xdebug_xml_expand_attribute_value(contents, "facet", "static"); - xdebug_xml_expand_attribute_value(contents, "facet", modifier); - xdebug_xml_add_child(node, contents); - } else { - xdebug_var_xml_attach_uninitialized_var(options, node, xdebug_str_create(ZSTR_VAL(prop_info->name), ZSTR_LEN(prop_info->name))); - } -} - -void xdebug_var_xml_attach_static_vars(xdebug_xml_node *node, xdebug_var_export_options *options, zend_class_entry *ce) -{ - HashTable *static_members = &ce->properties_info; - int children = 0; - xdebug_xml_node *static_container; - zend_property_info *zpi; - - static_container = xdebug_xml_node_init("property"); - options->encode_as_extended_property = 0; - - xdebug_xml_add_attribute(static_container, "name", "::"); - xdebug_xml_add_attribute(static_container, "fullname", "::"); - xdebug_xml_add_attribute(static_container, "type", "object"); - xdebug_xml_add_attribute_ex(static_container, "classname", xdstrdup(STR_NAME_VAL(ce->name)), 0, 1); - - xdebug_zend_hash_apply_protection_begin(static_members); - -#if PHP_VERSION_ID >= 80100 - if (ce->default_static_members_count && !CE_STATIC_MEMBERS(ce)) { - zend_class_init_statics(ce); - } -#endif - - ZEND_HASH_FOREACH_PTR(static_members, zpi) { - xdebug_var_xml_attach_property_with_contents(zpi, static_container, options, ce, STR_NAME_VAL(ce->name), &children); - } ZEND_HASH_FOREACH_END(); - - xdebug_zend_hash_apply_protection_end(static_members); - - xdebug_xml_add_attribute(static_container, "children", children > 0 ? "1" : "0"); - xdebug_xml_add_attribute_ex(static_container, "numchildren", xdebug_sprintf("%d", children), 0, 1); - - xdebug_xml_add_child(node, static_container); -} - -void xdebug_var_export_xml_node(zval **struc, xdebug_str *name, xdebug_xml_node *node, xdebug_var_export_options *options, int level) -{ - HashTable *myht; - zend_ulong num; - zend_string *key; - zval *z_val; - xdebug_object_item *xoi_val; - zval *tmpz; - - if (!*struc) { - xdebug_xml_add_attribute(node, "type", "uninitialized"); - return; - } - - if (Z_TYPE_P(*struc) == IS_INDIRECT) { - tmpz = ((*struc)->value.zv); - struc = &tmpz; - } - if (Z_TYPE_P(*struc) == IS_REFERENCE) { - tmpz = &((*struc)->value.ref->val); - struc = &tmpz; - } - - switch (Z_TYPE_P(*struc)) { - case IS_TRUE: - case IS_FALSE: - xdebug_xml_add_attribute(node, "type", "bool"); - add_unencoded_text_value_attribute_or_element(options, node, xdebug_sprintf("%d", Z_TYPE_P(*struc) == IS_TRUE ? 1 : 0)); - break; - - case IS_NULL: - xdebug_xml_add_attribute(node, "type", "null"); - break; - - case IS_LONG: - xdebug_xml_add_attribute(node, "type", "int"); - add_unencoded_text_value_attribute_or_element(options, node, xdebug_sprintf(XDEBUG_INT_FMT, Z_LVAL_P(*struc))); - break; - - case IS_DOUBLE: - xdebug_xml_add_attribute(node, "type", "float"); - add_unencoded_text_value_attribute_or_element(options, node, xdebug_sprintf("%.*G", (int) EG(precision), Z_DVAL_P(*struc))); - break; - - case IS_STRING: - xdebug_xml_add_attribute(node, "type", "string"); - if (options->max_data == 0 || (size_t) Z_STRLEN_P(*struc) <= (size_t) options->max_data) { - add_encoded_text_value_attribute_or_element(options, node, xdstrndup(Z_STRVAL_P(*struc), Z_STRLEN_P(*struc)), Z_STRLEN_P(*struc)); - } else { - add_encoded_text_value_attribute_or_element(options, node, xdstrndup(Z_STRVAL_P(*struc), options->max_data), options->max_data); - } - xdebug_xml_add_attribute_ex(node, "size", xdebug_sprintf("%d", Z_STRLEN_P(*struc)), 0, 1); - break; - - case IS_ARRAY: - myht = Z_ARRVAL_P(*struc); - xdebug_xml_add_attribute(node, "type", "array"); - xdebug_xml_add_attribute(node, "children", myht->nNumOfElements > 0?"1":"0"); - - if (!xdebug_zend_hash_is_recursive(myht)) { - xdebug_xml_add_attribute_ex(node, "numchildren", xdebug_sprintf("%d", myht->nNumOfElements), 0, 1); - if (level < options->max_depth) { - xdebug_xml_add_attribute_ex(node, "page", xdebug_sprintf("%d", options->runtimelevel.page), 0, 1); - xdebug_xml_add_attribute_ex(node, "pagesize", xdebug_sprintf("%d", options->max_children), 0, 1); - options->runtimelevel.current_element_nr = 0; - if (level == 0) { - options->runtimelevel.start_element_nr = options->max_children * options->runtimelevel.page; - options->runtimelevel.end_element_nr = options->max_children * (options->runtimelevel.page + 1); - } else { - options->runtimelevel.start_element_nr = 0; - options->runtimelevel.end_element_nr = options->max_children; - } - - xdebug_zend_hash_apply_protection_begin(myht); - - ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, z_val) { - xdebug_array_element_export_xml_node(z_val, num, key, level, node, name, options); - } ZEND_HASH_FOREACH_END(); - - xdebug_zend_hash_apply_protection_end(myht); - } - } else { - xdebug_xml_add_attribute(node, "recursive", "1"); - } - break; - - case IS_OBJECT: { - HashTable *merged_hash; - zend_string *class_name; - zend_class_entry *ce; -#if PHP_VERSION_ID < 70400 - int is_temp; -#endif - int extra_children = 0; - zend_property_info *zpi_val; - - ALLOC_HASHTABLE(merged_hash); - zend_hash_init(merged_hash, 128, NULL, merged_hash_object_item_dtor, 0); - - class_name = Z_OBJCE_P(*struc)->name; - ce = zend_fetch_class(class_name, ZEND_FETCH_CLASS_DEFAULT); - - /* Adding static properties */ - xdebug_zend_hash_apply_protection_begin(&ce->properties_info); - -#if PHP_VERSION_ID >= 80100 - zend_class_init_statics(ce); -#elif PHP_VERSION_ID >= 70400 - if (ce->type == ZEND_INTERNAL_CLASS || (ce->ce_flags & ZEND_ACC_IMMUTABLE)) { - zend_class_init_statics(ce); - } -#endif - - ZEND_HASH_FOREACH_PTR(&ce->properties_info, zpi_val) { - object_item_add_zend_prop_to_merged_hash(zpi_val, merged_hash, (int) XDEBUG_OBJECT_ITEM_TYPE_STATIC_PROPERTY, ce); - } ZEND_HASH_FOREACH_END(); - - xdebug_zend_hash_apply_protection_end(&ce->properties_info); - - /* Adding normal properties */ -#if PHP_VERSION_ID >= 70400 - myht = xdebug_objdebug_pp(struc, XDEBUG_VAR_OBJDEBUG_DEFAULT); -#else - myht = xdebug_objdebug_pp(struc, &is_temp, XDEBUG_VAR_OBJDEBUG_DEFAULT); -#endif - if (myht) { - zval *tmp_val; - - xdebug_zend_hash_apply_protection_begin(myht); - - ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, tmp_val) { - int flags = XDEBUG_OBJECT_ITEM_TYPE_PROPERTY; - -#if PHP_VERSION_ID >= 80100 - if (ce->type != ZEND_INTERNAL_CLASS) { - const char *cls_name, *tmp_prop_name; - size_t tmp_prop_name_len; - zend_string *unmangled; - zend_property_info *info; - - zend_unmangle_property_name_ex(key, &cls_name, &tmp_prop_name, &tmp_prop_name_len); - unmangled = zend_string_init_interned(tmp_prop_name, tmp_prop_name_len, 0); - - info = zend_get_property_info(Z_OBJCE_P(*struc), unmangled, 1); - - zend_string_release(unmangled); - - if (info && info != ZEND_WRONG_PROPERTY_INFO && info->flags & ZEND_ACC_READONLY) { - flags |= XDEBUG_OBJECT_ITEM_TYPE_READONLY; - } - } -#endif - object_item_add_to_merged_hash(tmp_val, num, key, merged_hash, flags); - } ZEND_HASH_FOREACH_END(); - - xdebug_zend_hash_apply_protection_end(myht); - } - - xdebug_xml_add_attribute(node, "type", "object"); - -#if PHP_VERSION_ID >= 80100 // Enums - { - zend_class_entry *ce = Z_OBJCE_P(*struc); - if (ce->ce_flags & ZEND_ACC_ENUM) { - xdebug_xml_expand_attribute_value(node, "facet", "enum"); - } - } -#endif - - if (instanceof_function(Z_OBJCE_P(*struc), zend_ce_closure)) { - xdebug_xml_node *closure_cont, *closure_func; -#if PHP_VERSION_ID >= 80000 - const zend_function *closure_function = zend_get_closure_method_def(Z_OBJ_P(*struc)); -#else - const zend_function *closure_function = zend_get_closure_method_def(*struc); -#endif - - xdebug_xml_expand_attribute_value(node, "facet", "closure"); - - closure_cont = xdebug_xml_node_init("property"); - xdebug_xml_add_attribute(closure_cont, "facet", "virtual readonly"); - xdebug_xml_add_attribute(closure_cont, "name", "{closure}"); - xdebug_xml_add_attribute(closure_cont, "type", "array"); - xdebug_xml_add_attribute(closure_cont, "children", "1"); - xdebug_xml_add_attribute(closure_cont, "page", "0"); - xdebug_xml_add_attribute(closure_cont, "pagesize", "2"); - - if (closure_function->common.scope) { - xdebug_xml_node *closure_scope = xdebug_xml_node_init("property"); - xdebug_xml_add_attribute(closure_scope, "facet", "readonly"); - xdebug_xml_add_attribute(closure_scope, "name", "scope"); - xdebug_xml_add_attribute(closure_scope, "type", "string"); - - if (closure_function->common.fn_flags & ZEND_ACC_STATIC) { - xdebug_xml_add_text_ex( - closure_scope, - ZSTR_VAL(closure_function->common.scope->name), - ZSTR_LEN(closure_function->common.scope->name), - 0, 0 - ); - } else { - xdebug_xml_add_text_ex(closure_scope, (char*) "$this", 6, 0, 0); - } - - xdebug_xml_add_child(closure_cont, closure_scope); - xdebug_xml_add_attribute(closure_cont, "numchildren", "2"); - } else { - xdebug_xml_add_attribute(closure_cont, "numchildren", "1"); - } - - closure_func = xdebug_xml_node_init("property"); - xdebug_xml_add_attribute(closure_func, "facet", "readonly"); - xdebug_xml_add_attribute(closure_func, "name", "function"); - xdebug_xml_add_attribute(closure_func, "type", "string"); - xdebug_xml_add_text_ex( - closure_func, - ZSTR_VAL(closure_function->common.function_name), - ZSTR_LEN(closure_function->common.function_name), - 0, 0 - ); - xdebug_xml_add_child(closure_cont, closure_func); - - xdebug_xml_add_child(node, closure_cont); - extra_children = 1; - } - - { - xdebug_str tmp_str; - tmp_str.d = ZSTR_VAL(class_name); - tmp_str.l = ZSTR_LEN(class_name); - add_xml_attribute_or_element(options, node, "classname", 9, &tmp_str); - } - xdebug_xml_add_attribute(node, "children", merged_hash->nNumOfElements ? "1" : "0"); - - - if (!myht || !xdebug_zend_hash_is_recursive(myht)) { - xdebug_xml_add_attribute_ex( - node, "numchildren", - xdebug_sprintf("%d", zend_hash_num_elements(merged_hash) + extra_children), - 0, 1 - ); - if (level < options->max_depth) { - xdebug_xml_add_attribute_ex(node, "page", xdebug_sprintf("%d", options->runtimelevel.page), 0, 1); - xdebug_xml_add_attribute_ex(node, "pagesize", xdebug_sprintf("%d", options->max_children), 0, 1); - options->runtimelevel.current_element_nr = 0; - if (level == 0) { - options->runtimelevel.start_element_nr = options->max_children * options->runtimelevel.page; - options->runtimelevel.end_element_nr = options->max_children * (options->runtimelevel.page + 1); - } else { - options->runtimelevel.start_element_nr = 0; - options->runtimelevel.end_element_nr = options->max_children; - } - - xdebug_zend_hash_apply_protection_begin(merged_hash); - - ZEND_HASH_FOREACH_KEY_PTR(merged_hash, num, key, xoi_val) { - xdebug_object_element_export_xml_node(xoi_val, level, node, name, options, ZSTR_VAL(class_name)); - } ZEND_HASH_FOREACH_END(); - - xdebug_zend_hash_apply_protection_end(merged_hash); - } - } - - zend_hash_destroy(merged_hash); - FREE_HASHTABLE(merged_hash); -#if PHP_VERSION_ID >= 70400 - zend_release_properties(myht); -#else - xdebug_var_maybe_destroy_ht(myht, is_temp); -#endif - break; - } - - case IS_RESOURCE: { - char *type_name; - - xdebug_xml_add_attribute(node, "type", "resource"); - type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); - xdebug_xml_add_text(node, xdebug_sprintf("resource id='%ld' type='%s'", Z_RES_P(*struc)->handle, type_name ? type_name : "Unknown")); - break; - } - - case IS_UNDEF: - xdebug_xml_add_attribute(node, "type", "uninitialized"); - break; - - default: - xdebug_xml_add_attribute(node, "type", "null"); - break; - } -} - -xdebug_xml_node* xdebug_get_zval_value_xml_node_ex(xdebug_str *name, zval *val, int var_type, xdebug_var_export_options *options) -{ - xdebug_xml_node *node; - xdebug_str *short_name = NULL; - xdebug_str *full_name = NULL; - - node = xdebug_xml_node_init("property"); - options->encode_as_extended_property = 0; - - if (name) { - switch (var_type) { - case XDEBUG_VAR_TYPE_NORMAL: { - short_name = prepare_variable_name(name); - full_name = xdebug_str_copy(short_name); - } break; - - case XDEBUG_VAR_TYPE_STATIC: { - xdebug_str tmp_formatted_name = XDEBUG_STR_INITIALIZER; - - xdebug_str_add_literal(&tmp_formatted_name, "::"); - xdebug_str_add_str(&tmp_formatted_name, name); - - short_name = xdebug_str_copy(&tmp_formatted_name); - full_name = xdebug_str_copy(&tmp_formatted_name); - - xdebug_str_destroy(&tmp_formatted_name); - } break; - - case XDEBUG_VAR_TYPE_CONSTANT: - short_name = xdebug_str_copy(name); - full_name = xdebug_str_copy(name); - break; - } - - check_if_extended_properties_are_needed(options, short_name, full_name, val); - add_xml_attribute_or_element(options, node, "name", 4, short_name); - add_xml_attribute_or_element(options, node, "fullname", 8, full_name); - } - xdebug_var_export_xml_node(&val, full_name ? full_name : NULL, node, options, 0); - - if (short_name) { - xdebug_str_free(short_name); - } - if (full_name) { - xdebug_str_free(full_name); - } - - return node; -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/profiler/profiler.c
Deleted
@@ -1,554 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifdef PHP_WIN32 -#include <process.h> -#endif - -#include "php.h" -#include "TSRM.h" -#include "php_globals.h" -#include "Zend/zend_alloc.h" - -#include "php_xdebug.h" -#include "profiler.h" -#include "profiler_private.h" - -#include "lib/log.h" -#include "lib/mm.h" -#include "lib/str.h" -#include "lib/var.h" -#include "lib/usefulstuff.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -int xdebug_profiler_exit_handler(XDEBUG_OPCODE_HANDLER_ARGS); - -void xdebug_init_profiler_globals(xdebug_profiler_globals_t *xg) -{ - xg->active = 0; -} - -void xdebug_profiler_minit(void) -{ - /* Overload the "exit" opcode */ - xdebug_set_opcode_handler(ZEND_EXIT, xdebug_profiler_exit_handler); -} - -void xdebug_profiler_mshutdown(void) -{ -} - -void xdebug_profiler_rinit(void) -{ - xdebug_file_init(&XG_PROF(profile_file)); - XG_PROF(profile_filename_refs) = NULL; - XG_PROF(profile_functionname_refs) = NULL; - XG_PROF(profile_last_filename_ref) = 0; - XG_PROF(php_internal_seen_before) = 0; - XG_PROF(profile_last_functionname_ref) = 0; - XG_PROF(active) = 0; -} - -static void deinit_if_active(void) -{ - if (!XG_PROF(active)) { - return; - } - - xdebug_profiler_deinit(); -} - -void xdebug_profiler_post_deactivate(void) -{ - deinit_if_active(); -} - -void xdebug_profiler_pcntl_exec_handler(void) -{ - deinit_if_active(); -} - -int xdebug_profiler_exit_handler(XDEBUG_OPCODE_HANDLER_ARGS) -{ - const zend_op *cur_opcode = execute_data->opline; - - deinit_if_active(); - - return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); -} - - -void xdebug_profiler_init_if_requested(zend_op_array *op_array) -{ - if (XG_PROF(active)) { - return; - } - - if (EG(flags) & EG_FLAGS_IN_SHUTDOWN) { - return; - } - - if (xdebug_lib_start_with_request(XDEBUG_MODE_PROFILING) || xdebug_lib_start_with_trigger(XDEBUG_MODE_PROFILING, NULL)) { - xdebug_profiler_init((char*) STR_NAME_VAL(op_array->filename)); - } -} - -void xdebug_profiler_execute_ex(function_stack_entry *fse, zend_op_array *op_array) -{ - if (!XG_PROF(active)) { - return; - } - - /* Calculate all elements for profile entries */ - xdebug_profiler_add_function_details_user(fse, op_array); - xdebug_profiler_function_begin(fse); -} - -void xdebug_profiler_execute_ex_end(function_stack_entry *fse) -{ - xdebug_profiler_function_end(fse); - xdebug_profiler_free_function_details(fse); -} - -void xdebug_profiler_execute_internal(function_stack_entry *fse) -{ - if (!XG_PROF(active)) { - return; - } - - xdebug_profiler_add_function_details_internal(fse); - xdebug_profiler_function_begin(fse); -} - -void xdebug_profiler_execute_internal_end(function_stack_entry *fse) -{ - if (!XG_PROF(active)) { - return; - } - - xdebug_profiler_function_end(fse); - xdebug_profiler_free_function_details(fse); -} - -void xdebug_profile_call_entry_dtor(void *dummy, void *elem) -{ - xdebug_call_entry *ce = elem; - - if (ce->function) { - xdfree(ce->function); - } - if (ce->filename) { - zend_string_release(ce->filename); - } - xdfree(ce); -} - -static void profiler_write_header(xdebug_file *file, char *script_name) -{ - if (XINI_PROF(profiler_append)) { - xdebug_file_printf(file, "\n==== NEW PROFILING FILE ==============================================\n"); - } - xdebug_file_printf(file, "version: 1\ncreator: xdebug %s (PHP %s)\n", XDEBUG_VERSION, XG_BASE(php_version_run_time)); - xdebug_file_printf(file, "cmd: %s\npart: 1\npositions: line\n\n", script_name); - xdebug_file_printf(file, "events: Time_(10ns) Memory_(bytes)\n\n"); - xdebug_file_flush(file); -} - -#define NANOTIME_SCALE_10NS(nanotime) ((unsigned long)(((nanotime) + 5) / 10)) - -void xdebug_profiler_init(char *script_name) -{ - char *filename = NULL, *fname = NULL; - char *output_dir = NULL; - - if (XG_PROF(active)) { - return; - } - - if (!strlen(XINI_PROF(profiler_output_name)) || - xdebug_format_output_filename(&fname, XINI_PROF(profiler_output_name), script_name) <= 0 - ) { - /* Invalid or empty xdebug.profiler_output_name */ - return; - } - - /* Add a slash if none is present in the output_dir setting */ - output_dir = xdebug_lib_get_output_dir(); /* not duplicated */ - - if (IS_SLASH(output_dirstrlen(output_dir) - 1)) { - filename = xdebug_sprintf("%s%s", output_dir, fname); - } else { - filename = xdebug_sprintf("%s%c%s", output_dir, DEFAULT_SLASH, fname); - } - - if (!xdebug_file_open(&XG_PROF(profile_file), filename, NULL, XINI_PROF(profiler_append) ? "a" : "w")) { - xdebug_log_diagnose_permissions(XLOG_CHAN_PROFILE, output_dir, fname); - goto return_and_free_names; - } - - profiler_write_header(&XG_PROF(profile_file), script_name); - - if (!SG(headers_sent)) { - sapi_header_line ctr = {0}; - - ctr.line = xdebug_sprintf("X-Xdebug-Profile-Filename: %s", XG_PROF(profile_file).name); - ctr.line_len = strlen(ctr.line); - sapi_header_op(SAPI_HEADER_REPLACE, &ctr); - xdfree((void*) ctr.line); - } - - XG_PROF(profiler_start_nanotime) = xdebug_get_nanotime(); - - XG_PROF(active) = 1; - XG_PROF(profile_filename_refs) = xdebug_hash_alloc(128, xdfree); - XG_PROF(profile_functionname_refs) = xdebug_hash_alloc(128, xdfree); - XG_PROF(profile_last_filename_ref) = 1; - XG_PROF(profile_last_functionname_ref) = 0; - -return_and_free_names: - xdfree(filename); - xdfree(fname); -} - -void xdebug_profiler_deinit() -{ - function_stack_entry *fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - int i; - - for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, fse--) { - xdebug_profiler_function_end(fse); - } - - xdebug_file_printf( - &XG_PROF(profile_file), - "summary: %lu %zd\n\n", - NANOTIME_SCALE_10NS(xdebug_get_nanotime() - XG_PROF(profiler_start_nanotime)), - zend_memory_peak_usage(0) - ); - - XG_PROF(active) = 0; - - xdebug_file_flush(&XG_PROF(profile_file)); - - if (XG_PROF(profile_file).type != XDEBUG_FILE_TYPE_NULL) { - xdebug_file_close(&XG_PROF(profile_file)); - xdebug_file_deinit(&XG_PROF(profile_file)); - } - - xdebug_hash_destroy(XG_PROF(profile_filename_refs)); - xdebug_hash_destroy(XG_PROF(profile_functionname_refs)); - XG_PROF(profile_filename_refs) = NULL; - XG_PROF(profile_functionname_refs) = NULL; -} - -static inline void xdebug_profiler_function_push(function_stack_entry *fse) -{ - fse->profile.nanotime += (xdebug_get_nanotime() - fse->profile.nanotime_mark); - fse->profile.nanotime_mark = 0; - fse->profile.memory += (zend_memory_usage(0) - fse->profile.mem_mark); - fse->profile.mem_mark = 0; -} - -void xdebug_profiler_function_continue(function_stack_entry *fse) -{ - fse->profile.nanotime_mark = xdebug_get_nanotime(); -} - -void xdebug_profiler_function_pause(function_stack_entry *fse) -{ - xdebug_profiler_function_push(fse); -} - -static inline void add_filename_ref(xdebug_str *buffer, char *name) -{ - char *ref; - - if (xdebug_hash_find(XG_PROF(profile_filename_refs), name, strlen(name), (void*) &ref)) { - xdebug_str_add(buffer, ref, 0); - } else { - XG_PROF(profile_last_filename_ref)++; - ref = xdebug_sprintf("(%d)", XG_PROF(profile_last_filename_ref)); - - xdebug_hash_add(XG_PROF(profile_filename_refs), name, strlen(name), (void*) ref); - - xdebug_str_add(buffer, ref, 0); - xdebug_str_addc(buffer, ' '); - xdebug_str_add(buffer, name, 0); - } -} - -static inline void add_functionname_ref(xdebug_str *buffer, char *name) -{ - char *ref; - - if (xdebug_hash_find(XG_PROF(profile_functionname_refs), name, strlen(name), (void*) &ref)) { - xdebug_str_add(buffer, ref, 0); - } else { - XG_PROF(profile_last_functionname_ref)++; - ref = xdebug_sprintf("(%d)", XG_PROF(profile_last_functionname_ref)); - - xdebug_hash_add(XG_PROF(profile_functionname_refs), name, strlen(name), (void*) ref); - - xdebug_str_add(buffer, ref, 0); - xdebug_str_addc(buffer, ' '); - xdebug_str_add(buffer, name, 0); - } -} - -void xdebug_profiler_add_function_details_user(function_stack_entry *fse, zend_op_array *op_array) -{ - char *tmp_fname, *tmp_name; - - tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); - switch (fse->function.type) { - case XFUNC_INCLUDE: - case XFUNC_INCLUDE_ONCE: - case XFUNC_REQUIRE: - case XFUNC_REQUIRE_ONCE: - tmp_fname = xdebug_sprintf("%s::%s", tmp_name, ZSTR_VAL(fse->include_filename)); - xdfree(tmp_name); - tmp_name = tmp_fname; - fse->profiler.lineno = 1; - break; - - default: - if (op_array/* && op_array->function_name*/) { - fse->profiler.lineno = fse->op_array->line_start; - } else { - fse->profiler.lineno = fse->lineno; - } - break; - } - if (fse->profiler.lineno == 0) { - fse->profiler.lineno = 1; - } - - if (op_array && op_array->filename) { - fse->profiler.filename = zend_string_copy(op_array->filename); - } else { - fse->profiler.filename = zend_string_copy(fse->filename); - } - fse->profiler.funcname = xdstrdup(tmp_name); - xdfree(tmp_name); -} - -void xdebug_profiler_add_function_details_internal(function_stack_entry *fse) -{ - char *tmp_fname, *tmp_name; - - tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); - switch (fse->function.type) { - case XFUNC_INCLUDE: - case XFUNC_INCLUDE_ONCE: - case XFUNC_REQUIRE: - case XFUNC_REQUIRE_ONCE: - tmp_fname = xdebug_sprintf("%s::%s", tmp_name, fse->include_filename); - xdfree(tmp_name); - tmp_name = tmp_fname; - fse->profiler.lineno = 1; - break; - - default: - fse->profiler.lineno = fse->lineno; - break; - } - if (fse->profiler.lineno == 0) { - fse->profiler.lineno = 1; - } - - fse->profiler.filename = zend_string_copy(fse->filename); - fse->profiler.funcname = xdstrdup(tmp_name); - - xdfree(tmp_name); -} - -void xdebug_profiler_function_begin(function_stack_entry *fse) -{ - fse->profile.nanotime = 0; - fse->profile.nanotime_mark = xdebug_get_nanotime(); - fse->profile.memory = 0; - fse->profile.mem_mark = zend_memory_usage(0); -} - -#define TMP_KEY_BUFFER_LEN 1024 -#define TMP_KEY_PREFIX "php::" -#define TMP_KEY_PREFIX_LEN (sizeof(TMP_KEY_PREFIX)-1) -#define TMP_KEY_MAX_LEN (TMP_KEY_BUFFER_LEN-TMP_KEY_PREFIX_LEN-1) - -void xdebug_profiler_function_end(function_stack_entry *fse) -{ - xdebug_llist_element *le; - xdebug_str file_buffer = XDEBUG_STR_INITIALIZER; - char tmp_keyTMP_KEY_BUFFER_LEN; - - if (!XG_PROF(active)) { - return; - } - - /* The temporary key always starts with 'php::' */ - memcpy(tmp_key, TMP_KEY_PREFIX, TMP_KEY_PREFIX_LEN); - - if (xdebug_vector_element_is_valid(XG_BASE(stack), fse - 1) && !(fse - 1)->profile.call_list) { - (fse - 1)->profile.call_list = xdebug_llist_alloc(xdebug_profile_call_entry_dtor); - } - if (!fse->profile.call_list) { - fse->profile.call_list = xdebug_llist_alloc(xdebug_profile_call_entry_dtor); - } - xdebug_profiler_function_push(fse); - - if (xdebug_vector_element_is_valid(XG_BASE(stack), fse - 1)) { - xdebug_call_entry *ce = xdmalloc(sizeof(xdebug_call_entry)); - - ce->filename = zend_string_copy(fse->profiler.filename); - ce->function = xdstrdup(fse->profiler.funcname); - ce->nanotime_taken = fse->profile.nanotime; - ce->lineno = fse->lineno; - ce->user_defined = fse->user_defined; - ce->mem_used = fse->profile.memory; - - xdebug_llist_insert_next((fse - 1)->profile.call_list, NULL, ce); - } - - /* use previously created filename and funcname (or a reference to them) to show - * time spend */ - if (fse->user_defined == XDEBUG_BUILT_IN) { - size_t tmp_key_funcname_len = strlen(fse->profiler.funcname); - - memcpy(tmp_key + TMP_KEY_PREFIX_LEN, - fse->profiler.funcname, - tmp_key_funcname_len > TMP_KEY_MAX_LEN ? TMP_KEY_MAX_LEN : tmp_key_funcname_len + 1 - ); - tmp_keyTMP_KEY_BUFFER_LEN - 1 = '\0'; - - if (XG_PROF(php_internal_seen_before)) { - xdebug_str_add_literal(&file_buffer, "fl=(1)\n"); - } else { - xdebug_str_add_literal(&file_buffer, "fl=(1) php:internal\n"); - XG_PROF(php_internal_seen_before) = 1; - } - xdebug_str_add_literal(&file_buffer, "fn="); - add_functionname_ref(&file_buffer, tmp_key); - xdebug_str_addc(&file_buffer, '\n'); - } else { - - xdebug_str_add_literal(&file_buffer, "fl="); - add_filename_ref(&file_buffer, ZSTR_VAL(fse->profiler.filename)); - - xdebug_str_add_literal(&file_buffer, "\nfn="); - add_functionname_ref(&file_buffer, fse->profiler.funcname); - xdebug_str_addc(&file_buffer, '\n'); - } - - - /* Subtract time in calledfunction from time here */ - for (le = XDEBUG_LLIST_HEAD(fse->profile.call_list); le != NULL; le = XDEBUG_LLIST_NEXT(le)) - { - xdebug_call_entry *call_entry = XDEBUG_LLIST_VALP(le); - fse->profile.nanotime -= call_entry->nanotime_taken; - fse->profile.memory -= call_entry->mem_used; - } - - /* Adds %d %lu %lu, with lineno, time, and memory */ - xdebug_str_add_uint64(&file_buffer, fse->profiler.lineno); - xdebug_str_addc(&file_buffer, ' '); - xdebug_str_add_uint64(&file_buffer, NANOTIME_SCALE_10NS(fse->profile.nanotime)); - xdebug_str_addc(&file_buffer, ' '); - xdebug_str_add_uint64(&file_buffer, fse->profile.memory >= 0 ? fse->profile.memory : 0); - xdebug_str_addc(&file_buffer, '\n'); - - /* dump call list */ - for (le = XDEBUG_LLIST_HEAD(fse->profile.call_list); le != NULL; le = XDEBUG_LLIST_NEXT(le)) - { - xdebug_call_entry *call_entry = XDEBUG_LLIST_VALP(le); - - if (call_entry->user_defined == XDEBUG_BUILT_IN) { - size_t tmp_key_funcname_len = strlen(call_entry->function); - - memcpy(tmp_key + TMP_KEY_PREFIX_LEN, - call_entry->function, - tmp_key_funcname_len > TMP_KEY_MAX_LEN ? TMP_KEY_MAX_LEN : tmp_key_funcname_len + 1 - ); - tmp_keyTMP_KEY_BUFFER_LEN - 1 = '\0'; - - if (XG_PROF(php_internal_seen_before)) { - xdebug_str_add_literal(&file_buffer, "cfl=(1)\n"); - } else { - xdebug_str_add_literal(&file_buffer, "cfl=(1) php:internal\n"); - XG_PROF(php_internal_seen_before) = 1; - } - - xdebug_str_add_literal(&file_buffer, "cfn="); - add_functionname_ref(&file_buffer, tmp_key); - xdebug_str_addc(&file_buffer, '\n'); - } else { - xdebug_str_add_literal(&file_buffer, "cfl="); - add_filename_ref(&file_buffer, ZSTR_VAL(call_entry->filename)); - - xdebug_str_add_literal(&file_buffer, "\ncfn="); - add_functionname_ref(&file_buffer, call_entry->function); - xdebug_str_addc(&file_buffer, '\n'); - } - - xdebug_str_add_literal(&file_buffer, "calls=1 0 0\n"); - - /* Adds %d %lu %lu, with lineno, time, and memory */ - xdebug_str_add_uint64(&file_buffer, call_entry->lineno); - xdebug_str_addc(&file_buffer, ' '); - xdebug_str_add_uint64(&file_buffer, NANOTIME_SCALE_10NS(call_entry->nanotime_taken)); - xdebug_str_addc(&file_buffer, ' '); - xdebug_str_add_uint64(&file_buffer, call_entry->mem_used >= 0 ? call_entry->mem_used : 0); - xdebug_str_addc(&file_buffer, '\n'); - } - xdebug_str_addc(&file_buffer, '\n'); - - xdebug_file_write(file_buffer.d, sizeof(char), file_buffer.l, &XG_PROF(profile_file)); - xdebug_str_dtor(file_buffer); -} - -void xdebug_profiler_free_function_details(function_stack_entry *fse) -{ - if (fse->profiler.funcname) { - xdfree(fse->profiler.funcname); - fse->profiler.funcname = NULL; - } - if (fse->profiler.filename) { - zend_string_release(fse->profiler.filename); - fse->profiler.filename = NULL; - } -} - -/* Returns a *pointer* to the current profile filename, if active. NULL - * otherwise. Calling function is responsible for duplicating immediately */ -char *xdebug_get_profiler_filename() -{ - if (!XG_PROF(active)) { - return NULL; - } - - return XG_PROF(profile_file).name; -} - -PHP_FUNCTION(xdebug_get_profiler_filename) -{ - char *filename = xdebug_get_profiler_filename(); - - if (!filename) { - RETURN_FALSE; - } - - RETURN_STRING(filename); -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/profiler/profiler.h
Deleted
@@ -1,72 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifndef __XDEBUG_PROFILER_H__ -#define __XDEBUG_PROFILER_H__ - -#include "php.h" -#include "TSRM.h" -#include "lib/file.h" -#include "lib/lib.h" - -#include "php_xdebug.h" - -typedef struct _xdebug_profiler_globals_t { - zend_bool active; - uint64_t profiler_start_nanotime; - xdebug_file profile_file; - xdebug_hash *profile_filename_refs; - int profile_last_filename_ref; - int php_internal_seen_before; - xdebug_hash *profile_functionname_refs; - int profile_last_functionname_ref; -} xdebug_profiler_globals_t; - -typedef struct _xdebug_profiler_settings_t { - char *profiler_output_name; /* "pid" or "crc32" */ - zend_bool profiler_append; -} xdebug_profiler_settings_t; - -void xdebug_init_profiler_globals(xdebug_profiler_globals_t *xg); -void xdebug_profiler_minit(void); -void xdebug_profiler_mshutdown(void); -void xdebug_profiler_rinit(void); -void xdebug_profiler_post_deactivate(void); - -void xdebug_profiler_pcntl_exec_handler(void); - -void xdebug_profiler_init_if_requested(zend_op_array *op_array); -void xdebug_profiler_execute_ex(function_stack_entry *fse, zend_op_array *op_array); -void xdebug_profiler_execute_ex_end(function_stack_entry *fse); -void xdebug_profiler_execute_internal(function_stack_entry *fse); -void xdebug_profiler_execute_internal_end(function_stack_entry *fse); - -void xdebug_profiler_init(char *script_name); -void xdebug_profiler_deinit(); - -void xdebug_profiler_add_function_details_user(function_stack_entry *fse, zend_op_array *op_array); -void xdebug_profiler_add_function_details_internal(function_stack_entry *fse); -void xdebug_profiler_free_function_details(function_stack_entry *fse); - -void xdebug_profiler_function_begin(function_stack_entry *fse); -void xdebug_profiler_function_end(function_stack_entry *fse); - -void xdebug_profile_call_entry_dtor(void *dummy, void *elem); - -char *xdebug_get_profiler_filename(void); - -PHP_FUNCTION(xdebug_get_profiler_filename); -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/tracing/trace_computerized.c
Deleted
@@ -1,274 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ -#include "php.h" -#include "ext/standard/php_string.h" - -#include "php_xdebug.h" -#include "tracing_private.h" -#include "trace_computerized.h" - -#include "lib/lib_private.h" -#include "lib/var_export_line.h" - -extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); - -void *xdebug_trace_computerized_init(char *fname, zend_string *script_filename, long options) -{ - xdebug_trace_computerized_context *tmp_computerized_context; - - tmp_computerized_context = xdmalloc(sizeof(xdebug_trace_computerized_context)); - tmp_computerized_context->trace_file = xdebug_trace_open_file(fname, script_filename, options); - - if (!tmp_computerized_context->trace_file) { - xdfree(tmp_computerized_context); - return NULL; - } - - return tmp_computerized_context; -} - -void xdebug_trace_computerized_deinit(void *ctxt) -{ - xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; - - xdebug_file_close(context->trace_file); - xdebug_file_dtor(context->trace_file); - context->trace_file = NULL; - - xdfree(context); -} - -void xdebug_trace_computerized_write_header(void *ctxt) -{ - xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; - char *str_time; - - xdebug_file_printf(context->trace_file, "Version: %s\n", XDEBUG_VERSION); - xdebug_file_printf(context->trace_file, "File format: 4\n"); - - str_time = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6); - xdebug_file_printf(context->trace_file, "TRACE START %s\n", str_time); - xdfree(str_time); - - xdebug_file_flush(context->trace_file); -} - -void xdebug_trace_computerized_write_footer(void *ctxt) -{ - xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; - char *str_time; - uint64_t nanotime; - - nanotime = xdebug_get_nanotime(); - - xdebug_file_printf(context->trace_file, "\t\t\t%F\t", XDEBUG_SECONDS_SINCE_START(nanotime)); - xdebug_file_printf(context->trace_file, "%zu", zend_memory_usage(0)); - xdebug_file_printf(context->trace_file, "\n"); - - str_time = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6); - xdebug_file_printf(context->trace_file, "TRACE END %s\n\n", str_time); - xdfree(str_time); - - xdebug_file_flush(context->trace_file); -} - -char *xdebug_trace_computerized_get_filename(void *ctxt) -{ - xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; - - return context->trace_file->name; -} - -static void add_single_value(xdebug_str *str, zval *zv) -{ - xdebug_str *tmp_value = NULL; - - tmp_value = xdebug_get_zval_value_line(zv, 0, NULL); - - if (tmp_value) { - xdebug_str_add_str(str, tmp_value); - xdebug_str_free(tmp_value); - } else { - xdebug_str_add_literal(str, "???"); - } -} - -static void add_arguments(xdebug_str *line_entry, function_stack_entry *fse) -{ - unsigned int j = 0; /* Counter */ - int sent_variables = fse->varc; - - if (sent_variables > 0 && fse->varsent_variables-1.is_variadic && Z_ISUNDEF(fse->varsent_variables-1.data)) { - sent_variables--; - } - - /* Nr of arguments (11) */ - xdebug_str_add_fmt(line_entry, "\t%d", sent_variables); - - /* Arguments (12-...) */ - for (j = 0; j < sent_variables; j++) { - xdebug_str_addc(line_entry, '\t'); - - if (!Z_ISUNDEF(fse->varj.data)) { - add_single_value(line_entry, &(fse->varj.data)); - } else { - xdebug_str_add_literal(line_entry, "???"); - } - } -} - -void xdebug_trace_computerized_function_entry(void *ctxt, function_stack_entry *fse, int function_nr) -{ - xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; - char *tmp_name; - xdebug_str str = XDEBUG_STR_INITIALIZER; - - xdebug_str_add_fmt(&str, "%d\t", fse->level); - xdebug_str_add_fmt(&str, "%d\t", function_nr); - - tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); - - xdebug_str_add_literal(&str, "0\t"); - xdebug_str_add_fmt(&str, "%F\t", XDEBUG_SECONDS_SINCE_START(fse->nanotime)); - xdebug_str_add_fmt(&str, "%lu\t", fse->memory); - xdebug_str_add_fmt(&str, "%s\t", tmp_name); - if (fse->user_defined == XDEBUG_USER_DEFINED) { - xdebug_str_add_literal(&str, "1\t"); - } else { - xdebug_str_add_literal(&str, "0\t"); - } - xdfree(tmp_name); - - if (fse->include_filename) { - if (fse->function.type == XFUNC_EVAL) { - zend_string *escaped; -#if PHP_VERSION_ID >= 70300 - escaped = php_addcslashes(fse->include_filename, (char*) "'\\\0..\37", 6); -#else - escaped = php_addcslashes(fse->include_filename, 0, (char*) "'\\\0..\37", 6); -#endif - xdebug_str_addc(&str, '\''); - xdebug_str_add_zstr(&str, escaped); - xdebug_str_addc(&str, '\''); - zend_string_release(escaped); - } else { - xdebug_str_add_zstr(&str, fse->include_filename); - } - } - - /* Filename and Lineno (9, 10) */ - xdebug_str_add_fmt(&str, "\t%s\t%d", ZSTR_VAL(fse->filename), fse->lineno); - - add_arguments(&str, fse); - - /* Trailing \n */ - xdebug_str_addc(&str, '\n'); - - xdebug_file_printf(context->trace_file, "%s", str.d); - xdebug_file_flush(context->trace_file); - xdfree(str.d); -} - -void xdebug_trace_computerized_function_exit(void *ctxt, function_stack_entry *fse, int function_nr) -{ - xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; - xdebug_str str = XDEBUG_STR_INITIALIZER; - - xdebug_str_add_fmt(&str, "%d\t", fse->level); - xdebug_str_add_fmt(&str, "%d\t", function_nr); - - xdebug_str_add_literal(&str, "1\t"); - xdebug_str_add_fmt(&str, "%F\t", XDEBUG_SECONDS_SINCE_START(xdebug_get_nanotime())); - xdebug_str_add_fmt(&str, "%lu\n", zend_memory_usage(0)); - - xdebug_file_printf(context->trace_file, "%s", str.d); - xdebug_file_flush(context->trace_file); - xdfree(str.d); -} - -void xdebug_trace_computerized_function_return_value(void *ctxt, function_stack_entry *fse, int function_nr, zval *return_value) -{ - xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; - xdebug_str str = XDEBUG_STR_INITIALIZER; - - xdebug_str_add_fmt(&str, "%d\t", fse->level); - xdebug_str_add_fmt(&str, "%d\t", function_nr); - xdebug_str_add_literal(&str, "R\t\t\t"); - - add_single_value(&str, return_value); - - xdebug_str_add_literal(&str, "\n"); - - xdebug_file_printf(context->trace_file, "%s", str.d); - xdebug_file_flush(context->trace_file); - xdfree(str.d); -} - -void xdebug_trace_computerized_assignment(void *ctxt, function_stack_entry *fse, char *full_varname, zval *retval, char *right_full_varname, const char *op, char *filename, int lineno) -{ - xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; - xdebug_str str = XDEBUG_STR_INITIALIZER; - xdebug_str *tmp_value; - - xdebug_str_add_fmt(&str, "%d\t", fse->level); - /* no function_nr */ - xdebug_str_add_literal(&str, "\t"); - - xdebug_str_add_literal(&str, "A\t"); - /* skip time index, memory usage, function name, user defined */ - xdebug_str_add_literal(&str, "\t\t\t\t"); - - /* Filename and Lineno (9, 10) */ - xdebug_str_add_fmt(&str, "\t%s\t%d", filename, lineno); - xdebug_str_add_fmt(&str, "\t%s", full_varname); - - if (op0 != '\0' ) { /* pre/post inc/dec ops are special */ - xdebug_str_addc(&str, ' '); - xdebug_str_add(&str, op, 0); - xdebug_str_addc(&str, ' '); - - tmp_value = xdebug_get_zval_value_line(retval, 0, NULL); - - if (tmp_value) { - xdebug_str_add_str(&str, tmp_value); - xdebug_str_free(tmp_value); - } else { - xdebug_str_add_literal(&str, "NULL"); - } - } - - /* Trailing \n */ - xdebug_str_add_literal(&str, "\n"); - - xdebug_file_printf(context->trace_file, "%s", str.d); - xdebug_file_flush(context->trace_file); - - xdfree(str.d); -} - -xdebug_trace_handler_t xdebug_trace_handler_computerized = -{ - xdebug_trace_computerized_init, - xdebug_trace_computerized_deinit, - xdebug_trace_computerized_write_header, - xdebug_trace_computerized_write_footer, - xdebug_trace_computerized_get_filename, - xdebug_trace_computerized_function_entry, - xdebug_trace_computerized_function_exit, - xdebug_trace_computerized_function_return_value, - NULL /* xdebug_trace_computerized_generator_return_value */, - xdebug_trace_computerized_assignment -};
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/tracing/trace_html.c
Deleted
@@ -1,136 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ -#include "php.h" - -#include "php_xdebug.h" -#include "tracing_private.h" -#include "trace_html.h" - -#include "lib/var.h" - -extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); - -void *xdebug_trace_html_init(char *fname, zend_string *script_filename, long options) -{ - xdebug_trace_html_context *tmp_html_context; - - tmp_html_context = xdmalloc(sizeof(xdebug_trace_html_context)); - tmp_html_context->trace_file = xdebug_trace_open_file(fname, script_filename, options); - - if (!tmp_html_context->trace_file) { - xdfree(tmp_html_context); - return NULL; - } - - return tmp_html_context; -} - -void xdebug_trace_html_deinit(void *ctxt) -{ - xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt; - - xdebug_file_close(context->trace_file); - xdebug_file_dtor(context->trace_file); - context->trace_file = NULL; - - xdfree(context); -} - -void xdebug_trace_html_write_header(void *ctxt) -{ - xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt; - - xdebug_file_printf(context->trace_file, "<table style='hyphens: auto; -webkit-hyphens: auto; -ms-hyphens: auto;' class='xdebug-trace' dir='ltr' border='1' cellspacing='0'>\n"); - xdebug_file_printf(context->trace_file, "\t<tr><th>#</th><th>Time</th>"); - xdebug_file_printf(context->trace_file, "<th>Mem</th>"); - xdebug_file_printf(context->trace_file, "<th colspan='2'>Function</th><th>Location</th></tr>\n"); - xdebug_file_flush(context->trace_file); -} - -void xdebug_trace_html_write_footer(void *ctxt) -{ - xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt; - - xdebug_file_printf(context->trace_file, "</table>\n"); - xdebug_file_flush(context->trace_file); -} - -char *xdebug_trace_html_get_filename(void *ctxt) -{ - xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt; - - return context->trace_file->name; -} - -void xdebug_trace_html_function_entry(void *ctxt, function_stack_entry *fse, int function_nr) -{ - xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt; - char *tmp_name; - unsigned int j; - xdebug_str str = XDEBUG_STR_INITIALIZER; - - xdebug_str_add_literal(&str, "\t<tr>"); - xdebug_str_add_fmt(&str, "<td>%d</td>", function_nr); - xdebug_str_add_fmt(&str, "<td>%0.6F</td>", XDEBUG_SECONDS_SINCE_START(fse->nanotime)); - xdebug_str_add_fmt(&str, "<td align='right'>%lu</td>", fse->memory); - xdebug_str_add_literal(&str, "<td align='left'>"); - for (j = 0; j < fse->level - 1; j++) { - xdebug_str_add_literal(&str, " "); - } - xdebug_str_add_literal(&str, "-></td>"); - - tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); - xdebug_str_add_fmt(&str, "<td>%s(", tmp_name); - xdfree(tmp_name); - - if (fse->include_filename) { - if (fse->function.type == XFUNC_EVAL) { - xdebug_str *joined; - xdebug_arg *parts; - - parts = xdebug_arg_ctor(); - xdebug_explode("\n", ZSTR_VAL(fse->include_filename), parts, 99999); - joined = xdebug_join("<br />", parts, 0, 99999); - xdebug_arg_dtor(parts); - - xdebug_str_add_fmt(&str, "'%s'", joined->d); - xdebug_str_free(joined); - } else { - xdebug_str_add_zstr(&str, fse->include_filename); - } - } - - xdebug_str_add_fmt(&str, ")</td><td>%s:%d</td>", ZSTR_VAL(fse->filename), fse->lineno); - xdebug_str_add_literal(&str, "</tr>\n"); - - xdebug_file_printf(context->trace_file, "%s", str.d); - xdebug_file_flush(context->trace_file); - xdfree(str.d); -} - -xdebug_trace_handler_t xdebug_trace_handler_html = -{ - xdebug_trace_html_init, - xdebug_trace_html_deinit, - xdebug_trace_html_write_header, - xdebug_trace_html_write_footer, - xdebug_trace_html_get_filename, - xdebug_trace_html_function_entry, - NULL /* xdebug_trace_html_function_exit */, - NULL /* xdebug_trace_html_function_return_value */, - NULL /* xdebug_trace_html_generator_return_value */, - NULL /* xdebug_trace_html_assignment */ -};
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/tracing/trace_textual.c
Deleted
@@ -1,342 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ -#include "php.h" -#include "ext/standard/php_string.h" - -#include "php_xdebug.h" -#include "tracing_private.h" -#include "trace_textual.h" - -#include "lib/lib_private.h" -#include "lib/var_export_line.h" - -extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); - -void *xdebug_trace_textual_init(char *fname, zend_string *script_filename, long options) -{ - xdebug_trace_textual_context *tmp_textual_context; - - tmp_textual_context = xdmalloc(sizeof(xdebug_trace_textual_context)); - tmp_textual_context->trace_file = xdebug_trace_open_file(fname, script_filename, options); - - if (!tmp_textual_context->trace_file) { - xdfree(tmp_textual_context); - return NULL; - } - - return tmp_textual_context; -} - -void xdebug_trace_textual_deinit(void *ctxt) -{ - xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; - - xdebug_file_close(context->trace_file); - xdebug_file_dtor(context->trace_file); - context->trace_file = NULL; - - xdfree(context); -} - -void xdebug_trace_textual_write_header(void *ctxt) -{ - xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; - char *str_time; - - str_time = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6); - xdebug_file_printf(context->trace_file, "TRACE START %s\n", str_time); - xdfree(str_time); - - xdebug_file_flush(context->trace_file); -} - -void xdebug_trace_textual_write_footer(void *ctxt) -{ - xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; - char *str_time; - uint64_t nanotime; - char *tmp; - - nanotime = xdebug_get_nanotime(); - tmp = xdebug_sprintf("%10.4F ", XDEBUG_SECONDS_SINCE_START(nanotime)); - xdebug_file_printf(context->trace_file, "%s", tmp); - xdfree(tmp); - xdebug_file_printf(context->trace_file, "%10zu", zend_memory_usage(0)); - xdebug_file_printf(context->trace_file, "\n"); - - str_time = xdebug_nanotime_to_chars(nanotime, 6); - xdebug_file_printf(context->trace_file, "TRACE END %s\n\n", str_time); - xdfree(str_time); - - xdebug_file_flush(context->trace_file); -} - -char *xdebug_trace_textual_get_filename(void *ctxt) -{ - xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; - - return context->trace_file->name; -} - -static void add_single_value(xdebug_str *str, zval *zv) -{ - xdebug_str *tmp_value = NULL; - - tmp_value = xdebug_get_zval_value_line(zv, 0, NULL); - - if (tmp_value) { - xdebug_str_add_str(str, tmp_value); - xdebug_str_free(tmp_value); - } else { - xdebug_str_add_literal(str, "???"); - } -} - -static void add_arguments(xdebug_str *line_entry, function_stack_entry *fse) -{ - unsigned int j = 0; /* Counter */ - int c = 0; /* Comma flag */ - int variadic_opened = 0; - int variadic_count = 0; - int sent_variables = fse->varc; - - if (sent_variables > 0 && fse->varsent_variables-1.is_variadic && Z_ISUNDEF(fse->varsent_variables-1.data)) { - sent_variables--; - } - - for (j = 0; j < sent_variables; j++) { - if (c) { - xdebug_str_add_literal(line_entry, ", "); - } else { - c = 1; - } - - if (fse->varj.is_variadic) { - xdebug_str_add_literal(line_entry, "..."); - variadic_opened = 1; - c = 0; - } - - if (fse->varj.name) { - xdebug_str_addc(line_entry, '$'); - xdebug_str_add_zstr(line_entry, fse->varj.name); - if (variadic_opened && !fse->varj.is_variadic) { - xdebug_str_add_literal(line_entry, " => "); - } else { - xdebug_str_add_literal(line_entry, " = "); - } - } - - if (fse->varj.is_variadic) { - xdebug_str_add_literal(line_entry, "variadic("); - if (Z_ISUNDEF(fse->varj.data)) { - continue; - } - c = 1; - } - - if (variadic_opened && (!fse->varj.name || fse->varj.is_variadic)) { - xdebug_str_add_fmt(line_entry, "%d => ", variadic_count++); - } - - if (!Z_ISUNDEF(fse->varj.data)) { - add_single_value(line_entry, &fse->varj.data); - } else { - xdebug_str_add_literal(line_entry, "???"); - } - } - - if (variadic_opened) { - xdebug_str_addc(line_entry, ')'); - } -} - -void xdebug_trace_textual_function_entry(void *ctxt, function_stack_entry *fse, int function_nr) -{ - xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; - unsigned int j = 0; /* Counter */ - char *tmp_name; - xdebug_str str = XDEBUG_STR_INITIALIZER; - - tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); - - xdebug_str_add_fmt(&str, "%10.4F ", XDEBUG_SECONDS_SINCE_START(fse->nanotime)); - xdebug_str_add_fmt(&str, "%10lu ", fse->memory); - for (j = 0; j < fse->level; j++) { - xdebug_str_add_literal(&str, " "); - } - xdebug_str_add_fmt(&str, "-> %s(", tmp_name); - - xdfree(tmp_name); - - add_arguments(&str, fse); - - if (fse->include_filename) { - if (fse->function.type == XFUNC_EVAL) { - zend_string *escaped; -#if PHP_VERSION_ID >= 70300 - escaped = php_addcslashes(fse->include_filename, (char*) "'\\\0..\37", 6); -#else - escaped = php_addcslashes(fse->include_filename, 0, (char*) "'\\\0..\37", 6); -#endif - xdebug_str_addc(&str, '\''); - xdebug_str_add_zstr(&str, escaped); - xdebug_str_addc(&str, '\''); - zend_string_release(escaped); - } else { - xdebug_str_add_zstr(&str, fse->include_filename); - } - } - - xdebug_str_add_fmt(&str, ") %s:%d\n", ZSTR_VAL(fse->filename), fse->lineno); - - xdebug_file_printf(context->trace_file, "%s", str.d); - xdebug_file_flush(context->trace_file); - - xdfree(str.d); -} - -/* Used for normal return values, and generator return values */ -static void xdebug_return_trace_stack_common(xdebug_str *str, function_stack_entry *fse) -{ - unsigned int j = 0; /* Counter */ - - xdebug_str_add_fmt(str, "%10.4F ", XDEBUG_SECONDS_SINCE_START(xdebug_get_nanotime())); - xdebug_str_add_fmt(str, "%10lu ", zend_memory_usage(0)); - - for (j = 0; j < fse->level; j++) { - xdebug_str_add_literal(str, " "); - } - xdebug_str_add_literal(str, " >=> "); -} - - -void xdebug_trace_textual_function_return_value(void *ctxt, function_stack_entry *fse, int function_nr, zval *return_value) -{ - xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; - xdebug_str str = XDEBUG_STR_INITIALIZER; - xdebug_str *tmp_value; - - xdebug_return_trace_stack_common(&str, fse); - - tmp_value = xdebug_get_zval_value_line(return_value, 0, NULL); - if (tmp_value) { - xdebug_str_add_str(&str, tmp_value); - xdebug_str_free(tmp_value); - } - xdebug_str_addc(&str, '\n'); - - xdebug_file_printf(context->trace_file, "%s", str.d); - xdebug_file_flush(context->trace_file); - - xdebug_str_destroy(&str); -} - -void xdebug_trace_textual_generator_return_value(void *ctxt, function_stack_entry *fse, int function_nr, zend_generator *generator) -{ - xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; - xdebug_str str = XDEBUG_STR_INITIALIZER; - xdebug_str *tmp_value = NULL; - - if (! (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING)) { - return; - } - - if (generator->execute_data == NULL) { - return; - } - - /* Generator key */ - tmp_value = xdebug_get_zval_value_line(&generator->key, 0, NULL); - if (!tmp_value) { - return; - } - - xdebug_return_trace_stack_common(&str, fse); - - xdebug_str_addc(&str, '('); - xdebug_str_add_str(&str, tmp_value); - xdebug_str_add_literal(&str, " => "); - - tmp_value = xdebug_get_zval_value_line(&generator->value, 0, NULL); - if (tmp_value) { - xdebug_str_add_str(&str, tmp_value); - xdebug_str_free(tmp_value); - } - - xdebug_str_add_literal(&str, ")\n"); - - xdebug_file_printf(context->trace_file, "%s", str.d); - xdebug_file_flush(context->trace_file); - - xdebug_str_destroy(&str); -} - -void xdebug_trace_textual_assignment(void *ctxt, function_stack_entry *fse, char *full_varname, zval *retval, char *right_full_varname, const char *op, char *filename, int lineno) -{ - xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; - unsigned int j = 0; - xdebug_str str = XDEBUG_STR_INITIALIZER; - xdebug_str *tmp_value; - - xdebug_str_add_literal(&str, " "); - for (j = 0; j <= fse->level; j++) { - xdebug_str_add_literal(&str, " "); - } - xdebug_str_add_literal(&str, " => "); - - xdebug_str_add(&str, full_varname, 0); - - if (op0 != '\0' ) { /* pre/post inc/dec ops are special */ - xdebug_str_addc(&str, ' '); - xdebug_str_add(&str, op, 0); - xdebug_str_addc(&str, ' '); - - if (right_full_varname) { - xdebug_str_add(&str, right_full_varname, 0); - } else { - tmp_value = xdebug_get_zval_value_line(retval, 0, NULL); - - if (tmp_value) { - xdebug_str_add_str(&str, tmp_value); - xdebug_str_free(tmp_value); - } else { - xdebug_str_add_literal(&str, "NULL"); - } - } - - } - xdebug_str_add_fmt(&str, " %s:%d\n", filename, lineno); - - xdebug_file_printf(context->trace_file, "%s", str.d); - xdebug_file_flush(context->trace_file); - - xdfree(str.d); -} - -xdebug_trace_handler_t xdebug_trace_handler_textual = -{ - xdebug_trace_textual_init, - xdebug_trace_textual_deinit, - xdebug_trace_textual_write_header, - xdebug_trace_textual_write_footer, - xdebug_trace_textual_get_filename, - xdebug_trace_textual_function_entry, - NULL /*xdebug_trace_textual_function_exit */, - xdebug_trace_textual_function_return_value, - xdebug_trace_textual_generator_return_value, - xdebug_trace_textual_assignment -};
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/tracing/tracing.c
Deleted
@@ -1,828 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ -#include "php.h" -#include "ext/standard/php_string.h" - -#include "php_xdebug.h" -#include "tracing_private.h" -#include "trace_textual.h" -#include "trace_computerized.h" -#include "trace_html.h" - -#include "lib/compat.h" -#include "lib/log.h" -#include "lib/str.h" -#include "lib/var_export_line.h" - -ZEND_EXTERN_MODULE_GLOBALS(xdebug) - -static xdebug_trace_handler_t *xdebug_select_trace_handler(int options) -{ - xdebug_trace_handler_t *tmp; - - switch (XINI_TRACE(trace_format)) { - case 0: tmp = &xdebug_trace_handler_textual; break; - case 1: tmp = &xdebug_trace_handler_computerized; break; - case 2: tmp = &xdebug_trace_handler_html; break; - default: - php_error(E_NOTICE, "A wrong value for xdebug.trace_format was selected (%d), defaulting to the textual format", (int) XINI_TRACE(trace_format)); - tmp = &xdebug_trace_handler_textual; break; - } - - if (options & XDEBUG_TRACE_OPTION_COMPUTERIZED) { - tmp = &xdebug_trace_handler_computerized; - } - if (options & XDEBUG_TRACE_OPTION_HTML) { - tmp = &xdebug_trace_handler_html; - } - - return tmp; -} - -xdebug_file *xdebug_trace_open_file(char *requested_filename, zend_string *script_filename, long options) -{ - xdebug_file *file = xdebug_file_ctor(); - char *filename_to_use; - char *generated_filename = NULL; - char *output_dir = xdebug_lib_get_output_dir(); /* not duplicated */ - - if (requested_filename && strlen(requested_filename)) { - filename_to_use = xdstrdup(requested_filename); - } else { - - if (!strlen(XINI_TRACE(trace_output_name)) || - xdebug_format_output_filename(&generated_filename, XINI_TRACE(trace_output_name), ZSTR_VAL(script_filename)) <= 0 - ) { - /* Invalid or empty xdebug.trace_output_name */ - xdebug_file_dtor(file); - return NULL; - } - - /* Add a slash if none is present in the output_dir setting */ - output_dir = xdebug_lib_get_output_dir(); /* not duplicated */ - - if (IS_SLASH(output_dirstrlen(output_dir) - 1)) { - filename_to_use = xdebug_sprintf("%s%s", output_dir, generated_filename); - } else { - filename_to_use = xdebug_sprintf("%s%c%s", output_dir, DEFAULT_SLASH, generated_filename); - } - } - - if (!xdebug_file_open( - file, - filename_to_use, - (options & XDEBUG_TRACE_OPTION_NAKED_FILENAME) ? NULL : "xt", - (options & XDEBUG_TRACE_OPTION_APPEND) ? "a" : "w" - )) { - xdebug_log_diagnose_permissions(XLOG_CHAN_TRACE, output_dir, generated_filename); - } - - if (generated_filename) { - xdfree(generated_filename); - } - xdfree(filename_to_use); - - return file; -} - -static char* xdebug_start_trace(char* fname, zend_string *script_filename, long options) -{ - if (XG_TRACE(trace_context)) { - return NULL; - } - - XG_TRACE(trace_handler) = xdebug_select_trace_handler(options); - XG_TRACE(trace_context) = (void*) XG_TRACE(trace_handler)->init(fname, script_filename, options); - - if (!XG_TRACE(trace_context)) { - return NULL; - } - - XG_TRACE(trace_handler)->write_header(XG_TRACE(trace_context)); - return xdstrdup(XG_TRACE(trace_handler)->get_filename(XG_TRACE(trace_context))); -} - -static void xdebug_stop_trace(void) -{ - if (!XG_TRACE(trace_context)) { - return; - } - - XG_TRACE(trace_handler)->write_footer(XG_TRACE(trace_context)); - XG_TRACE(trace_handler)->deinit(XG_TRACE(trace_context)); - XG_TRACE(trace_context) = NULL; -} - -char *xdebug_get_trace_filename(void) -{ - if (!(XG_TRACE(trace_context) && XG_TRACE(trace_handler) && XG_TRACE(trace_handler)->get_filename)) { - return NULL; - } - - return XG_TRACE(trace_handler)->get_filename(XG_TRACE(trace_context)); -} - -PHP_FUNCTION(xdebug_start_trace) -{ - char *fname = NULL; - size_t fname_len = 0; - char *trace_fname; - zend_long options = XINI_TRACE(trace_options); - function_stack_entry *fse; - - WARN_AND_RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_TRACING); - - if (XG_TRACE(trace_context)) { - php_error(E_NOTICE, "Function trace already started"); - RETURN_FALSE; - } - - if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sl", &fname, &fname_len, &options) == FAILURE) { - return; - } - - fse = xdebug_get_stack_frame(0); - - if ((trace_fname = xdebug_start_trace(fname, fse->filename, options)) != NULL) { - RETVAL_STRING(trace_fname); - xdfree(trace_fname); - return; - } else { - php_error(E_NOTICE, "Trace could not be started"); - } - - RETURN_FALSE; -} - -PHP_FUNCTION(xdebug_stop_trace) -{ - WARN_AND_RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_TRACING); - - if (!XG_TRACE(trace_context)) { - php_error(E_NOTICE, "Function trace was not started"); - RETURN_FALSE; - } - - RETVAL_STRING(XG_TRACE(trace_handler)->get_filename(XG_TRACE(trace_context))); - xdebug_stop_trace(); -} - -PHP_FUNCTION(xdebug_get_tracefile_name) -{ - char *filename; - - WARN_AND_RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_TRACING); - - filename = xdebug_get_trace_filename(); - if (!filename) { - RETURN_FALSE; - } - - RETVAL_STRING(filename); -} - -#if PHP_VERSION_ID >= 70400 -static const char *get_assign_operation(uint32_t extended_value) -{ - switch (extended_value) { - case ZEND_ADD: return "+="; - case ZEND_SUB: return "-="; - case ZEND_MUL: return "*="; - case ZEND_DIV: return "/="; - case ZEND_MOD: return "%="; - case ZEND_SL: return "<<="; - case ZEND_SR: return ">>="; - case ZEND_CONCAT: return ".="; - case ZEND_BW_OR: return "|="; - case ZEND_BW_AND: return "&="; - case ZEND_BW_XOR: return "^="; - case ZEND_POW: return "**="; - default: - return ""; - } -} -#endif - -static int xdebug_is_static_call(const zend_op *first_opcode, const zend_op *cur_opcode, const zend_op *prev_opcode, const zend_op **found_opcode) -{ - const zend_op *opcode_ptr; - - opcode_ptr = cur_opcode; - -# if PHP_VERSION_ID >= 70400 - if ( - (opcode_ptr->opcode == ZEND_ASSIGN_STATIC_PROP) || (opcode_ptr->opcode == ZEND_ASSIGN_STATIC_PROP_REF) || - (opcode_ptr->opcode == ZEND_PRE_INC_STATIC_PROP) || (opcode_ptr->opcode == ZEND_PRE_DEC_STATIC_PROP) || - (opcode_ptr->opcode == ZEND_POST_INC_STATIC_PROP) || (opcode_ptr->opcode == ZEND_POST_DEC_STATIC_PROP) - ) { - *found_opcode = opcode_ptr; - return 1; - } -# endif - while (!(opcode_ptr->opcode == ZEND_EXT_STMT) && !((opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_W) || (opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_RW))) { - opcode_ptr = opcode_ptr - 1; - if (opcode_ptr < first_opcode) { - return 0; - } - } - if ((opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_W) || (opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_RW)) { - *found_opcode = opcode_ptr; - return 1; - } - return 0; -} - -static const zend_op *xdebug_find_referenced_opline(zend_execute_data *execute_data, const zend_op *cur_opcode, int op1_or_op2) -{ - size_t variable_number; - const zend_op *scan_opcode; - int found; - int op_type = (op1_or_op2 == 1) ? cur_opcode->op1_type : cur_opcode->op2_type; - - if (op_type != IS_VAR) { - return NULL; - } - - variable_number = (op1_or_op2 == 1) ? cur_opcode->op1.var : cur_opcode->op2.var; - scan_opcode = cur_opcode; - found = 0; - - /* Scroll up until we find a RES of IS_VAR with the right value */ - do { - scan_opcode--; - if (scan_opcode->result_type == IS_VAR && scan_opcode->result.var == variable_number) { - found = 1; - } - } while (!found); - - return scan_opcode; -} - -static int is_fetch_op(const zend_op *op) -{ - return ( - op->opcode == ZEND_FETCH_DIM_W || op->opcode == ZEND_FETCH_DIM_RW || - op->opcode == ZEND_FETCH_OBJ_W || op->opcode == ZEND_FETCH_OBJ_RW || - op->opcode == ZEND_FETCH_W || op->opcode == ZEND_FETCH_RW - ); -} - -static char *xdebug_find_var_name(zend_execute_data *execute_data, const zend_op *cur_opcode, const zend_op *lower_bound) -{ - const zend_op *next_opcode, *prev_opcode = NULL, *opcode_ptr; - zval *dimval; - int is_var; - zend_op_array *op_array = &execute_data->func->op_array; - xdebug_str name = XDEBUG_STR_INITIALIZER; - int gohungfound = 0, is_static = 0; - xdebug_str *zval_value = NULL; - xdebug_var_export_options *options; - const zend_op *static_opcode_ptr = NULL; - - next_opcode = cur_opcode + 1; - prev_opcode = cur_opcode - 1; - - if (cur_opcode->opcode == ZEND_QM_ASSIGN) { - xdebug_str_addc(&name, '$'); - xdebug_str_add(&name, zend_get_compiled_variable_name(op_array, cur_opcode->result.var)->val, 0); - - return name.d; - } - - is_static = xdebug_is_static_call(op_array->opcodes, cur_opcode, prev_opcode, &static_opcode_ptr); - options = xdebug_var_export_options_from_ini(); - options->no_decoration = 1; - - if (cur_opcode->op1_type == IS_CV) { - if (!lower_bound) { - xdebug_str_addc(&name, '$'); - xdebug_str_add(&name, zend_get_compiled_variable_name(op_array, cur_opcode->op1.var)->val, 0); - } - } else if (cur_opcode->op1_type == IS_VAR && cur_opcode->opcode == ZEND_ASSIGN && (prev_opcode->opcode == ZEND_FETCH_W || prev_opcode->opcode == ZEND_FETCH_RW)) { - if (is_static) { - xdebug_str_add_literal(&name, "self::"); - } else { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, prev_opcode, prev_opcode->op1_type, &prev_opcode->op1, &is_var), 0, options); - xdebug_str_addc(&name, '$'); - xdebug_str_add_str(&name, zval_value); - xdebug_str_free(zval_value); - } - } else if (is_static) { /* todo : see if you can change this and the previous cases around */ - xdebug_str_add_literal(&name, "self::"); - } - if (cur_opcode->opcode >= ZEND_PRE_INC_OBJ && cur_opcode->opcode <= ZEND_POST_DEC_OBJ) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var), 0, options); - xdebug_str_add_literal(&name, "$this->"); - xdebug_str_add_str(&name, zval_value); - xdebug_str_free(zval_value); - } -#if PHP_VERSION_ID >= 70400 - if (cur_opcode->opcode >= ZEND_PRE_INC_STATIC_PROP && cur_opcode->opcode <= ZEND_POST_DEC_STATIC_PROP) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var), 0, options); - xdebug_str_add_str(&name, zval_value); - xdebug_str_free(zval_value); - } -#endif - - /* Scroll back to start of FETCHES */ - /* FIXME: See whether we can do this unroll looping only once - in is_static() */ - gohungfound = 0; - if (!is_static) { - if (cur_opcode == lower_bound) { - gohungfound = 1; - } - opcode_ptr = prev_opcode; - while ((opcode_ptr >= lower_bound) && is_fetch_op(opcode_ptr)) { - opcode_ptr = opcode_ptr - 1; - gohungfound = 1; - } - opcode_ptr = opcode_ptr + 1; - } else { /* if we have a static method, we should already have found the first fetch */ - opcode_ptr = static_opcode_ptr; - gohungfound = 1; - } - - if (gohungfound) { - int cv_found = 0; - - do - { - if ( - opcode_ptr->op1_type == IS_UNUSED && - (opcode_ptr->opcode == ZEND_FETCH_OBJ_W || opcode_ptr->opcode == ZEND_FETCH_OBJ_RW) - ) { - xdebug_str_add_literal(&name, "$this"); - } - if (opcode_ptr->op1_type == IS_CV) { - xdebug_str_addc(&name, '$'); - xdebug_str_add(&name, zend_get_compiled_variable_name(op_array, opcode_ptr->op1.var)->val, 0); - } - if (opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_W || opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_R || opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_RW) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op1_type, &opcode_ptr->op1, &is_var), 0, options); - xdebug_str_add_str(&name, zval_value); - xdebug_str_free(zval_value); - } - if (opcode_ptr->opcode == ZEND_FETCH_W) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op1_type, &opcode_ptr->op1, &is_var), 0, options); - xdebug_str_add_str(&name, zval_value); - xdebug_str_free(zval_value); - } - if (is_static && opcode_ptr->opcode == ZEND_FETCH_RW) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op1_type, &opcode_ptr->op1, &is_var), 0, options); - xdebug_str_add_str(&name, zval_value); - xdebug_str_free(zval_value); - } - if (opcode_ptr->opcode == ZEND_FETCH_DIM_W || opcode_ptr->opcode == ZEND_FETCH_DIM_RW) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op2_type, &opcode_ptr->op2, &is_var), 0, NULL); - xdebug_str_addc(&name, ''); - if (zval_value) { - xdebug_str_add_str(&name, zval_value); - } - xdebug_str_addc(&name, ''); - xdebug_str_free(zval_value); - } else if (opcode_ptr->opcode == ZEND_FETCH_OBJ_W || opcode_ptr->opcode == ZEND_FETCH_OBJ_RW) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op2_type, &opcode_ptr->op2, &is_var), 0, options); - xdebug_str_add_literal(&name, "->"); - xdebug_str_add_str(&name, zval_value); - xdebug_str_free(zval_value); - } - opcode_ptr = opcode_ptr + 1; - if (opcode_ptr->op1_type == IS_CV) { - cv_found = 1; - } - } while (!cv_found && is_fetch_op(opcode_ptr)); - } - - if ( - (cur_opcode->opcode == ZEND_ASSIGN_OBJ) -#if PHP_VERSION_ID >= 70400 - || (cur_opcode->opcode == ZEND_ASSIGN_OBJ_REF) -#endif - ) { - if (cur_opcode->op1_type == IS_UNUSED) { - xdebug_str_add_literal(&name, "$this"); - } - dimval = xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var); - xdebug_str_add_literal(&name, "->"); - xdebug_str_add(&name, Z_STRVAL_P(dimval), 0); - } -#if PHP_VERSION_ID >= 70400 - if (cur_opcode->opcode == ZEND_ASSIGN_STATIC_PROP_REF) { - dimval = xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var); - xdebug_str_add(&name, Z_STRVAL_P(dimval), 0); - } - if (cur_opcode->opcode == ZEND_ASSIGN_DIM_OP) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var), 0, NULL); - xdebug_str_addc(&name, ''); - xdebug_str_add_str(&name, zval_value); - xdebug_str_addc(&name, ''); - xdebug_str_free(zval_value); - } - if (cur_opcode->opcode == ZEND_ASSIGN_OBJ_OP) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var), 0, options); - if (cur_opcode->op1_type == IS_UNUSED) { - xdebug_str_add_literal(&name, "$this->"); - } else { - xdebug_str_add_literal(&name, "->"); - } - xdebug_str_add_str(&name, zval_value); - xdebug_str_free(zval_value); - } - if (cur_opcode->opcode == ZEND_ASSIGN_STATIC_PROP_OP) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var), 0, options); - xdebug_str_add_literal(&name, "self::"); - xdebug_str_add_str(&name, zval_value); - xdebug_str_free(zval_value); - } -#else - if ((cur_opcode->opcode >= ZEND_ASSIGN_ADD && cur_opcode->opcode <= ZEND_ASSIGN_BW_XOR) - || cur_opcode->opcode == ZEND_ASSIGN_POW - ) { - if (cur_opcode->extended_value == ZEND_ASSIGN_DIM) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var), 0, NULL); - xdebug_str_addc(&name, ''); - xdebug_str_add_str(&name, zval_value); - xdebug_str_addc(&name, ''); - xdebug_str_free(zval_value); - } - if (cur_opcode->extended_value == ZEND_ASSIGN_OBJ) { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var), 0, options); - if (cur_opcode->op1_type == IS_UNUSED) { - xdebug_str_add_literal(&name, "$this->"); - } else { - xdebug_str_add_literal(&name, "->"); - } - xdebug_str_add_str(&name, zval_value); - xdebug_str_free(zval_value); - } - } -#endif - - if (cur_opcode->opcode == ZEND_ASSIGN_DIM) { - if (next_opcode->opcode == ZEND_OP_DATA && cur_opcode->op2_type == IS_UNUSED) { - xdebug_str_add_literal(&name, ""); - } else { - zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op2_type, &opcode_ptr->op2, &is_var), 0, NULL); - xdebug_str_addc(&name, ''); - xdebug_str_add_str(&name, zval_value); - xdebug_str_addc(&name, ''); - xdebug_str_free(zval_value); - } - } - -#if PHP_VERSION_ID >= 70400 - if (cur_opcode->opcode == ZEND_ASSIGN_STATIC_PROP) { - dimval = xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var); - xdebug_str_add(&name, Z_STRVAL_P(dimval), 0); - } -#endif - - xdfree(options->runtime); - xdfree(options); - - return name.d; -} - -static int xdebug_common_assign_dim_handler(const char *op, XDEBUG_OPCODE_HANDLER_ARGS) -{ - char *file; - zend_op_array *op_array = &execute_data->func->op_array; - int lineno; - const zend_op *cur_opcode, *next_opcode; - zval *val = NULL; - char *right_full_varname = NULL; - int is_var; - function_stack_entry *fse; - - cur_opcode = execute_data->opline; - next_opcode = cur_opcode + 1; - file = (char*) STR_NAME_VAL(op_array->filename); - lineno = cur_opcode->lineno; - - /* TODO TEST FOR ASSIGNMENTS IN FILTERING */ -// if (xdebug_is_top_stack_frame_filtered(XDEBUG_FILTER_CODE_COVERAGE)) { -// return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); -// } - - if (XG_TRACE(trace_context) && XINI_TRACE(collect_assignments)) { - char *full_varname; - - if (cur_opcode->opcode == ZEND_QM_ASSIGN && cur_opcode->result_type != IS_CV) { - return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); - } - full_varname = xdebug_find_var_name(execute_data, execute_data->opline, NULL); - - if (cur_opcode->opcode >= ZEND_PRE_INC && cur_opcode->opcode <= ZEND_POST_DEC) { - char *tmp_varname; - - switch (cur_opcode->opcode) { - case ZEND_PRE_INC: tmp_varname = xdebug_sprintf("++%s", full_varname); break; - case ZEND_POST_INC: tmp_varname = xdebug_sprintf("%s++", full_varname); break; - case ZEND_PRE_DEC: tmp_varname = xdebug_sprintf("--%s", full_varname); break; - case ZEND_POST_DEC: tmp_varname = xdebug_sprintf("%s--", full_varname); break; - } - xdfree(full_varname); - full_varname = tmp_varname; - - val = xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var); - } else if (cur_opcode->opcode >= ZEND_PRE_INC_OBJ && cur_opcode->opcode <= ZEND_POST_DEC_OBJ) { - char *tmp_varname; - - switch (cur_opcode->opcode) { - case ZEND_PRE_INC_OBJ: tmp_varname = xdebug_sprintf("++%s", full_varname); break; - case ZEND_POST_INC_OBJ: tmp_varname = xdebug_sprintf("%s++", full_varname); break; - case ZEND_PRE_DEC_OBJ: tmp_varname = xdebug_sprintf("--%s", full_varname); break; - case ZEND_POST_DEC_OBJ: tmp_varname = xdebug_sprintf("%s--", full_varname); break; - } - xdfree(full_varname); - full_varname = tmp_varname; - - val = xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var); -#if PHP_VERSION_ID >= 70400 - } else if (cur_opcode->opcode >= ZEND_PRE_INC_STATIC_PROP && cur_opcode->opcode <= ZEND_POST_DEC_STATIC_PROP) { - char *tmp_varname; - - switch (cur_opcode->opcode) { - case ZEND_PRE_INC_STATIC_PROP: tmp_varname = xdebug_sprintf("++%s", full_varname); break; - case ZEND_POST_INC_STATIC_PROP: tmp_varname = xdebug_sprintf("%s++", full_varname); break; - case ZEND_PRE_DEC_STATIC_PROP: tmp_varname = xdebug_sprintf("--%s", full_varname); break; - case ZEND_POST_DEC_STATIC_PROP: tmp_varname = xdebug_sprintf("%s--", full_varname); break; - } - xdfree(full_varname); - full_varname = tmp_varname; - - val = xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var); -#endif - } else if ( - (next_opcode->opcode == ZEND_OP_DATA) -#if PHP_VERSION_ID >= 70400 - && (cur_opcode->opcode != ZEND_ASSIGN_OBJ_REF) - && (cur_opcode->opcode != ZEND_ASSIGN_STATIC_PROP_REF) -#endif - ) { - val = xdebug_get_zval_with_opline(execute_data, next_opcode, next_opcode->op1_type, &next_opcode->op1, &is_var); - } else if (cur_opcode->opcode == ZEND_QM_ASSIGN) { - val = xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var); - } else if (cur_opcode->opcode == ZEND_ASSIGN_REF) { - if (cur_opcode->op2_type == IS_CV) { - right_full_varname = xdebug_sprintf("$%s", zend_get_compiled_variable_name(op_array, cur_opcode->op2.var)->val); - } else { - const zend_op *referenced_opline = xdebug_find_referenced_opline(execute_data, cur_opcode, 2); - right_full_varname = xdebug_find_var_name(execute_data, referenced_opline, NULL); - } -#if PHP_VERSION_ID >= 70400 - } else if (cur_opcode->opcode == ZEND_ASSIGN_OBJ_REF) { - if (next_opcode->op1_type == IS_CV) { - right_full_varname = xdebug_sprintf("$%s", zend_get_compiled_variable_name(op_array, next_opcode->op1.var)->val); - } else { - const zend_op *referenced_opline = xdebug_find_referenced_opline(execute_data, next_opcode, 1); - right_full_varname = xdebug_find_var_name(execute_data, referenced_opline, NULL); - } - } else if (cur_opcode->opcode == ZEND_ASSIGN_STATIC_PROP_REF) { - if (next_opcode->op1_type == IS_CV) { - right_full_varname = xdebug_sprintf("$%s", zend_get_compiled_variable_name(op_array, next_opcode->op1.var)->val); - } else { - const zend_op *referenced_opline = xdebug_find_referenced_opline(execute_data, next_opcode, 1); - right_full_varname = xdebug_find_var_name(execute_data, referenced_opline, NULL); - } -#endif - } else { - val = xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var); - } - - fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); - if (XG_TRACE(trace_context) && XINI_TRACE(collect_assignments) && XG_TRACE(trace_handler)->assignment) { - XG_TRACE(trace_handler)->assignment(XG_TRACE(trace_context), fse, full_varname, val, right_full_varname, op, file, lineno); - } - xdfree(full_varname); - xdfree(right_full_varname); - } - - return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); -} - -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign, "="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(qm_assign, "="); -#if PHP_VERSION_ID >= 70400 -XDEBUG_OPCODE_OVERRIDE_ASSIGN_OP(assign_op); -XDEBUG_OPCODE_OVERRIDE_ASSIGN_OP(assign_dim_op); -XDEBUG_OPCODE_OVERRIDE_ASSIGN_OP(assign_obj_op); -XDEBUG_OPCODE_OVERRIDE_ASSIGN_OP(assign_static_prop_op); -#else -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_add, "+="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_sub, "-="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_mul, "*="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_div, "/="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_mod, "%="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_sl, "<<="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_sr, ">>="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_bw_or, "|="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_bw_and, "&="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_bw_xor, "^="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_pow, "**="); -#endif -XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_inc, ""); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_inc, ""); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_dec, ""); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_dec, ""); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_inc_obj, ""); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_inc_obj, ""); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_dec_obj, ""); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_dec_obj, ""); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_concat, ".="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_dim, "="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_obj, "="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_ref, "=&"); -#if PHP_VERSION_ID >= 70400 -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_obj_ref, "=&"); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_static_prop, "="); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_static_prop_ref, "=&"); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_inc_static_prop, ""); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_dec_static_prop, ""); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_inc_static_prop, ""); -XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_dec_static_prop, ""); -#endif - -void xdebug_init_tracing_globals(xdebug_tracing_globals_t *xg) -{ - xg->trace_handler = NULL; - xg->trace_context = NULL; -} - -void xdebug_tracing_minit(INIT_FUNC_ARGS) -{ - /* Override opcodes for variable assignments in traces */ - xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN, xdebug_assign_handler); - xdebug_register_with_opcode_multi_handler(ZEND_QM_ASSIGN, xdebug_qm_assign_handler); - -#if PHP_VERSION_ID >= 70400 - xdebug_set_opcode_handler(ZEND_ASSIGN_OP, xdebug_assign_op_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_DIM_OP, xdebug_assign_dim_op_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_OBJ_OP, xdebug_assign_obj_op_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_STATIC_PROP_OP, xdebug_assign_static_prop_op_handler); -#else - xdebug_set_opcode_handler(ZEND_ASSIGN_ADD, xdebug_assign_add_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_SUB, xdebug_assign_sub_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_MUL, xdebug_assign_mul_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_DIV, xdebug_assign_div_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_MOD, xdebug_assign_mod_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_POW, xdebug_assign_pow_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_SL, xdebug_assign_sl_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_SR, xdebug_assign_sr_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_CONCAT, xdebug_assign_concat_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_BW_OR, xdebug_assign_bw_or_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_BW_AND, xdebug_assign_bw_and_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_BW_XOR, xdebug_assign_bw_xor_handler); -#endif - xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_DIM, xdebug_assign_dim_handler); - xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_OBJ, xdebug_assign_obj_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_REF, xdebug_assign_ref_handler); - xdebug_set_opcode_handler(ZEND_PRE_INC, xdebug_pre_inc_handler); - xdebug_set_opcode_handler(ZEND_POST_INC, xdebug_post_inc_handler); - xdebug_set_opcode_handler(ZEND_PRE_DEC, xdebug_pre_dec_handler); - xdebug_set_opcode_handler(ZEND_POST_DEC, xdebug_post_dec_handler); - xdebug_set_opcode_handler(ZEND_PRE_INC_OBJ, xdebug_pre_inc_obj_handler); - xdebug_set_opcode_handler(ZEND_POST_INC_OBJ, xdebug_post_inc_obj_handler); - xdebug_set_opcode_handler(ZEND_PRE_DEC_OBJ, xdebug_pre_dec_obj_handler); - xdebug_set_opcode_handler(ZEND_POST_DEC_OBJ, xdebug_post_dec_obj_handler); -#if PHP_VERSION_ID >= 70400 - xdebug_set_opcode_handler(ZEND_ASSIGN_OBJ_REF, xdebug_assign_obj_ref_handler); - xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_STATIC_PROP, xdebug_assign_static_prop_handler); - xdebug_set_opcode_handler(ZEND_ASSIGN_STATIC_PROP_REF, xdebug_assign_static_prop_ref_handler); - xdebug_set_opcode_handler(ZEND_PRE_INC_STATIC_PROP, xdebug_pre_inc_static_prop_handler); - xdebug_set_opcode_handler(ZEND_PRE_DEC_STATIC_PROP, xdebug_pre_dec_static_prop_handler); - xdebug_set_opcode_handler(ZEND_POST_INC_STATIC_PROP, xdebug_post_inc_static_prop_handler); - xdebug_set_opcode_handler(ZEND_POST_DEC_STATIC_PROP, xdebug_post_dec_static_prop_handler); -#endif -} - -void xdebug_tracing_register_constants(INIT_FUNC_ARGS) -{ - REGISTER_LONG_CONSTANT("XDEBUG_TRACE_APPEND", XDEBUG_TRACE_OPTION_APPEND, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("XDEBUG_TRACE_COMPUTERIZED", XDEBUG_TRACE_OPTION_COMPUTERIZED, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("XDEBUG_TRACE_HTML", XDEBUG_TRACE_OPTION_HTML, CONST_CS | CONST_PERSISTENT); - REGISTER_LONG_CONSTANT("XDEBUG_TRACE_NAKED_FILENAME", XDEBUG_TRACE_OPTION_NAKED_FILENAME, CONST_CS | CONST_PERSISTENT); -} - -void xdebug_tracing_rinit(void) -{ - XG_TRACE(trace_handler) = NULL; - XG_TRACE(trace_context) = NULL; -} - -void xdebug_tracing_post_deactivate(void) -{ - if (XG_TRACE(trace_context)) { - xdebug_stop_trace(); - } - - XG_TRACE(trace_context) = NULL; -} - -void xdebug_tracing_init_if_requested(zend_op_array *op_array) -{ - if (xdebug_lib_start_with_request(XDEBUG_MODE_TRACING) || xdebug_lib_start_with_trigger(XDEBUG_MODE_TRACING, NULL)) { - /* In case we do an auto-trace we are not interested in the return - * value, but we still have to free it. */ - xdfree(xdebug_start_trace(NULL, op_array->filename, XINI_TRACE(trace_options))); - } -} - -void xdebug_tracing_execute_ex(int function_nr, function_stack_entry *fse) -{ - if (fse->filtered_tracing || !XG_TRACE(trace_context)) { - return; - } - - if (XG_TRACE(trace_handler)->function_entry) { - XG_TRACE(trace_handler)->function_entry(XG_TRACE(trace_context), fse, function_nr); - } -} - -void xdebug_tracing_execute_ex_end(int function_nr, function_stack_entry *fse, zend_execute_data *execute_data) -{ - zend_op_array *op_array; - - if (fse->filtered_tracing || !XG_TRACE(trace_context)) { - return; - } - - if ((XG_TRACE(trace_handler)->function_exit)) { - XG_TRACE(trace_handler)->function_exit(XG_TRACE(trace_context), fse, function_nr); - } - - /* Store return value in the trace file */ - if (!XINI_TRACE(collect_return)) { - return; - } - - op_array = &(execute_data->func->op_array); - - if (!execute_data || !execute_data->return_value) { - return; - } - - if (op_array->fn_flags & ZEND_ACC_GENERATOR) { - if (XG_TRACE(trace_handler)->generator_return_value) { - XG_TRACE(trace_handler)->generator_return_value(XG_TRACE(trace_context), fse, function_nr, (zend_generator*) execute_data->return_value); - } - } else { - if (XG_TRACE(trace_handler)->return_value) { - XG_TRACE(trace_handler)->return_value(XG_TRACE(trace_context), fse, function_nr, execute_data->return_value); - } - } -} - -int xdebug_tracing_execute_internal(int function_nr, function_stack_entry *fse) -{ - if (fse->filtered_tracing || !XG_TRACE(trace_context)) { - return 0; - } - - if (fse->function.type != XFUNC_ZEND_PASS && (XG_TRACE(trace_handler)->function_entry)) { - XG_TRACE(trace_handler)->function_entry(XG_TRACE(trace_context), fse, function_nr); - return 1; - } - - return 0; -} - -void xdebug_tracing_execute_internal_end(int function_nr, function_stack_entry *fse, zval *return_value) -{ - if (fse->filtered_tracing || !XG_TRACE(trace_context)) { - return; - } - - if (fse->function.type != XFUNC_ZEND_PASS && (XG_TRACE(trace_handler)->function_exit)) { - XG_TRACE(trace_handler)->function_exit(XG_TRACE(trace_context), fse, function_nr); - } - - /* Store return value in the trace file */ - if (XINI_TRACE(collect_return) && fse->function.type != XFUNC_ZEND_PASS && return_value && XG_TRACE(trace_handler)->return_value) { - XG_TRACE(trace_handler)->return_value(XG_TRACE(trace_context), fse, function_nr, return_value); - } -} - -void xdebug_tracing_save_trace_context(void **original_trace_context) -{ - *original_trace_context = XG_TRACE(trace_context); - XG_TRACE(trace_context) = NULL; -} - -void xdebug_tracing_restore_trace_context(void *original_trace_context) -{ - XG_TRACE(trace_context) = original_trace_context; -}
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/tracing/tracing.h
Deleted
@@ -1,77 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ -#ifndef XDEBUG_TRACING_H -#define XDEBUG_TRACING_H - -#include "php.h" - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeclaration-after-statement" -#include "zend_generators.h" -#pragma GCC diagnostic pop - -typedef struct -{ - void *(*init)(char *fname, zend_string *script_filename, long options); - void (*deinit)(void *ctxt); - void (*write_header)(void *ctxt); - void (*write_footer)(void *ctxt); - char *(*get_filename)(void *ctxt); - void (*function_entry)(void *ctxt, function_stack_entry *fse, int function_nr); - void (*function_exit)(void *ctxt, function_stack_entry *fse, int function_nr); - void (*return_value)(void *ctxt, function_stack_entry *fse, int function_nr, zval *return_value); - void (*generator_return_value)(void *ctxt, function_stack_entry *fse, int function_nr, zend_generator *generator); - void (*assignment)(void *ctxt, function_stack_entry *fse, char *full_varname, zval *value, char *right_full_varname, const char *op, char *file, int lineno); -} xdebug_trace_handler_t; - -typedef struct _xdebug_tracing_globals_t { - xdebug_trace_handler_t *trace_handler; - void *trace_context; -} xdebug_tracing_globals_t; - -typedef struct _xdebug_tracing_settings_t { - char *trace_output_name; - zend_long trace_options; - zend_long trace_format; - - zend_bool collect_assignments; - zend_bool collect_return; -} xdebug_tracing_settings_t; - -void xdebug_init_tracing_globals(xdebug_tracing_globals_t *xg); -void xdebug_tracing_minit(INIT_FUNC_ARGS); -void xdebug_tracing_rinit(void); -void xdebug_tracing_post_deactivate(void); -void xdebug_tracing_register_constants(INIT_FUNC_ARGS); - -void xdebug_tracing_init_if_requested(zend_op_array *op_array); -void xdebug_tracing_execute_ex(int function_nr, function_stack_entry *fse); -void xdebug_tracing_execute_ex_end(int function_nr, function_stack_entry *fse, zend_execute_data *execute_data); -int xdebug_tracing_execute_internal(int function_nr, function_stack_entry *fse); -void xdebug_tracing_execute_internal_end(int function_nr, function_stack_entry *fse, zval *return_value); - -void xdebug_tracing_save_trace_context(void **old_trace_context); -void xdebug_tracing_restore_trace_context(void *old_trace_context); - -char* xdebug_return_trace_stack_retval(function_stack_entry* i, int fnr, zval* retval); -char* xdebug_return_trace_stack_generator_retval(function_stack_entry* i, zend_generator* generator); -char* xdebug_return_trace_assignment(function_stack_entry *i, char *varname, zval *retval, char *op, char *file, int fileno); - -void xdebug_trace_function_begin(function_stack_entry *fse, int function_nr); -void xdebug_trace_function_end(function_stack_entry *fse, int function_nr); - -char *xdebug_get_trace_filename(void); -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/src/tracing/tracing_private.h
Deleted
@@ -1,83 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2020 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ -#ifndef __XDEBUG_TRACING_PRIVATE_H__ -#define __XDEBUG_TRACING_PRIVATE_H__ - -#include "tracing.h" - -#define XG_TRACE(v) (XG(globals.tracing.v)) -#define XINI_TRACE(v) (XG(settings.tracing.v)) - -#define XDEBUG_OPCODE_OVERRIDE_ASSIGN(f,o) \ - int xdebug_##f##_handler(zend_execute_data *execute_data) \ - { \ - return xdebug_common_assign_dim_handler((o), execute_data); \ - } - -#if PHP_VERSION_ID >= 70400 -#define XDEBUG_OPCODE_OVERRIDE_ASSIGN_OP(f) \ - int xdebug_##f##_handler(zend_execute_data *execute_data) \ - { \ - const char *op = get_assign_operation(execute_data->opline->extended_value); \ - return xdebug_common_assign_dim_handler(op, execute_data); \ - } -#endif - -int xdebug_assign_handler(zend_execute_data *execute_data); -int xdebug_qm_assign_handler(zend_execute_data *execute_data); -#if PHP_VERSION_ID >= 70400 -int xdebug_assign_op_handler(zend_execute_data *execute_data); -int xdebug_assign_dim_op_handler(zend_execute_data *execute_data); -int xdebug_assign_obj_op_handler(zend_execute_data *execute_data); -int xdebug_assign_static_prop_op_handler(zend_execute_data *execute_data); -#else -int xdebug_assign_add_handler(zend_execute_data *execute_data); -int xdebug_assign_sub_handler(zend_execute_data *execute_data); -int xdebug_assign_mul_handler(zend_execute_data *execute_data); -int xdebug_assign_div_handler(zend_execute_data *execute_data); -int xdebug_assign_mod_handler(zend_execute_data *execute_data); -int xdebug_assign_sl_handler(zend_execute_data *execute_data); -int xdebug_assign_sr_handler(zend_execute_data *execute_data); -int xdebug_assign_bw_or_handler(zend_execute_data *execute_data); -int xdebug_assign_bw_and_handler(zend_execute_data *execute_data); -int xdebug_assign_bw_xor_handler(zend_execute_data *execute_data); -int xdebug_assign_pow_handler(zend_execute_data *execute_data); -#endif -int xdebug_pre_inc_handler(zend_execute_data *execute_data); -int xdebug_post_inc_handler(zend_execute_data *execute_data); -int xdebug_pre_dec_handler(zend_execute_data *execute_data); -int xdebug_post_dec_handler(zend_execute_data *execute_data); -int xdebug_pre_inc_obj_handler(zend_execute_data *execute_data); -int xdebug_post_inc_obj_handler(zend_execute_data *execute_data); -int xdebug_pre_dec_obj_handler(zend_execute_data *execute_data); -int xdebug_post_dec_obj_handler(zend_execute_data *execute_data); -int xdebug_assign_concat_handler(zend_execute_data *execute_data); -int xdebug_assign_dim_handler(zend_execute_data *execute_data); -int xdebug_assign_obj_handler(zend_execute_data *execute_data); -int xdebug_assign_ref_handler(zend_execute_data *execute_data); -#if PHP_VERSION_ID >= 70400 -int xdebug_assign_obj_ref_handler(zend_execute_data *execute_data); -int xdebug_assign_static_prop_handler(zend_execute_data *execute_data); -int xdebug_assign_static_prop_ref_handler(zend_execute_data *execute_data); -int xdebug_pre_inc_static_prop_handler(zend_execute_data *execute_data); -int xdebug_pre_dec_static_prop_handler(zend_execute_data *execute_data); -int xdebug_post_inc_static_prop_handler(zend_execute_data *execute_data); -int xdebug_post_dec_static_prop_handler(zend_execute_data *execute_data); -#endif - -xdebug_file *xdebug_trace_open_file(char *fname, zend_string *script_filename, long options); - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/xdebug.c
Deleted
@@ -1,826 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Xdebug | - +----------------------------------------------------------------------+ - | Copyright (c) 2002-2021 Derick Rethans | - +----------------------------------------------------------------------+ - | This source file is subject to version 1.01 of the Xdebug license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | https://xdebug.org/license.php | - | If you did not receive a copy of the Xdebug license and are unable | - | to obtain it through the world-wide-web, please send a note to | - | derick@xdebug.org so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "php.h" -#include "main/php_version.h" -#include "lib/compat.h" - -#if HAVE_XDEBUG - -#ifndef PHP_WIN32 -#include <sys/time.h> -#include <unistd.h> -#else -#include "win32/time.h" -#include <process.h> -#endif - -#include "TSRM.h" -#include "SAPI.h" -#include "zend_extensions.h" -#include "main/php_ini.h" -#include "ext/standard/head.h" -#include "ext/standard/html.h" -#include "ext/standard/info.h" -#include "ext/standard/php_string.h" -#include "php_globals.h" -#include "main/php_output.h" -#include "ext/standard/php_var.h" - -#include "php_xdebug.h" -#include "php_xdebug_arginfo.h" - -#include "base/base.h" -#include "base/filter.h" -#include "coverage/code_coverage.h" -#include "develop/monitor.h" -#include "develop/stack.h" -#include "develop/superglobals.h" -#include "gcstats/gc_stats.h" -#include "lib/usefulstuff.h" -#include "lib/lib.h" -#include "lib/llist.h" -#include "lib/log.h" -#include "lib/mm.h" -#include "lib/var_export_html.h" -#include "lib/var_export_line.h" -#include "lib/var_export_text.h" -#include "profiler/profiler.h" -#include "tracing/tracing.h" - -#if PHP_VERSION_ID >= 80000 -static zend_result (*xdebug_orig_post_startup_cb)(void); -static zend_result xdebug_post_startup(void); -#elif PHP_VERSION_ID >= 70300 -static int (*xdebug_orig_post_startup_cb)(void); -static int xdebug_post_startup(void); -#endif - -int xdebug_include_or_eval_handler(zend_execute_data *execute_data); - -int zend_xdebug_initialised = 0; - -zend_module_entry xdebug_module_entry = { - STANDARD_MODULE_HEADER, - "xdebug", - ext_functions, - PHP_MINIT(xdebug), - PHP_MSHUTDOWN(xdebug), - PHP_RINIT(xdebug), - PHP_RSHUTDOWN(xdebug), - PHP_MINFO(xdebug), - XDEBUG_VERSION, - NO_MODULE_GLOBALS, - ZEND_MODULE_POST_ZEND_DEACTIVATE_N(xdebug), - STANDARD_MODULE_PROPERTIES_EX -}; - -ZEND_DECLARE_MODULE_GLOBALS(xdebug) - -#if COMPILE_DL_XDEBUG -ZEND_GET_MODULE(xdebug) -# ifdef ZTS -ZEND_TSRMLS_CACHE_DEFINE(); -# endif -#endif - -static PHP_INI_MH(OnUpdateServer) -{ - DUMP_TOK(server); -} - -static PHP_INI_MH(OnUpdateGet) -{ - DUMP_TOK(get); -} - -static PHP_INI_MH(OnUpdatePost) -{ - DUMP_TOK(post); -} - -static PHP_INI_MH(OnUpdateCookie) -{ - DUMP_TOK(cookie); -} - -static PHP_INI_MH(OnUpdateFiles) -{ - DUMP_TOK(files); -} - -static PHP_INI_MH(OnUpdateEnv) -{ - DUMP_TOK(env); -} - -static PHP_INI_MH(OnUpdateRequest) -{ - DUMP_TOK(request); -} - -static PHP_INI_MH(OnUpdateSession) -{ - DUMP_TOK(session); -} - -static PHP_INI_MH(OnUpdateMode) -{ - if (!new_value) { - return FAILURE; - } - - if (!xdebug_lib_set_mode(ZSTR_VAL(new_value))) { - return FAILURE; - } - - return SUCCESS; -} - -static PHP_INI_MH(OnUpdateStartWithRequest) -{ - if (!new_value) { - return FAILURE; - } - - if (!xdebug_lib_set_start_with_request(ZSTR_VAL(new_value))) { - return FAILURE; - } - - return SUCCESS; -} - -static PHP_INI_MH(OnUpdateStartUponError) -{ - if (!new_value) { - return FAILURE; - } - - if (!xdebug_lib_set_start_upon_error(ZSTR_VAL(new_value))) { - return FAILURE; - } - - return SUCCESS; -} - -static PHP_INI_MH(OnUpdateRemovedSetting) -{ - if (! (EG(error_reporting) & E_DEPRECATED)) { - return SUCCESS; - } - if (new_value && ZSTR_LEN(new_value) > 0 && strncmp("This setting", ZSTR_VAL(new_value), 11) != 0) { - xdebug_log_ex( - XLOG_CHAN_CONFIG, XLOG_CRIT, "REMOVED", - "The setting '%s' has been removed, see the upgrading guide at %supgrade_guide#changed-%s", - ZSTR_VAL(entry->name), xdebug_lib_docs_base(), ZSTR_VAL(entry->name) - ); - } - return FAILURE; -} - -static PHP_INI_MH(OnUpdateChangedSetting) -{ - if (! (EG(error_reporting) & E_DEPRECATED)) { - return SUCCESS; - } - if (new_value && ZSTR_LEN(new_value) > 0 && strncmp("This setting", ZSTR_VAL(new_value), 11) != 0) { - xdebug_log_ex( - XLOG_CHAN_CONFIG, XLOG_CRIT, "CHANGED", - "The setting '%s' has been renamed, see the upgrading guide at %supgrade_guide#changed-%s", - ZSTR_VAL(entry->name), xdebug_lib_docs_base(), ZSTR_VAL(entry->name) - ); - } - return FAILURE; -} - - -#ifdef P_tmpdir -# define XDEBUG_TEMP_DIR P_tmpdir -#else -# ifdef PHP_WIN32 -# define XDEBUG_TEMP_DIR "C:\\Windows\\Temp" -# else -# define XDEBUG_TEMP_DIR "/tmp" -# endif -#endif - -ZEND_INI_DISP(display_removed_setting) -{ - ZEND_PUTS("(setting removed in Xdebug 3)"); -} - -ZEND_INI_DISP(display_changed_setting) -{ - ZEND_PUTS("(setting renamed in Xdebug 3)"); -} - -#define XDEBUG_REMOVED_INI_ENTRY(n) PHP_INI_ENTRY_EX(("" # n), "This setting has been removed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#removed-" # n, PHP_INI_ALL, OnUpdateRemovedSetting, display_removed_setting) -#define XDEBUG_CHANGED_INI_ENTRY(n) PHP_INI_ENTRY_EX(("" # n), "This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-" # n, PHP_INI_ALL, OnUpdateChangedSetting, display_changed_setting) - -static const char *xdebug_start_with_request_types5 = { "", "default", "yes", "no", "trigger" }; - -ZEND_INI_DISP(display_start_with_request) -{ - char *value; - - if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { - value = ZSTR_VAL(ini_entry->orig_value); - } else if (ini_entry->value) { - value = ZSTR_VAL(ini_entry->value); - } else { - value = NULL; - } - if (value) { - ZEND_PUTS(xdebug_start_with_request_typesxdebug_lib_get_start_with_request()); - } else { - ZEND_PUTS("?"); - } -} - - -static const char *xdebug_start_upon_error_types4 = { "", "default", "yes", "no" }; - -ZEND_INI_DISP(display_start_upon_error) -{ - char *value; - - if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { - value = ZSTR_VAL(ini_entry->orig_value); - } else if (ini_entry->value) { - value = ZSTR_VAL(ini_entry->value); - } else { - value = NULL; - } - if (value) { - ZEND_PUTS(xdebug_start_upon_error_typesxdebug_lib_get_start_upon_error()); - } else { - ZEND_PUTS("?"); - } -} - - -#if HAVE_XDEBUG_ZLIB -# define USE_COMPRESSION_DEFAULT "1" -#else -# define USE_COMPRESSION_DEFAULT "0" -#endif - -PHP_INI_BEGIN() - /* Library settings */ - PHP_INI_ENTRY( "xdebug.mode", "develop", PHP_INI_SYSTEM, OnUpdateMode) - PHP_INI_ENTRY_EX( "xdebug.start_with_request", "default", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStartWithRequest, display_start_with_request) - PHP_INI_ENTRY_EX( "xdebug.start_upon_error", "default", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStartUponError, display_start_upon_error) - STD_PHP_INI_ENTRY("xdebug.output_dir", XDEBUG_TEMP_DIR, PHP_INI_ALL, OnUpdateString, settings.library.output_dir, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.use_compression", USE_COMPRESSION_DEFAULT, PHP_INI_ALL, OnUpdateBool, settings.library.use_compression, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.trigger_value", "", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, settings.library.trigger_value, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.file_link_format", "", PHP_INI_ALL, OnUpdateString, settings.library.file_link_format, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.filename_format", "", PHP_INI_ALL, OnUpdateString, settings.library.filename_format, zend_xdebug_globals, xdebug_globals) - - STD_PHP_INI_ENTRY("xdebug.log", "", PHP_INI_ALL, OnUpdateString, settings.library.log, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.log_level", XLOG_DEFAULT, PHP_INI_ALL, OnUpdateLong, settings.library.log_level, zend_xdebug_globals, xdebug_globals) - - /* Variable display settings */ - STD_PHP_INI_ENTRY("xdebug.var_display_max_children", "128", PHP_INI_ALL, OnUpdateLong, settings.library.display_max_children, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.var_display_max_data", "512", PHP_INI_ALL, OnUpdateLong, settings.library.display_max_data, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.var_display_max_depth", "3", PHP_INI_ALL, OnUpdateLong, settings.library.display_max_depth, zend_xdebug_globals, xdebug_globals) - - /* Base settings */ - STD_PHP_INI_ENTRY("xdebug.max_nesting_level", "256", PHP_INI_ALL, OnUpdateLong, settings.base.max_nesting_level, zend_xdebug_globals, xdebug_globals) - - /* Develop settings */ - STD_PHP_INI_ENTRY("xdebug.cli_color", "0", PHP_INI_ALL, OnUpdateLong, settings.develop.cli_color, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_BOOLEAN("xdebug.force_display_errors", "0", PHP_INI_SYSTEM, OnUpdateBool, settings.develop.force_display_errors, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.force_error_reporting", "0", PHP_INI_SYSTEM, OnUpdateLong, settings.develop.force_error_reporting, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.halt_level", "0", PHP_INI_ALL, OnUpdateLong, settings.develop.halt_level, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.max_stack_frames", "-1", PHP_INI_ALL, OnUpdateLong, settings.develop.max_stack_frames, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_BOOLEAN("xdebug.show_error_trace", "0", PHP_INI_ALL, OnUpdateBool, settings.develop.show_error_trace, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_BOOLEAN("xdebug.show_exception_trace", "0", PHP_INI_ALL, OnUpdateBool, settings.develop.show_ex_trace, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_BOOLEAN("xdebug.show_local_vars", "0", PHP_INI_ALL, OnUpdateBool, settings.develop.show_local_vars, zend_xdebug_globals, xdebug_globals) - - /* Dump superglobals settings */ - PHP_INI_ENTRY("xdebug.dump.COOKIE", NULL, PHP_INI_ALL, OnUpdateCookie) - PHP_INI_ENTRY("xdebug.dump.ENV", NULL, PHP_INI_ALL, OnUpdateEnv) - PHP_INI_ENTRY("xdebug.dump.FILES", NULL, PHP_INI_ALL, OnUpdateFiles) - PHP_INI_ENTRY("xdebug.dump.GET", NULL, PHP_INI_ALL, OnUpdateGet) - PHP_INI_ENTRY("xdebug.dump.POST", NULL, PHP_INI_ALL, OnUpdatePost) - PHP_INI_ENTRY("xdebug.dump.REQUEST", NULL, PHP_INI_ALL, OnUpdateRequest) - PHP_INI_ENTRY("xdebug.dump.SERVER", NULL, PHP_INI_ALL, OnUpdateServer) - PHP_INI_ENTRY("xdebug.dump.SESSION", NULL, PHP_INI_ALL, OnUpdateSession) - STD_PHP_INI_BOOLEAN("xdebug.dump_globals", "1", PHP_INI_ALL, OnUpdateBool, settings.develop.dump_globals, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_BOOLEAN("xdebug.dump_once", "1", PHP_INI_ALL, OnUpdateBool, settings.develop.dump_once, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_BOOLEAN("xdebug.dump_undefined", "0", PHP_INI_ALL, OnUpdateBool, settings.develop.dump_undefined, zend_xdebug_globals, xdebug_globals) - - /* Profiler settings */ - STD_PHP_INI_ENTRY("xdebug.profiler_output_name", "cachegrind.out.%p", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, settings.profiler.profiler_output_name, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_BOOLEAN("xdebug.profiler_append", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, settings.profiler.profiler_append, zend_xdebug_globals, xdebug_globals) - - /* Xdebug Cloud */ - STD_PHP_INI_ENTRY("xdebug.cloud_id", "", PHP_INI_SYSTEM, OnUpdateString, settings.debugger.cloud_id, zend_xdebug_globals, xdebug_globals) - - /* Remote debugger settings */ - STD_PHP_INI_ENTRY("xdebug.client_host", "localhost", PHP_INI_ALL, OnUpdateString, settings.debugger.client_host, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.client_port", "9003", PHP_INI_ALL, OnUpdateLong, settings.debugger.client_port, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_BOOLEAN("xdebug.discover_client_host", "0", PHP_INI_ALL, OnUpdateBool, settings.debugger.discover_client_host, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.client_discovery_header", "", PHP_INI_ALL, OnUpdateString, settings.debugger.client_discovery_header, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.idekey", "", PHP_INI_ALL, OnUpdateString, settings.debugger.ide_key_setting, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.connect_timeout_ms", "200", PHP_INI_ALL, OnUpdateLong, settings.debugger.connect_timeout_ms, zend_xdebug_globals, xdebug_globals) - - /* Scream support */ - STD_PHP_INI_BOOLEAN("xdebug.scream", "0", PHP_INI_ALL, OnUpdateBool, settings.develop.do_scream, zend_xdebug_globals, xdebug_globals) - - /* GC Stats support */ - STD_PHP_INI_ENTRY("xdebug.gc_stats_output_name", "gcstats.%p", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, settings.gc_stats.output_name, zend_xdebug_globals, xdebug_globals) - - /* Tracing settings */ - STD_PHP_INI_ENTRY("xdebug.trace_output_name", "trace.%c", PHP_INI_ALL, OnUpdateString, settings.tracing.trace_output_name, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.trace_format", "0", PHP_INI_ALL, OnUpdateLong, settings.tracing.trace_format, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_ENTRY("xdebug.trace_options", "0", PHP_INI_ALL, OnUpdateLong, settings.tracing.trace_options, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_BOOLEAN("xdebug.collect_assignments", "0", PHP_INI_ALL, OnUpdateBool, settings.tracing.collect_assignments, zend_xdebug_globals, xdebug_globals) - STD_PHP_INI_BOOLEAN("xdebug.collect_return", "0", PHP_INI_ALL, OnUpdateBool, settings.tracing.collect_return, zend_xdebug_globals, xdebug_globals) - - /* Removed/Changed settings */ - XDEBUG_CHANGED_INI_ENTRY(xdebug.auto_trace) - XDEBUG_REMOVED_INI_ENTRY(xdebug.collect_includes) - XDEBUG_REMOVED_INI_ENTRY(xdebug.collect_params) - XDEBUG_REMOVED_INI_ENTRY(xdebug.collect_vars) - XDEBUG_CHANGED_INI_ENTRY(xdebug.coverage_enable) - XDEBUG_CHANGED_INI_ENTRY(xdebug.default_enable) - XDEBUG_CHANGED_INI_ENTRY(xdebug.gc_stats_enable) - XDEBUG_CHANGED_INI_ENTRY(xdebug.gc_stats_output_dir) - XDEBUG_REMOVED_INI_ENTRY(xdebug.overload_var_dump) - XDEBUG_CHANGED_INI_ENTRY(xdebug.profiler_enable) - XDEBUG_CHANGED_INI_ENTRY(xdebug.profiler_enable_trigger) - XDEBUG_CHANGED_INI_ENTRY(xdebug.profiler_enable_trigger_value) - XDEBUG_CHANGED_INI_ENTRY(xdebug.profiler_output_dir) - XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_autostart) - XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_connect_back) - XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_enable) - XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_host) - XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_log) - XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_log_level) - XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_mode) - XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_port) - XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_timeout) - XDEBUG_REMOVED_INI_ENTRY(xdebug.show_mem_delta) - XDEBUG_CHANGED_INI_ENTRY(xdebug.trace_output_dir) - XDEBUG_CHANGED_INI_ENTRY(xdebug.trace_enable_trigger) - XDEBUG_CHANGED_INI_ENTRY(xdebug.trace_enable_trigger_value) -PHP_INI_END() - -static void xdebug_init_base_globals(xdebug_base_globals_t *xg) -{ - xg->stack = NULL; - xg->in_debug_info = 0; - xg->output_is_tty = OUTPUT_NOT_CHECKED; - xg->in_execution = 0; - xg->in_var_serialisation = 0; - xg->error_reporting_override = 0; - xg->error_reporting_overridden = 0; - - xg->filter_type_code_coverage = XDEBUG_FILTER_NONE; - xg->filter_type_stack = XDEBUG_FILTER_NONE; - xg->filter_type_tracing = XDEBUG_FILTER_NONE; - xg->filters_code_coverage = NULL; - xg->filters_stack = NULL; - xg->filters_tracing = NULL; - - xg->php_version_compile_time = PHP_VERSION; - xg->php_version_run_time = zend_get_module_version("standard"); - - xdebug_nanotime_init(xg); -} - - -static void php_xdebug_init_globals(zend_xdebug_globals *xg) -{ - memset(&xg->globals, 0, sizeof(xg->globals)); - - xdebug_init_library_globals(&xg->globals.library); - xdebug_init_base_globals(&xg->globals.base); - - if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { - xdebug_init_coverage_globals(&xg->globals.coverage); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - xdebug_init_debugger_globals(&xg->globals.debugger); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - xdebug_init_develop_globals(&xg->globals.develop); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - xdebug_init_profiler_globals(&xg->globals.profiler); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { - xdebug_init_gc_stats_globals(&xg->globals.gc_stats); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { - xdebug_init_tracing_globals(&xg->globals.tracing); - } -} - -static void php_xdebug_shutdown_globals(zend_xdebug_globals *xg) -{ - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - xdebug_deinit_develop_globals(&xg->globals.develop); - } -} - - -static void xdebug_env_config(void) -{ - char *config = getenv("XDEBUG_CONFIG"); - xdebug_arg *parts; - int i; - /* - XDEBUG_CONFIG format: - XDEBUG_CONFIG=var=val var=val - */ - if (!config) { - return; - } - - parts = xdebug_arg_ctor(); - xdebug_explode(" ", config, parts, -1); - - for (i = 0; i < parts->c; ++i) { - const char *name = NULL; - char *envvar = parts->argsi; - char *envval = NULL; - char *eq = strchr(envvar, '='); - if (!eq || !*eq) { - continue; - } - *eq = 0; - envval = eq + 1; - if (!*envval) { - continue; - } - - if (strcasecmp(envvar, "discover_client_host") == 0) { - name = "xdebug.discover_client_host"; - } else - if (strcasecmp(envvar, "client_port") == 0) { - name = "xdebug.client_port"; - } else - if (strcasecmp(envvar, "client_host") == 0) { - name = "xdebug.client_host"; - } else - if (strcasecmp(envvar, "cloud_id") == 0) { - name = "xdebug.cloud_id"; - } else - if (strcasecmp(envvar, "idekey") == 0) { - xdebug_debugger_reset_ide_key(envval); - } else - if (strcasecmp(envvar, "output_dir") == 0) { - name = "xdebug.output_dir"; - } else - if (strcasecmp(envvar, "profiler_output_name") == 0) { - name = "xdebug.profiler_output_name"; - } else - if (strcasecmp(envvar, "log") == 0) { - name = "xdebug.log"; - } else - if (strcasecmp(envvar, "log_level") == 0) { - name = "xdebug.log_level"; - } else - if (strcasecmp(envvar, "cli_color") == 0) { - name = "xdebug.cli_color"; - } - - if (name) { - zend_string *ini_name = zend_string_init(name, strlen(name), 0); - zend_string *ini_val = zend_string_init(envval, strlen(envval), 0); - zend_alter_ini_entry(ini_name, ini_val, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); - zend_string_release(ini_val); - zend_string_release(ini_name); - } - } - - xdebug_arg_dtor(parts); -} - -int xdebug_is_output_tty(void) -{ - if (XG_BASE(output_is_tty) == OUTPUT_NOT_CHECKED) { -#ifndef PHP_WIN32 - XG_BASE(output_is_tty) = isatty(STDOUT_FILENO); -#else - XG_BASE(output_is_tty) = getenv("ANSICON") != NULL; -#endif - } - return (XG_BASE(output_is_tty)); -} - -PHP_MINIT_FUNCTION(xdebug) -{ - ZEND_INIT_MODULE_GLOBALS(xdebug, php_xdebug_init_globals, php_xdebug_shutdown_globals); - REGISTER_INI_ENTRIES(); - - if (XDEBUG_MODE_IS_OFF()) { - return SUCCESS; - } - - xdebug_library_minit(); - xdebug_base_minit(INIT_FUNC_ARGS_PASSTHRU); - - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - xdebug_debugger_minit(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - xdebug_develop_minit(INIT_FUNC_ARGS_PASSTHRU); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { - xdebug_gcstats_minit(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - xdebug_profiler_minit(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { - xdebug_tracing_minit(INIT_FUNC_ARGS_PASSTHRU); - } - - /* Overload the "include_or_eval" opcode if the mode is 'debug' or 'trace' */ - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG) || XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { - xdebug_register_with_opcode_multi_handler(ZEND_INCLUDE_OR_EVAL, xdebug_include_or_eval_handler); - } - - /* Coverage must be last, as it has a catch all override for opcodes */ - if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { - xdebug_coverage_minit(INIT_FUNC_ARGS_PASSTHRU); - } - - if (zend_xdebug_initialised == 0) { - zend_error(E_WARNING, "Xdebug MUST be loaded as a Zend extension"); - } - - xdebug_coverage_register_constants(INIT_FUNC_ARGS_PASSTHRU); - xdebug_filter_register_constants(INIT_FUNC_ARGS_PASSTHRU); - xdebug_tracing_register_constants(INIT_FUNC_ARGS_PASSTHRU); - - return SUCCESS; -} - -PHP_MSHUTDOWN_FUNCTION(xdebug) -{ - if (XDEBUG_MODE_IS_OFF()) { -#ifdef ZTS - ts_free_id(xdebug_globals_id); -#endif - return SUCCESS; - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { - xdebug_gcstats_mshutdown(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - xdebug_profiler_mshutdown(); - } - - xdebug_library_mshutdown(); - -#ifdef ZTS - ts_free_id(xdebug_globals_id); -#else - php_xdebug_shutdown_globals(&xdebug_globals); -#endif - - return SUCCESS; -} - -static void xdebug_init_auto_globals(void) -{ - zend_is_auto_global_str((char*) ZEND_STRL("_ENV")); - zend_is_auto_global_str((char*) ZEND_STRL("_GET")); - zend_is_auto_global_str((char*) ZEND_STRL("_POST")); - zend_is_auto_global_str((char*) ZEND_STRL("_COOKIE")); - zend_is_auto_global_str((char*) ZEND_STRL("_REQUEST")); - zend_is_auto_global_str((char*) ZEND_STRL("_FILES")); - zend_is_auto_global_str((char*) ZEND_STRL("_SERVER")); - zend_is_auto_global_str((char*) ZEND_STRL("_SESSION")); -} - - -PHP_RINIT_FUNCTION(xdebug) -{ -#if defined(ZTS) && defined(COMPILE_DL_XDEBUG) - ZEND_TSRMLS_CACHE_UPDATE(); -#endif - - if (XDEBUG_MODE_IS_OFF()) { - return SUCCESS; - } - -#if PHP_VERSION_ID >= 70300 && PHP_VERSION_ID <= 70301 - /* PHP Bug #77287 causes Xdebug to segfault if Opcache has the "compact - * literals" optimisation turned on. So force the optimisation off for PHP - * 7.3.0 and 7.3.1. */ - xdebug_disable_opcache_optimizer(); -#endif - - xdebug_library_rinit(); - - if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { - xdebug_coverage_rinit(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - xdebug_debugger_rinit(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - xdebug_develop_rinit(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { - xdebug_gcstats_rinit(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - xdebug_profiler_rinit(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { - xdebug_tracing_rinit(); - } - - /* Get xdebug ini entries from the environment also, - this can override the idekey if one is set */ - xdebug_env_config(); - - xdebug_init_auto_globals(); - - /* Only enabled extended info when it is not disabled */ - CG(compiler_options) = CG(compiler_options) | ZEND_COMPILE_EXTENDED_STMT; - - xdebug_base_rinit(); - - return SUCCESS; -} - -ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xdebug) -{ - if (XDEBUG_MODE_IS_OFF()) { - return SUCCESS; - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { - xdebug_coverage_post_deactivate(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - xdebug_debugger_post_deactivate(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { - xdebug_develop_post_deactivate(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { - xdebug_profiler_post_deactivate(); - } - if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { - xdebug_tracing_post_deactivate(); - } - - xdebug_base_post_deactivate(); - xdebug_library_post_deactivate(); - - return SUCCESS; -} - -PHP_RSHUTDOWN_FUNCTION(xdebug) -{ - if (XDEBUG_MODE_IS_OFF()) { - return SUCCESS; - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { - xdebug_gcstats_rshutdown(); - } - - xdebug_base_rshutdown(); - - return SUCCESS; -} - -PHP_MINFO_FUNCTION(xdebug) -{ - xdebug_print_info(); - - if (zend_xdebug_initialised == 0) { - php_info_print_table_start(); - php_info_print_table_header(1, "XDEBUG NOT LOADED AS ZEND EXTENSION"); - php_info_print_table_end(); - } - - if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { - xdebug_debugger_minfo(); - } - - DISPLAY_INI_ENTRIES(); -} - -ZEND_DLEXPORT void xdebug_statement_call(zend_execute_data *frame) -{ - zend_op_array *op_array = &frame->func->op_array; - int lineno; - - if (XDEBUG_MODE_IS_OFF()) { - return; - } - - if (!EG(current_execute_data)) { - return; - } - - lineno = EG(current_execute_data)->opline->lineno; - - xdebug_coverage_count_line_if_active(op_array, op_array->filename, lineno); - xdebug_debugger_statement_call(op_array->filename, lineno); -} - -ZEND_DLEXPORT int xdebug_zend_startup(zend_extension *extension) -{ - xdebug_library_zend_startup(); - xdebug_debugger_zend_startup(); - - zend_xdebug_initialised = 1; - -#if PHP_VERSION_ID >= 70300 - xdebug_orig_post_startup_cb = zend_post_startup_cb; - zend_post_startup_cb = xdebug_post_startup; - - return zend_startup_module(&xdebug_module_entry); -} - -static int xdebug_post_startup(void) -{ - if (xdebug_orig_post_startup_cb) { - int (*cb)(void) = xdebug_orig_post_startup_cb; - - xdebug_orig_post_startup_cb = NULL; - if (cb() != SUCCESS) { - return FAILURE; - } - } - - xdebug_base_post_startup(); - - return SUCCESS; -#else - return zend_startup_module(&xdebug_module_entry); -#endif -} - -ZEND_DLEXPORT void xdebug_zend_shutdown(zend_extension *extension) -{ - xdebug_debugger_zend_shutdown(); - - xdebug_library_zend_shutdown(); -} - -ZEND_DLEXPORT void xdebug_init_oparray(zend_op_array *op_array) -{ - if (XDEBUG_MODE_IS_OFF()) { - return; - } - - xdebug_coverage_init_oparray(op_array); -} - -#ifndef ZEND_EXT_API -#define ZEND_EXT_API ZEND_DLEXPORT -#endif - -ZEND_EXT_API zend_extension_version_info extension_version_info = { ZEND_EXTENSION_API_NO, (char*) ZEND_EXTENSION_BUILD_ID }; - -ZEND_DLEXPORT zend_extension zend_extension_entry = { - (char*) XDEBUG_NAME, - (char*) XDEBUG_VERSION, - (char*) XDEBUG_AUTHOR, - (char*) XDEBUG_URL_FAQ, - (char*) XDEBUG_COPYRIGHT_SHORT, - xdebug_zend_startup, - xdebug_zend_shutdown, - NULL, /* activate_func_t */ - NULL, /* deactivate_func_t */ - NULL, /* message_handler_func_t */ - NULL, /* op_array_handler_func_t */ - xdebug_statement_call, /* statement_handler_func_t */ - NULL, /* fcall_begin_handler_func_t */ - NULL, /* fcall_end_handler_func_t */ - xdebug_init_oparray, /* op_array_ctor_func_t */ - NULL, /* op_array_dtor_func_t */ - STANDARD_ZEND_EXTENSION_PROPERTIES -}; - -#endif
View file
xdebug-3.1.5.tgz/xdebug-3.1.5/xdebug.ini
Deleted
@@ -1,1204 +0,0 @@ -; This file is generated by the 'xdebug.org:html/docs/convert.php' robot -; for Xdebug 3.1.5 — do not modify by hand - -; ----------------------------------------------------------------------------- -; xdebug.cli_color -; -; Type: integer, Default value: 0 -; -; If this setting is 1, Xdebug will color var_dumps and stack traces output when -; in CLI mode and when the output is a tty. On Windows, the ANSICON 1 tool -; needs to be installed. -; -; 1 http://adoxa.altervista.org/ansicon/ -; -; If the setting is 2, then Xdebug will always color var_dumps and stack trace, -; no matter whether it's connected to a tty or whether ANSICON is installed. In -; this case, you might end up seeing escape codes. -; -; See this article 1 for some more information. -; -; 1 https://derickrethans.nl/cli-color.html -; -; .. note:: -; -; This setting can additionally be configured through the -; ``XDEBUG_CONFIG``environment variable 1. 1 -; /docs/all_settings#XDEBUG_CONFIG -; -; -;xdebug.cli_color = 0 - -; ----------------------------------------------------------------------------- -; xdebug.client_discovery_header -; -; Type: string, Default value: "" -; -; If xdebug.client_discovery_header is configured to be a non-empty string, then -; the value is used as key in the ``$_SERVER`` superglobal array to determine -; which header to use to find the IP address or hostname to use for 'connecting -; back to'. This setting is only used in combination with -; xdebug.discover_client_host and is otherwise ignored. -; -; For example, if xdebug.client_discovery_header is set to -; ``HTTP_FORWARD_HOST``, then Xdebug will check -; ``$_SERVER'HTTP_FORWARD_HOST'`` before the -; ``$_SERVER'HTTP_X_FORWARDED_FOR'`` and ``$_SERVER'REMOTE_ADDR'`` -; variables. -; -; .. warning:: -; -; PHP automatically prepends ``HTTP_``, and converts ``-`` to ``_``, for -; received HTTP header names. The ``THIS-IS-MY-HOST`` HTTP header is -; converted into ``$_SERVER'HTTP_THIS_IS_MY_HOST'``. Therefore, the -; xdebug.client_discovery_header needs to be set to ``HTTP_THIS_IS_MY_HOST`` -; to match this. -; -; -;xdebug.client_discovery_header = "" - -; ----------------------------------------------------------------------------- -; xdebug.client_host -; -; Type: string, Default value: localhost -; -; Configures the IP address or hostname where Xdebug will attempt to connect to -; when initiating a debugging connection. This address should be the address of -; the machine where your IDE or debugging client is listening for incoming -; debugging connections. -; -; On non-Windows platforms, it is also possible to configure a Unix domain -; socket 1 which is supported by only a select view debugging clients. In that -; case, instead of the hostname or IP address, use ``unix:///path/to/sock``. -; -; 1 https://en.wikipedia.org/wiki/Unix_domain_socket -; -; If xdebug.discover_client_host is enabled then Xdebug will only use the value -; of this setting in case Xdebug can not connect to an IDE using the information -; it obtained from HTTP headers. In that case, the value of this setting acts as -; a fallback only. -; -; .. note:: -; -; This setting can additionally be configured through the -; ``XDEBUG_CONFIG``environment variable 1. 1 -; /docs/all_settings#XDEBUG_CONFIG -; -; -;xdebug.client_host = localhost - -; ----------------------------------------------------------------------------- -; xdebug.client_port -; -; Type: integer, Default value: 9003 -; -; The port to which Xdebug tries to connect on the remote host. Port ``9003`` is -; the default for both Xdebug and the Command Line Debug Client. As many clients -; use this port number, it is best to leave this setting unchanged. -; -; .. note:: -; -; This setting can additionally be configured through the -; ``XDEBUG_CONFIG``environment variable 1. 1 -; /docs/all_settings#XDEBUG_CONFIG -; -; -;xdebug.client_port = 9003 - -; ----------------------------------------------------------------------------- -; xdebug.cloud_id -; -; Type: string, Default value: -; -; With this setting you configure Xdebug for use with Xdebug Cloud 1. It needs -; to match one of the tokens from your profile page 2. -; -; 1 https://xdebug.cloud -; 2 https://xdebug.cloud/profile#tokens -; -; Your IDE needs to be configured with the same token for Xdebug and your IDE to -; communicate through Xdebug Cloud. -; -; | In PhpStorm you can find this setting under: -; | File | Settings | PHP | Debug | Xdebug Cloud for Windows and Linux -; | PhpStorm | Preferences | PHP | Debug | Xdebug Cloud for macOS -; -; -;xdebug.cloud_id = - -; ----------------------------------------------------------------------------- -; xdebug.collect_assignments -; -; Type: boolean, Default value: false -; -; This setting, defaulting to 0, controls whether Xdebug should add variable -; assignments to function traces. Assign-by-var ( ``=&``) assignments are -; included too. -; -; -;xdebug.collect_assignments = false - -; ----------------------------------------------------------------------------- -; xdebug.collect_return -; -; Type: boolean, Default value: false -; -; This setting, defaulting to 0, controls whether Xdebug should write the return -; value of function calls to the trace files. -; -; -;xdebug.collect_return = false - -; ----------------------------------------------------------------------------- -; xdebug.connect_timeout_ms -; -; Type: integer, Default value: 200 -; -; The amount of time in milliseconds that Xdebug will wait for on an IDE to -; acknowledge an incoming debugging connection. The default value of 200 ms -; should in most cases be enough. In case you often get dropped debugging -; requests, perhaps because you have a high latency network, or a development -; box far away from your IDE, or have a slow firewall, then you can should -; increase this value. -; -; Please note that increasing this value might mean that your requests seem to -; 'hang' in case Xdebug tries to establish a connection, but your IDE is not -; listening. -; -; -;xdebug.connect_timeout_ms = 200 - -; ----------------------------------------------------------------------------- -; xdebug.discover_client_host -; -; Type: boolean, Default value: false -; -; If enabled, Xdebug will first try to connect to the client that made the HTTP -; request. It checks the ``$_SERVER'HTTP_X_FORWARDED_FOR'`` and -; ``$_SERVER'REMOTE_ADDR'`` variables to find out which hostname or IP address -; to use. -; -; If xdebug.client_discovery_header is configured, then the ``$_SERVER`` -; variable with that configured name will be checked before -; ``HTTP_X_FORWARDED_FOR`` and ``REMOTE_ADDR``. -; -; If Xdebug can not connect to a debugging client as found in one of the HTTP -; headers, it will fall back to the hostname or IP address as configured by the -; xdebug.client_host setting. -; -; This setting does not apply for debugging through the CLI, as the ``$_SERVER`` -; header variables are not available there. -; -; .. note:: -; -; This setting can additionally be configured through the -; ``XDEBUG_CONFIG``environment variable 1. 1 -; /docs/all_settings#XDEBUG_CONFIG -; -; .. warning:: -; -; Please note that there is no filter available, and anybody who can connect -; to the webserver will then be able to start a debugging session, even if -; their address does not match xdebug.client_host. -; -; -;xdebug.discover_client_host = false - -; ----------------------------------------------------------------------------- -; xdebug.dump.* -; -; Type: string, Default value: Empty -; -; * can be any of COOKIE, FILES, GET, POST, REQUEST, SERVER, SESSION. These -; seven settings control which data from the superglobals is shown when an error -; situation occurs. -; -; Each of those php.ini setting can consist of a comma separated list of -; variables from this superglobal to dump, or ``*`` for all of them. Make sure -; you do not add spaces in this setting. -; -; In order to dump the REMOTE_ADDR and the REQUEST_METHOD when an error occurs, -; and all GET parameters, add these settings: -; -; xdebug.dump.SERVER = REMOTE_ADDR,REQUEST_METHOD -; xdebug.dump.GET = * -; -; -;xdebug.dump.* = Empty - -; ----------------------------------------------------------------------------- -; xdebug.dump_globals -; -; Type: boolean, Default value: true -; -; When this setting is set to ``true``, Xdebug adds the values of the super -; globals as configured through the xdebug.dump.* to on-screen stack traces and -; the error log (if enabled). -; -; -;xdebug.dump_globals = true - -; ----------------------------------------------------------------------------- -; xdebug.dump_once -; -; Type: boolean, Default value: true -; -; Controls whether the values of the superglobals should be dumped on all error -; situations (set to 0) or only on the first (set to 1). -; -; -;xdebug.dump_once = true - -; ----------------------------------------------------------------------------- -; xdebug.dump_undefined -; -; Type: boolean, Default value: false -; -; If you want to dump undefined values from the superglobals you should set this -; setting to 1, otherwise leave it set to 0. -; -; -;xdebug.dump_undefined = false - -; ----------------------------------------------------------------------------- -; xdebug.file_link_format -; -; Type: string, Default value: -; -; This setting determines the format of the links that are made in the display -; of stack traces where file names are used. This allows IDEs to set up a -; link-protocol that makes it possible to go directly to a line and file by -; clicking on the filenames that Xdebug shows in stack traces. An example format -; might look like: -; -; myide://%f@%l -; -; The possible format specifiers are: -; -; ========= =============== -; Specifier Meaning -; ========= =============== -; %f the filename -; --------- --------------- -; %l the line number -; ========= =============== -; -; For various IDEs/OSses there are some instructions listed on how to make this -; work: -; -; ---------------- -; Firefox on Linux -; ---------------- -; -; - Open -; -; about:config -; -; - Add a new boolean setting "network.protocol-handler.expose.xdebug" and set -; it to "false" -; -; - Add the following into a shell script -; -; ``~/bin/ff-xdebug.sh``: -; -; #! /bin/sh -; -; f=`echo $1 | cut -d @ -f 1 | sed 's/xdebug:\/\///'` -; l=`echo $1 | cut -d @ -f 2` -; -; Add to that one of (depending whether you have komodo, gvim or netbeans): -; -; - komodo $f -l $l -; -; - gvim --remote-tab +$l $f -; -; - netbeans "$f:$l" -; -; - Make the script executable with -; -; chmod +x ~/bin/ff-xdebug.sh -; -; - Set the xdebug.file_link_format setting to -; -; xdebug://%f@%l -; -; -------------------- -; Windows and netbeans -; -------------------- -; -; - Create the file -; -; ``netbeans.bat`` and save it in your path ( ``C:\Windows`` will work): -; -; @echo off -; setlocal enableextensions enabledelayedexpansion -; set NETBEANS=%1 -; set FILE=%~2 -; %NETBEANS% --nosplash --console suppress --open "%FILE:~19%" -; nircmd win activate process netbeans.exe -; -; **Note:** Remove the last line if you don't have ``nircmd``. -; -; - Save the following code as -; -; ``netbeans_protocol.reg``: -; -; Windows Registry Editor Version 5.00 -; -; HKEY_CLASSES_ROOT\netbeans -; "URL Protocol"="" -; @="URL:Netbeans Protocol" -; -; HKEY_CLASSES_ROOT\netbeans\DefaultIcon -; @="\"C:\\Program Files\\NetBeans 7.1.1\\bin\\netbeans.exe,1\"" -; -; HKEY_CLASSES_ROOT\netbeans\shell -; -; HKEY_CLASSES_ROOT\netbeans\shell\open -; -; HKEY_CLASSES_ROOT\netbeans\shell\open\command -; @="\"C:\\Windows\\netbeans.bat\" \"C:\\Program Files\\NetBeans 7.1.1\\bin\\netbeans.exe\" \"%1\"" -; -; **Note:** Make sure to change the path to Netbeans (twice), as well as the -; ``netbeans.bat`` batch file if you saved it somewhere else than -; ``C:\Windows\``. -; -; - Double click on the -; -; ``netbeans_protocol.reg`` file to import it into the registry. -; -; - Set the xdebug.file_link_format setting to -; -; xdebug.file_link_format = -; "netbeans://open/?f=%f:%l" -; -; -;xdebug.file_link_format = - -; ----------------------------------------------------------------------------- -; xdebug.filename_format -; -; Type: string, Default value: ...%s%n -; -; This setting determines the format with which Xdebug renders filenames in HTML -; stack traces (default: ``...%s%n``) and location information through the -; overloaded xdebug_var_dump() (default: ``%f``). -; -; The possible format specifiers are listed in this table. The example output is -; rendered according to the full path -; ``/var/www/vendor/mail/transport/mta.php``. -; -; ========= ============================================== =========================================================== -; Specifier Meaning Example Output -; ========= ============================================== =========================================================== -; %a Ancester: Two directory elements and filename mail/transport/mta.php -; --------- ---------------------------------------------- ----------------------------------------------------------- -; %f Full path /var/www/vendor/mail/transport/mta.php -; --------- ---------------------------------------------- ----------------------------------------------------------- -; %n Name: Only the file name mta.php -; --------- ---------------------------------------------- ----------------------------------------------------------- -; %p Parent: One directory element and the filename transport/mta.php -; --------- ---------------------------------------------- ----------------------------------------------------------- -; %s Directory separator / -; on Linux, OSX and other Unix-like systems, ``\`` on Windows -; ========= ============================================== =========================================================== -; -; -;xdebug.filename_format = ...%s%n - -; ----------------------------------------------------------------------------- -; xdebug.force_display_errors -; -; Type: integer, Default value: 0 -; -; If this setting is set to ``1`` then errors will **always** be displayed, no -; matter what the setting of PHP's display_errors 1 is. -; -; 1 https://www.php.net/manual/errorfunc.configuration.php#ini.display-errors -; -; -;xdebug.force_display_errors = 0 - -; ----------------------------------------------------------------------------- -; xdebug.force_error_reporting -; -; Type: integer, Default value: 0 -; -; This setting is a bitmask, like error_reporting 1. This bitmask will be -; logically ORed with the bitmask represented by error_reporting 2 to dermine -; which errors should be displayed. This setting can only be made in php.ini and -; allows you to force certain errors from being shown no matter what an -; application does with ini_set() 3. -; -; 1 https://www.php.net/manual/errorfunc.configuration.php#ini.error-reporting -; 2 https://www.php.net/manual/errorfunc.configuration.php#ini.error-reporting -; 3 https://www.php.net/manual/function.ini-set.php -; -; -;xdebug.force_error_reporting = 0 - -; ----------------------------------------------------------------------------- -; xdebug.gc_stats_output_name -; -; Type: string, Default value: gcstats.%p -; -; This setting determines the name of the file that is used to dump garbage -; collection statistics into. The setting specifies the format with format -; specifiers, very similar to sprintf() and strftime(). There are several format -; specifiers that can be used to format the file name. -; -; See the xdebug.trace_output_name documentation for the supported specifiers. -; -; -;xdebug.gc_stats_output_name = gcstats.%p - -; ----------------------------------------------------------------------------- -; xdebug.halt_level -; -; Type: integer, Default value: 0 -; -; This setting allows you to configure a mask that determines whether, and -; which, notices and/or warnings get converted to errors. You can configure -; notices and warnings that are generated by PHP, and notices and warnings that -; you generate yourself (by means of trigger_error()). For example, to convert -; the warning of strlen() (without arguments) to an error, you would do: -; -; ini_set('xdebug.halt_level', E_WARNING); -; strlen(); -; echo "Hi!\n"; -; -; Which will then result in the showing of the error message, and the abortion -; of the script. ``echo "Hi!\n";`` will not be executed. -; -; The setting is a bit mask, so to convert all notices and warnings into errors -; for all applications, you can set this in php.ini: -; -; xdebug.halt_level=E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE -; -; The bitmask only supports the four level that are mentioned above. -; -; -;xdebug.halt_level = 0 - -; ----------------------------------------------------------------------------- -; xdebug.idekey -; -; Type: string, Default value: *complex* -; -; Controls which IDE Key Xdebug should pass on to the debugging client or proxy. -; The IDE Key is only important for use with the DBGp Proxy Tool, although some -; IDEs are incorrectly picky as to what its value is. -; -; The default is based on the ``DBGP_IDEKEY`` environment setting. If it is not -; present, the default falls back to an empty string. -; -; If this setting is set to a non-empty string, it selects its value over -; ``DBGP_IDEKEY`` environment variable as default value. -; -; The internal IDE Key also gets updated through debugging session management -; and overrides the value of this setting as is explained in the Step Debugging -; documentation. -; -; .. note:: -; -; This setting can additionally be configured through the -; ``XDEBUG_CONFIG``environment variable 1. 1 -; /docs/all_settings#XDEBUG_CONFIG -; -; -;xdebug.idekey = *complex* - -; ----------------------------------------------------------------------------- -; xdebug.log -; -; Type: string, Default value: -; -; Configures Xdebug's log file. -; -; Xdebug will log to this file all file creations issues, Step Debugging -; connection attempts, failures, and debug communication. -; -; Enable this functionality by setting the value to a absolute path. Make sure -; that the system user that PHP runs at (such as ``www-data`` if you are running -; with Apache) can create and write to the file. -; -; The file is opened in append-mode, and will therefore not be overwritten by -; default. There is no concurrency protection available. -; -; The log file will include any attempt that Xdebug makes to connect to an IDE: -; -; 2693358 Log opened at 2020-09-02 07:19:09.616195 -; 2693358 Step Debug INFO: Connecting to configured address/port: localhost:9003. -; 2693358 Step Debug ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port). -; 2693358 Profiler ERR: File '/foo/cachegrind.out.2693358' could not be opened. -; 2693358 Profiler WARN: /foo: No such file or directory -; 2693358 Tracing ERR: File '/foo/trace.1485761369' could not be opened. -; 2693358 Tracing WARN: /foo: No such file or directory -; 2693358 Log closed at 2020-09-02 07:19:09.617510 -; -; It includes the opening time ( ``2020-09-02 07:19:09.616195``), the -; IP/Hostname and port Xdebug is trying to connect to ( ``localhost:9003``), and -; whether it succeeded ( ``Connected to client``). The number in brackets ( -; ``2693358``) is the Process ID. -; -; It includes: -; -; 2693358 -; process ID in brackets -; -; 2020-09-02 07:19:09.616195 -; opening time -; -; For Step Debugging: -; -; INFO: Connecting to configured address/port: localhost:9003. -; ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port). -; -; For Profiling: -; -; ERR: File '/foo/cachegrind.out.2693358' could not be opened. -; WARN: /foo: No such file or directory -; -; For Function Trace: -; -; ERR: File '/foo/trace.1485761369' could not be opened. -; WARN: /foo: No such file or directory -; -; All warnings and errors are described on the Description of errors page, with -; detailed instructions on how to resolve the problem, if possible. All errors -; are always logged through PHP's internal logging mechanism (configured with -; error_log 1 in ``php.ini``). All warnings and errors also show up in the -; diagnostics log that you can view by calling xdebug_info(). -; -; 1 https://www.php.net/manual/en/errorfunc.configuration.php#ini.error-log -; -; --------------------------- -; Step Debugger Communication -; --------------------------- -; -; The debugging log can also log the communication between Xdebug and an IDE. -; This communication is in XML, and starts with the ``<init`` XML element: -; -; <init -; xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" -; fileuri="file:///home/httpd/www.xdebug.org/html/router.php" -; language="PHP" xdebug:language_version="7.4.11-dev" -; protocol_version="1.0" appid="2693358" idekey="XDEBUG_ECLIPSE"> -; <engine version="3.0.0-dev"><!CDATAXdebug></engine> -; <author><!CDATADerick Rethans></author> -; <url><!CDATAhttps://xdebug.org></url> -; <copyright><!CDATACopyright (c) 2002-2020 by Derick Rethans></copyright> -; </init> -; -; The ``fileuri`` attribute lists the entry point of your application, which can -; be useful to compare to ``breakpoint_set`` commands to see if path mappings -; are set-up correctly. -; -; Beyond the ``<init`` element, you will find the configuration of features 1: -; -; 1 /docs/dbgp#feature-names -; -; <- feature_set -i 4 -n extended_properties -v 1 -; -> <response -; xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" -; command="feature_set" transaction_id="4" feature="extended_properties" success="1"> -; </response> -; -; And continuation commands 1: -; -; 1 /docs/dbgp#continuation-commands -; -; <- step_into -i 9 -; -> <response -; xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" -; command="step_into" transaction_id="9" -; status="break" reason="ok"> -; <xdebug:message filename="file:///home/httpd/www.xdebug.org/html/router.php" lineno="3"> -; </xdebug:message> -; </response> -; -; You can read about DBGP - A common debugger protocol specification at its -; dedicated documation page. -; -; The xdebug.log_level setting controls how much information is logged. -; -; .. warning:: -; -; Many Linux distributions now use systemd, which implements **private tmp** -; directories. This means that when PHP is run through a web server or as -; PHP-FPM, the ``/tmp`` directory is prefixed with something akin to: -; -; /tmp/systemd-private-ea3cfa882b4e478993e1994033fc5feb-apache.service-FfWZRg -; -; -; .. note:: -; -; This setting can additionally be configured through the -; ``XDEBUG_CONFIG``environment variable 1. 1 -; /docs/all_settings#XDEBUG_CONFIG -; -; -;xdebug.log = - -; ----------------------------------------------------------------------------- -; xdebug.log_level -; -; Type: integer, Default value: 7 -; -; Configures which logging messages should be added to the log file. -; -; The log file is configured with the xdebug.log setting. -; -; The following levels are supported: -; -; ===== ============= ================================ -; Level Name Example -; ===== ============= ================================ -; 0 Criticals Errors in the configuration -; ----- ------------- -------------------------------- -; 1 Errors Connection errors -; ----- ------------- -------------------------------- -; 3 Warnings Connection warnings -; ----- ------------- -------------------------------- -; 5 Communication Protocol messages -; ----- ------------- -------------------------------- -; **7** Information Information while connecting -; ----- ------------- -------------------------------- -; 10 Debug Breakpoint resolving information -; ===== ============= ================================ -; -; Criticals, errors, and warnings always show up in the diagnostics log that you -; can view by calling xdebug_info(). -; -; Criticals and errors are additionally logged through PHP's internal logging -; mechanism (configured with error_log 1 in ``php.ini``). -; -; 1 https://www.php.net/manual/en/errorfunc.configuration.php#ini.error-log -; -; .. note:: -; -; This setting can additionally be configured through the -; ``XDEBUG_CONFIG``environment variable 1. 1 -; /docs/all_settings#XDEBUG_CONFIG -; -; -;xdebug.log_level = 7 - -; ----------------------------------------------------------------------------- -; xdebug.max_nesting_level -; -; Type: integer, Default value: 256 -; -; Controls the protection mechanism for infinite recursion protection. The value -; of this setting is the maximum level of nested functions that are allowed -; before the script will be aborted. -; -; When the maximum nesting level is reached, an "Error 1" exception is thrown. -; -; 1 https://www.php.net/manual/class.error.php -; -; -;xdebug.max_nesting_level = 256 - -; ----------------------------------------------------------------------------- -; xdebug.max_stack_frames -; -; Type: integer, Default value: -1 -; -; Controls how many stack frames are shown in stack traces, both on the command -; line during PHP error stack traces, as well as in the browser for HTML traces. -; -; -;xdebug.max_stack_frames = -1 - -; ----------------------------------------------------------------------------- -; xdebug.mode -; -; Type: string, Default value: develop -; -; This setting controls which Xdebug features are enabled. -; -; .. note:: -; -; This setting can only be set in ``php.ini`` or files like ``99-xdebug.ini`` -; that are read when a PHP process starts (directly, or through php-fpm), but -; not in ``.htaccess`` and ``.user.ini`` files, which are read per-request. -; -; The following values are accepted: -; -; off -; Nothing is enabled. Xdebug does no work besides checking whether -; functionality is enabled. Use this setting if you want close to 0 -; overhead. -; -; develop -; Enables Development Helpers including the overloaded var_dump(). -; -; coverage -; Enables Code Coverage Analysis to generate code coverage reports, mainly -; in combination with -; -; PHPUnit 1. -; -; debug -; Enables Step Debugging. This can be used to step through your code while -; it is running, and analyse values of variables. -; -; gcstats -; Enables Garbage Collection Statistics to collect statistics about PHP's -; Garbage Collection Mechanism. -; -; profile -; Enables Profiling, with which you can analyse performance bottlenecks with -; tools like -; -; KCacheGrind 2. -; -; trace -; Enables the Function Trace feature, which allows you record every function -; call, including arguments, variable assignment, and return value that is -; made during a request to a file. -; -; You can enable multiple modes at the same time by comma separating their -; identifiers as value to xdebug.mode: ``xdebug.mode=develop,trace``. -; -; 1 https://phpunit.readthedocs.io/en/9.0/code-coverage-analysis.html -; 2 /docs/profiler#kcachegrind -; -; -------------------------------- -; XDEBUG_MODE environment variable -; -------------------------------- -; -; You can also set Xdebug's mode by setting the ``XDEBUG_MODE`` environment -; variable on the command-line; this will take precedence over the xdebug.mode -; setting, but will not change the value of the xdebug.mode setting. -; -; .. warning:: -; -; Some web servers have a configuration option to prevent environment -; variables from being propagated to PHP and Xdebug. For example, PHP-FPM has -; a ``clear_env`` 1 configuration setting that is ``on`` by default, which -; you will need to turn ``off`` if you want to use ``XDEBUG_MODE``. Make sure -; that your web server does not clean the environment, or specifically allows -; the ``XDEBUG_MODE`` environment variable to be passed on. 1 -; https://www.php.net/manual/en/install.fpm.configuration.php#clear-env -; -; -;xdebug.mode = develop - -; ----------------------------------------------------------------------------- -; xdebug.output_dir -; -; Type: string, Default value: /tmp -; -; The directory where Xdebug will write tracing, profiling, and garbage -; collection statistics to. This directory needs to be writable for the system -; user with which PHP is running. -; -; This setting can be changed in ``php.ini``, ``.htaccess`` (and equivalent -; files), and within a PHP file with ``ini_set()``. -; -; In some cases (when profiling, or when xdebug.start_with_request= ``yes`` with -; tracing), Xdebug creates the file before the script runs. In that case, -; changes made through ``ini_set()`` will not be taken into account. -; -; .. note:: -; -; This setting can additionally be configured through the -; ``XDEBUG_CONFIG``environment variable 1. 1 -; /docs/all_settings#XDEBUG_CONFIG -; -; -;xdebug.output_dir = /tmp - -; ----------------------------------------------------------------------------- -; xdebug.profiler_append -; -; Type: integer, Default value: 0 -; -; When this setting is set to 1, profiler files will not be overwritten when a -; new request would map to the same file (depending on the -; xdebug.profiler_output_name setting. Instead the file will be appended to with -; the new profile. -; -; -;xdebug.profiler_append = 0 - -; ----------------------------------------------------------------------------- -; xdebug.profiler_output_name -; -; Type: string, Default value: cachegrind.out.%p -; -; This setting determines the name of the file that is used to dump traces into. -; The setting specifies the format with format specifiers, very similar to -; sprintf() and strftime(). There are several format specifiers that can be used -; to format the file name. -; -; See the xdebug.trace_output_name documentation for the supported specifiers. -; -; .. note:: -; -; This setting can additionally be configured through the -; ``XDEBUG_CONFIG``environment variable 1. 1 -; /docs/all_settings#XDEBUG_CONFIG -; -; -;xdebug.profiler_output_name = cachegrind.out.%p - -; ----------------------------------------------------------------------------- -; xdebug.scream -; -; Type: boolean, Default value: false -; -; If this setting is 1, then Xdebug will disable the @ (shut-up) operator so -; that notices, warnings and errors are no longer hidden. -; -; -;xdebug.scream = false - -; ----------------------------------------------------------------------------- -; xdebug.show_error_trace -; -; Type: integer, Default value: 0 -; -; When this setting is set to 1, Xdebug will show a stack trace whenever an -; Error is raised - even if this Error is actually caught. -; -; -;xdebug.show_error_trace = 0 - -; ----------------------------------------------------------------------------- -; xdebug.show_exception_trace -; -; Type: integer, Default value: 0 -; -; When this setting is set to 1, Xdebug will show a stack trace whenever an -; Exception or Error is raised - even if this Exception or Error is actually -; caught. -; -; Error 'exceptions' were introduced in PHP 7. -; -; -;xdebug.show_exception_trace = 0 - -; ----------------------------------------------------------------------------- -; xdebug.show_local_vars -; -; Type: integer, Default value: 0 -; -; When this setting is set to something != 0 Xdebug's generated stack dumps in -; error situations will also show all variables in the top-most scope. Beware -; that this might generate a lot of information, and is therefore turned off by -; default. -; -; -;xdebug.show_local_vars = 0 - -; ----------------------------------------------------------------------------- -; xdebug.start_upon_error -; -; Type: string, Default value: default -; -; Step Debugging can be activated when a PHP Notice or Warning is emitted, or -; when a Throwable 1 (Exception/Error) is thrown, depending on the value of -; this setting: -; -; 1 https://www.php.net/manual/en/class.throwable.php -; -; yes -; Initialise a debugging session when a PHP Notice or Warning is emitted, or -; when a Throwable is thrown. -; -; no -; default -; Do not start a debugging session upon an error situation. -; -; -;xdebug.start_upon_error = default - -; ----------------------------------------------------------------------------- -; xdebug.start_with_request -; -; Type: string, Default value: default -; -; A Function Trace, Garbage Collection Statistics, Profiling, or Step Debugging -; can be activated at the start of a PHP request. Whether this happens depends -; on the value of this setting: -; -; yes -; The functionality starts when the PHP request starts, and before any PHP -; code is run. -; -; For example xdebug.mode= ``trace`` and xdebug.start_with_request= ``yes`` -; starts a Function Trace for the whole request. -; -; no -; The functionality does not get activated when the request starts. -; -; You can still start a Function Trace with xdebug_start_trace(), Step -; Debugging with xdebug_break(), or Garbage Collection Statistics with -; xdebug_start_gcstats(). -; -; trigger -; The functionality only gets activated when a specific trigger is present -; when the request starts. -; -; The name of the trigger is ``XDEBUG_TRIGGER``, and Xdebug checks for its -; presence in either ``$_ENV`` (environment variable), ``$_GET`` or -; ``$_POST`` variable, or ``$_COOKIE`` (HTTP cookie name). -; -; There is a legacy fallback to a functionality specific trigger name: -; ``XDEBUG_PROFILE`` (for Profiling), ``XDEBUG_TRACE`` (for a Function -; Trace), and ``XDEBUG_SESSION`` (for Step Debugging). -; -; There is another legacy trigger. If you set the ``XDEBUG_CONFIG`` -; environment variable to any value, then Xdebug will also get activated. -; -; Debug session management for Step Debugging is also available through -; ``XDEBUG_SESSION_START``. -; -; With xdebug.trigger_value you can control which specific trigger value -; will activate the trigger. If xdebug.trigger_value is set to an empty -; string, **any** value will be accepted. -; -; default -; The ``default`` value depends on xdebug.mode: -; -; - **debug** : ``trigger`` -; -; - **gcstats** : ``no`` -; -; - **profile** : ``yes`` -; -; - **trace** : ``trigger`` -; -; -;xdebug.start_with_request = default - -; ----------------------------------------------------------------------------- -; xdebug.trace_format -; -; Type: integer, Default value: 0 -; -; The format of the trace file. -; -; ===== ============================================================================== -; Value Description -; ===== ============================================================================== -; 0 shows a human readable indented trace file with: -; -; *time index*, *memory usage*, *memory delta*, *level*, *function name*, -; *function parameters*, *filename* and *line number*. -; ----- ------------------------------------------------------------------------------ -; 1 writes a computer readable format which has two different records. There are -; different records for entering a stack frame, and leaving a stack frame. The -; table below lists the fields in each type of record. Fields are tab separated. -; ----- ------------------------------------------------------------------------------ -; 2 writes a trace formatted in (simple) HTML. -; ===== ============================================================================== -; -; Fields for the computerized format: -; -; =========== ===== ========== ========== ========== ============ ============= ========================================= =================================== ======== =========== ================ ============================================================ -; Record type 1 2 3 4 5 6 7 8 9 10 11 12 - ... -; =========== ===== ========== ========== ========== ============ ============= ========================================= =================================== ======== =========== ================ ============================================================ -; Entry level function # always '0' time index memory usage function name user-defined (1) or internal function (0) name of the include or require file filename line number no. of arguments arguments (as many as specified in field 11) - tab separated -; ----------- ----- ---------- ---------- ---------- ------------ ------------- ----------------------------------------- ----------------------------------- -------- ----------- ---------------- ------------------------------------------------------------ -; Exit level function # always '1' time index memory usage empty -; ----------- ----- ---------- ---------- ---------- ------------ ------------- ----------------------------------------- ----------------------------------- -------- ----------- ---------------- ------------------------------------------------------------ -; Return level function # always 'R' empty return value empty -; =========== ===== ========== ========== ========== ============ ============= ========================================= =================================== ======== =========== ================ ============================================================ -; -; See the introduction for Function Trace for a few examples. -; -; -;xdebug.trace_format = 0 - -; ----------------------------------------------------------------------------- -; xdebug.trace_options -; -; Type: integer, Default value: 0 -; -; When set to '1' the trace files will be appended to, instead of being -; overwritten in subsequent requests. -; -; -;xdebug.trace_options = 0 - -; ----------------------------------------------------------------------------- -; xdebug.trace_output_name -; -; Type: string, Default value: trace.%c -; -; This setting determines the name of the file that is used to dump traces into. -; The setting specifies the format with format specifiers, very similar to -; sprintf() and strftime(). There are several format specifiers that can be used -; to format the file name. The '.xt' extension is always added automatically. -; -; The possible format specifiers are: -; -; ========= ====================================== ================= ==================================================== -; Specifier Meaning Example Format Example Filename -; ========= ====================================== ================= ==================================================== -; %c crc32 of the current working directory trace.%c trace.1258863198.xt -; --------- -------------------------------------- ----------------- ---------------------------------------------------- -; %p pid trace.%p trace.5174.xt -; --------- -------------------------------------- ----------------- ---------------------------------------------------- -; %r random number trace.%r trace.072db0.xt -; --------- -------------------------------------- ----------------- ---------------------------------------------------- -; %s script name 2 cachegrind.out.%s cachegrind.out._home_httpd_html_test_xdebug_test_php -; --------- -------------------------------------- ----------------- ---------------------------------------------------- -; %t timestamp (seconds) trace.%t trace.1179434742.xt -; --------- -------------------------------------- ----------------- ---------------------------------------------------- -; %u timestamp (microseconds) trace.%u trace.1179434749_642382.xt -; --------- -------------------------------------- ----------------- ---------------------------------------------------- -; %H $_SERVER'HTTP_HOST' trace.%H trace.kossu.xt -; --------- -------------------------------------- ----------------- ---------------------------------------------------- -; %R $_SERVER'REQUEST_URI' trace.%R trace._test_xdebug_test_php_var=1_var2=2.xt -; --------- -------------------------------------- ----------------- ---------------------------------------------------- -; %U $_SERVER'UNIQUE_ID' trace.%U trace.TRX4n38AAAEAAB9gBFkAAAAB.xt -; -; 3 -; --------- -------------------------------------- ----------------- ---------------------------------------------------- -; %S session_id (from $_COOKIE if set) trace.%S trace.c70c1ec2375af58f74b390bbdd2a679d.xt -; --------- -------------------------------------- ----------------- ---------------------------------------------------- -; %% literal % trace.%% trace.%%.xt -; ========= ====================================== ================= ==================================================== -; -; 2 This one is only available for trace file names since Xdebug 2.6. -; -; 3 New in version 2.2. This one is set by Apache's mod_unique_id module 1 -; -; 1 http://httpd.apache.org/docs/current/mod/mod_unique_id.html -; -; -;xdebug.trace_output_name = trace.%c - -; ----------------------------------------------------------------------------- -; xdebug.trigger_value -; -; Type: string, Default value: "" -; -; This setting can be used when xdebug.start_with_request is set to ``trigger``, -; which is the default for Step Debugging and Function Trace. -; -; In ``trigger`` mode, Xdebug will only start its functionality when the -; ``XDEBUG_TRIGGER`` is set in the environment, or when the ``XDEBUG_TRIGGER`` -; GET, POST, or COOKIE variable is set. -; -; The legacy names ``XDEBUG_SESSION`` (for Step Debugging), ``XDEBUG_PROFILE`` -; (for Profiling), and ``XDEBUG_TRACE`` (for Function Trace) can also be used -; instead of ``XDEBUG_TRIGGER``. -; -; Normally, Xdebug does not look at which value is actually used. If this -; setting is set to a non-empty string, then Xdebug will only trigger if the -; value matches the value of this setting. -; -; With the following settings: -; -; xdebug.mode=profile -; xdebug.start_with_request=trigger -; xdebug.trigger_value=StartProfileForMe -; -; Xdebug's profiler will only start when either the environment variable -; ``XDEBUG_TRIGGER`` is set to ``StartProfileForMe``, the GET or POST variable -; ``XDEBUG_TRIGGER`` is set to ``StartProfileForMe``, or when the cookie -; ``XDEBUG_TRIGGER`` has the value ``StartProfileForMe``. -; -; From Xdebug 3.1, it is possible to configure multiple values by using a comma -; separated list. In that case, Xdebug will trigger if the supplied value -; matches any of the entries that are configured through this setting: -; -; xdebug.trigger_value=StartDebuggerForMe,StartDebuggerForYou -; -; See also: -; -; xdebug.start_with_request#trigger -; For how the triggering mechanism works, and which environment and server -; variables Xdebug acts on. -; -; -;xdebug.trigger_value = "" - -; ----------------------------------------------------------------------------- -; xdebug.use_compression -; -; Introduced in version 3.1 -; -; Type: boolean, Default value: true -; -; If enabled, the Function Trace and Profiling features will create GZip -; compressed files as output. This reduces diskspace. -; -; If GZip compression is not supported by Xdebug, because it was not compiled -; in, then Xdebug will add a warning to its log and xdebug_info() diagnostics -; section. -; -; It is enabled by default if Xdebug has GZip support, and disable if Xdebug -; does not have GZip support. -; -; The QCacheGrind tool that you can use to visualise profiling information does -; not support reading GZip compressed profile files, whereas KCacheGrind and -; PhpStorm do. If you are a QCacheGrind user, you should set -; xdebug.use_compression to ``false``. -; -; -;xdebug.use_compression = true - -; ----------------------------------------------------------------------------- -; xdebug.var_display_max_children -; -; Type: integer, Default value: 128 -; -; Controls the amount of array children and object's properties are shown when -; variables are displayed with either xdebug_var_dump(), xdebug.show_local_vars -; or when making a Function Trace. -; -; To disable any limitation, use *-1* as value. -; -; This setting does not have any influence on the number of children that is -; send to the client through the Step Debugging feature. -; -; -;xdebug.var_display_max_children = 128 - -; ----------------------------------------------------------------------------- -; xdebug.var_display_max_data -; -; Type: integer, Default value: 512 -; -; Controls the maximum string length that is shown when variables are displayed -; with either xdebug_var_dump(), xdebug.show_local_vars or when making a -; Function Trace. -; -; To disable any limitation, use *-1* as value. -; -; This setting does not have any influence on the number of children that is -; send to the client through the Step Debugging feature. -; -; -;xdebug.var_display_max_data = 512 - -; ----------------------------------------------------------------------------- -; xdebug.var_display_max_depth -; -; Type: integer, Default value: 3 -; -; Controls how many nested levels of array elements and object properties are -; when variables are displayed with either xdebug_var_dump(), -; xdebug.show_local_vars or when making a Function Trace. -; -; The maximum value you can select is *1023*. You can also use *-1* as value to -; select this maximum number. -; -; This setting does not have any influence on the number of children that is -; send to the client through the Step Debugging feature. -; -; .. warning:: -; -; Setting the value to a high number could potentially result in PHP using up -; all the available memory, so use with caution. -; -; -;xdebug.var_display_max_depth = 3 -
View file
xdebug-3.1.5.tgz/package.xml -> xdebug-3.2.0.tgz/package.xml
Changed
@@ -32,11 +32,11 @@ <email>derick@xdebug.org</email> <active>yes</active> </lead> - <date>2022-06-06</date> - <time>15:31:19</time> + <date>2022-12-08</date> + <time>19:00:12</time> <version> - <release>3.1.5</release> - <api>3.1.5</api> + <release>3.2.0</release> + <api>3.2.0</api> </version> <stability> <release>stable</release> @@ -44,15 +44,49 @@ </stability> <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD style</license> <notes> -Mon, Jun 06, 2022 - Xdebug 3.1.5 +Thu, Dec 08, 2022 - Xdebug 3.2.0 + ++ New features: + + - Fixed issue #1819: Allow a list of headers in 'xdebug.client_discovery_header' + - Fixed issue #2079: Add pseudo hosts xdebug://gateway and xdebug://nameserver + - Fixed issue #2086: Include return value in return breakpoint interruption response + - Fixed issue #2087: Introduce step for the return state and virtual property for return value + ++ Improvements: + + - Fixed issue #2062: Xdebug now records whether systemd's PrivateTmp is used in its diagnostics information + - Fixed issue #2104: Add support for PHP 8.2 "SensitiveParameter" attribute + - Fixed issue #2117: Removed emulated properties for closures, as PHP 8.2 adds debug information for them + - Fixed issue #2122: Local variables are now available when using start_upon_error + - Fixed issue #2123: Add warning in log and diagnositics information when a breakpoint is set on a non-existing file + - Fixed issue #2138: Step debugger now disconnects and continues running the script, when the debugging client closes the connection + - Fixed issue #2136: Duplicate line/conditional breakpoints are now rejected + +- Deprecations: + + - Fixed issue #2014: Drop support for PHP 7.2 + - Fixed issue #2102: Drop support for PHP 7.3 + - Fixed issue #2103: Drop support for PHP 7.4 = Fixed bugs: - - Fixed issue #2056: Install documentation gives wrong arch for installation on M1 Macs - - Fixed issue #2082: phpize --clean removes required clocks.m4 file - - Fixed issue #2083: Constant defined with an enum case produce double "facet" attribute in context_get response - - Fixed issue #2085: Crash when used with source guardian encoded files - - Fixed issue #2090: Segfault in __callStatic() after FFI initialization + - Fixed issue #2002: xdebug_trace_handler_t handler members are not always checked for NULL when executing + - Fixed issue #2045: Inapproriate frowny face + - Fixed issue #2089: Alpine Linux does not support res_ninit + - Fixed issue #2093: Fatal error: linux/rtnetlink.h: No such file or directory linux/rtnetlink.h + - Fixed issue #2098: With breakpoint_include_return_value enabled step_out break at every function + - Fixed issue #2105: 3.2.0alpha1 package misses the php-header.h file + - Fixed issue #2108: Segfault on PHP8.1 with PHPUnit 10 when path coverage is enabled + - Fixed issue #2113: Crash at step_into after thrown exception with return value debugging en + - Fixed issue #2121: Xdebug does not use local independent float-to-string functions + - Fixed issue #2124: Xdebug incorrectly reports that there are no children for static closure properties, even though there are + - Fixed issue #2125: Crash with PHP 8.2 on 32-bit due to change in "not set" value with CATCH opcode + - Fixed issue #2126: Problems with retrieving global variables + - Fixed issue #2127: Tracing does not handle NUL char in anonymous closure scope + - Fixed issue #2133: Warning with regards to extra NUL character in xdebug_setcookie call + - Fixed issue #2134: Xdebug stops at the line where the exception is created, not where it is thrown + - Fixed issue #2135: Xdebug stops twice at the same line after a call breakpoint or xdebug_break() </notes> <contents> <dir name="/"> @@ -60,109 +94,112 @@ <file md5sum="ed01d7b0936a39822cd5c9144852e1b9" name="contrib/xt.vim" role="doc" /> <file md5sum="372197f5b791b837269177402b31688c" name="m4/clocks.m4" role="src" /> <file md5sum="c55adfb3a3094c8029687ae1f7a46120" name="m4/pkg.m4" role="src" /> - <file md5sum="1a8a24cdabd1ed24acc3d6fbe9fe6a6f" name="src/base/base.c" role="src" /> + <file md5sum="6c582d721f4e657a0a1f09eadb05d3c1" name="src/base/base.c" role="src" /> <file md5sum="7db372db630677292df705a90c07e21c" name="src/base/base.h" role="src" /> - <file md5sum="4bc56e4bf66e6105ba31458fa3219ae9" name="src/base/base_globals.h" role="src" /> + <file md5sum="544be6135ec5b70de44b2205cebc7800" name="src/base/base_globals.h" role="src" /> <file md5sum="baf483b8b3f68c10d0c3f8863accf0c3" name="src/base/base_private.h" role="src" /> <file md5sum="d0e04b38a411646d145e3a62afccdd7d" name="src/base/filter.c" role="src" /> - <file md5sum="cfcba73b7c5a588bcfd7d69d0a08e772" name="src/base/filter.h" role="src" /> - <file md5sum="5bd6e0617b2e3e22a8e9b23ef3ad0fdf" name="src/lib/usefulstuff.c" role="src" /> + <file md5sum="dc9f79b67b940c0ca6676008b94f0c91" name="src/base/filter.h" role="src" /> + <file md5sum="7dbafec36b9ad06617acbf281c7236e9" name="src/lib/usefulstuff.c" role="src" /> <file md5sum="36f17d040407ee39a71c74b30e88f8b1" name="src/lib/usefulstuff.h" role="src" /> - <file md5sum="a2685b4fd650d89696762f191f60da7a" name="src/lib/compat.c" role="src" /> - <file md5sum="4655f7167b6a47eecdaf114df5f0746d" name="src/lib/compat.h" role="src" /> + <file md5sum="67b36ef33accd5b98ccbc1c1cd7ad9e4" name="src/lib/compat.c" role="src" /> + <file md5sum="420d62640093693d4cee3e0812e7a370" name="src/lib/compat.h" role="src" /> <file md5sum="5ded1e8050a567ddf31f15ccf8fc92d8" name="src/lib/crc32.c" role="src" /> <file md5sum="8e3d5ef843f03afab4cb27c4944d204f" name="src/lib/crc32.h" role="src" /> - <file md5sum="e8057c7e7294ee6ef1d5f636b64b7aec" name="src/lib/file.c" role="src" /> + <file md5sum="825fb123306f9531faa11e83fbaa0a9e" name="src/lib/file.c" role="src" /> <file md5sum="5c262995cdd25eb6b65a1fb76eedfd11" name="src/lib/file.h" role="src" /> <file md5sum="53ae56622dd00dccdbffc92c938fe5a0" name="src/lib/hash.c" role="src" /> <file md5sum="77bef9854199eb280ecbd97a83737648" name="src/lib/hash.h" role="src" /> <file md5sum="b95fb17e72285dd3c99ddd49356cbf80" name="src/lib/headers.c" role="src" /> <file md5sum="b05e34ecc50ab77d02933c583d88551b" name="src/lib/headers.h" role="src" /> - <file md5sum="bbcf90ab960a334d793fc16319895ba2" name="src/lib/lib.c" role="src" /> - <file md5sum="d0a89ae948e09c49592e0ce4bcaa33ad" name="src/lib/lib.h" role="src" /> - <file md5sum="a9d381a26a166fd8a7c6eb6aabb148f0" name="src/lib/log.c" role="src" /> + <file md5sum="d2b67839261cc354974d87d97c1631bb" name="src/lib/lib.c" role="src" /> + <file md5sum="8097bdd8d55f54204939bf7e4e7a7717" name="src/lib/lib.h" role="src" /> + <file md5sum="6c32e7d1b37168e7719f0e7e3e063aef" name="src/lib/log.c" role="src" /> <file md5sum="2ded0176decc29f511215987461419ff" name="src/lib/log.h" role="src" /> <file md5sum="8026528d3daa7d18021442eddbf60176" name="src/lib/lib_private.h" role="src" /> <file md5sum="88171fff82c5233a96d05341e0fcdcf9" name="src/lib/llist.c" role="src" /> <file md5sum="833b8b23d247ee19d10a58a0e9159174" name="src/lib/llist.h" role="src" /> <file md5sum="78eb2398cc1a535be67632e0de82b727" name="src/lib/mm.h" role="src" /> + <file md5sum="39d07a6b4e982c8d5787e188a93c8af9" name="src/lib/php-header.h" role="src" /> <file md5sum="7ad345e09f5c1768900ce690e5efd770" name="src/lib/set.c" role="src" /> <file md5sum="dc03fc37187e29189e906e577d5b9c4c" name="src/lib/set.h" role="src" /> - <file md5sum="51ae57e6480f0c40aa90f387b5b1ec97" name="src/lib/str.c" role="src" /> - <file md5sum="de7ed2c4e5f8f10fd684b607660a32e5" name="src/lib/str.h" role="src" /> + <file md5sum="3290e703fe7174012b5a45b423e3ca08" name="src/lib/str.c" role="src" /> + <file md5sum="34d98f97b0e5a32a459a083bae66edfb" name="src/lib/str.h" role="src" /> <file md5sum="326ce360a40b63e768992aee68fe0c9d" name="src/lib/timing.c" role="src" /> <file md5sum="637e3b5e753e6afc8b014b02cec7b0ec" name="src/lib/timing.h" role="src" /> - <file md5sum="bc75652efedfe10995279f11a0c7552d" name="src/lib/var.c" role="src" /> - <file md5sum="6e7077d2c6982e333d258e9609788cf3" name="src/lib/var.h" role="src" /> - <file md5sum="dd87a632c0d1c6fc0e7a34c6163fb60a" name="src/lib/var_export_html.c" role="src" /> + <file md5sum="01338932374d0f6accbc56a25a42d3b9" name="src/lib/var.c" role="src" /> + <file md5sum="61574c585b50325415382f8e47af452b" name="src/lib/var.h" role="src" /> + <file md5sum="3ac8a9c3b8944c944a36c0efc9031d6b" name="src/lib/var_export_html.c" role="src" /> <file md5sum="ab2c1ac724a54c2b50946c7746ee135c" name="src/lib/var_export_html.h" role="src" /> - <file md5sum="1d563e00283a2c504c5da7fc5fbc725e" name="src/lib/var_export_line.c" role="src" /> + <file md5sum="c27cbf3693dab0150eafa2875f76c99e" name="src/lib/var_export_line.c" role="src" /> <file md5sum="a865240b02e1f698ce57098f01693399" name="src/lib/var_export_line.h" role="src" /> - <file md5sum="15cab0d1d149690bf2c6affb5a8075fc" name="src/lib/var_export_text.c" role="src" /> + <file md5sum="1cb41799cc78d5bd3d6c8c8c8abc9ee8" name="src/lib/var_export_text.c" role="src" /> <file md5sum="ce4f91762755006f5df6353465e9927b" name="src/lib/var_export_text.h" role="src" /> - <file md5sum="55bc76df1f68409819d74aacc955d774" name="src/lib/var_export_xml.c" role="src" /> + <file md5sum="a6517026d9ce5216ba38455af26652d0" name="src/lib/var_export_xml.c" role="src" /> <file md5sum="dc4f5766d9ebe581d6de6319fcc966ab" name="src/lib/var_export_xml.h" role="src" /> <file md5sum="8d1a4cb863697a98bf063b6a4ab79050" name="src/lib/vector.h" role="src" /> <file md5sum="a637b4abdfcc5a1a74ea7fcb94ebf0db" name="src/lib/xml.c" role="src" /> <file md5sum="bf00317cca78941bc659bf15b07fe385" name="src/lib/xml.h" role="src" /> - <file md5sum="92d72ed5ef9a4dd4317f92bd04582572" name="src/coverage/branch_info.c" role="src" /> + <file md5sum="3bf888cd6a2d69da7738f278cb108561" name="src/coverage/branch_info.c" role="src" /> <file md5sum="963e2650561b374f99943254bda93688" name="src/coverage/branch_info.h" role="src" /> - <file md5sum="9bab949f6e0f2dd55002414104af0ecd" name="src/coverage/code_coverage.c" role="src" /> + <file md5sum="2af00c0a4b80185d245f6f956b64bca9" name="src/coverage/code_coverage.c" role="src" /> <file md5sum="c7c6c4688b7654d2a481e64a519596a3" name="src/coverage/code_coverage.h" role="src" /> - <file md5sum="8a73ee60f8eba6df2712da9085d419f9" name="src/coverage/code_coverage_private.h" role="src" /> - <file md5sum="9c7381bbe83085c5e2e78ba5ea15136a" name="src/develop/develop.c" role="src" /> - <file md5sum="6b059569e6b7c4ba3c46aea147ff9126" name="src/develop/develop.h" role="src" /> + <file md5sum="b0a609f56e0d13cf7f6c915af1774512" name="src/coverage/code_coverage_private.h" role="src" /> + <file md5sum="14b822a1660aecc8ef04dbf08dabd2a6" name="src/develop/develop.c" role="src" /> + <file md5sum="49cda41235b9d8c88a7b1f927f05a11a" name="src/develop/develop.h" role="src" /> <file md5sum="8bc34c16b460129c99c0a43ef3db87e4" name="src/develop/develop_private.h" role="src" /> - <file md5sum="75d302506fc6c1aabcbc501b7d6c0c2a" name="src/develop/monitor.c" role="src" /> + <file md5sum="796baf06ff0a1440b5aa75df129cb4c4" name="src/develop/monitor.c" role="src" /> <file md5sum="e29f144cd504ee14ebddee4f8ab5b714" name="src/develop/monitor.h" role="src" /> - <file md5sum="a6a76454d90efdb6106c8e76a035e9e0" name="src/develop/php_functions.c" role="src" /> - <file md5sum="85803cddf8cc9ef72a733b723baf4451" name="src/develop/stack.c" role="src" /> - <file md5sum="59ef2237151c3bf77c1493b65c7d1111" name="src/develop/stack.h" role="src" /> - <file md5sum="e784721dd6938c070fe209f9032d2636" name="src/develop/superglobals.c" role="src" /> - <file md5sum="de5e6312abee7eea0ac07bcb4920f704" name="src/develop/superglobals.h" role="src" /> - <file md5sum="dcc45764527a9b4e1551ee8df613e267" name="src/debugger/com.c" role="src" /> - <file md5sum="64d7afd2dfda444cb74382106f9edb3c" name="src/debugger/com.h" role="src" /> - <file md5sum="9da9f6e6100e3847a64569895f452b27" name="src/debugger/debugger.c" role="src" /> - <file md5sum="82013c30b962631a67d3c37f2b221e3e" name="src/debugger/debugger.h" role="src" /> + <file md5sum="a09242412a0af4c90f89f7114dab7028" name="src/develop/php_functions.c" role="src" /> + <file md5sum="ae4598e490b263fd096e29f91268de1b" name="src/develop/stack.c" role="src" /> + <file md5sum="8befdeb139efc9a471dc9a3277ca771c" name="src/develop/stack.h" role="src" /> + <file md5sum="a27d21b79bdf5acbe4725c7eeb8b1fb7" name="src/develop/superglobals.c" role="src" /> + <file md5sum="3a2f095163c396e8945274b6d4595eaf" name="src/develop/superglobals.h" role="src" /> + <file md5sum="481e1743d9d1f4fc0ac1dc66c3fedf34" name="src/debugger/com.c" role="src" /> + <file md5sum="1f5b38bf32e1d1afc2f01f82763f49b2" name="src/debugger/com.h" role="src" /> + <file md5sum="70d94bc2f6219e0df2be859040ef390e" name="src/debugger/debugger.c" role="src" /> + <file md5sum="1339d4ae8b273afbef329b0f8b643ab5" name="src/debugger/debugger.h" role="src" /> <file md5sum="57dc7787f58e11c1b703b3c2e32808fe" name="src/debugger/debugger_private.h" role="src" /> <file md5sum="ebb7b99fc1253c60f3caf63bdba60e32" name="src/debugger/handlers.c" role="src" /> - <file md5sum="46940b69874be77442128d0c13df742a" name="src/debugger/handlers.h" role="src" /> - <file md5sum="54d3e6172afd733135269a031dd025f3" name="src/debugger/handler_dbgp.c" role="src" /> - <file md5sum="2512b85a30418041ec34f3717fc428a5" name="src/debugger/handler_dbgp.h" role="src" /> - <file md5sum="96c018face07ce06623f16e4fefd6c4c" name="src/gcstats/gc_stats.c" role="src" /> + <file md5sum="e185e51f69cc321c0df3e26c5249a98f" name="src/debugger/handlers.h" role="src" /> + <file md5sum="d6f7f24620e72248f5817ce574fb6e38" name="src/debugger/handler_dbgp.c" role="src" /> + <file md5sum="cc1c0092e242bc454c43162a7a86c695" name="src/debugger/handler_dbgp.h" role="src" /> + <file md5sum="9634f8f1bafdd4dad90adb588f22b1eb" name="src/debugger/ip_info.c" role="src" /> + <file md5sum="e9bb3affd46a34d2ef21a8a251a54599" name="src/debugger/ip_info.h" role="src" /> + <file md5sum="4cdb157d8b1fa26bc97a7f1abd41fd58" name="src/gcstats/gc_stats.c" role="src" /> <file md5sum="3bf056d2ba948c4db6ec0375225ace32" name="src/gcstats/gc_stats.h" role="src" /> <file md5sum="574739da937d570df6371efbbe4369fb" name="src/gcstats/gc_stats_private.h" role="src" /> - <file md5sum="bec6f424a59cd84b0f9f3c5b6db75693" name="src/profiler/profiler.c" role="src" /> - <file md5sum="9dad15fe395223bebdc646341803242a" name="src/profiler/profiler.h" role="src" /> + <file md5sum="66cfb83461dbba41093c05265d0957ff" name="src/profiler/profiler.c" role="src" /> + <file md5sum="96f3f967d882ca71daa2e4225660319e" name="src/profiler/profiler.h" role="src" /> <file md5sum="bed3b315bb5ac1e7ea43cc09897d3257" name="src/profiler/profiler_private.h" role="src" /> - <file md5sum="46e0deb2b8fd92a14a3f46b7a67d3f00" name="src/tracing/tracing.c" role="src" /> - <file md5sum="e5b4b45b1dfe1ea3b486b1e822ffa6ab" name="src/tracing/tracing.h" role="src" /> - <file md5sum="5d09da4c1a1b82e95553600a6348620e" name="src/tracing/tracing_private.h" role="src" /> - <file md5sum="41133071f7de7f8cbd3046eb4a02d03c" name="src/tracing/trace_textual.c" role="src" /> + <file md5sum="74e93aaa403799f6b9eb0ac457c32d12" name="src/tracing/tracing.c" role="src" /> + <file md5sum="1cad6b024160965fe79a8e7ac9b8eabb" name="src/tracing/tracing.h" role="src" /> + <file md5sum="f1319418b7165faac0ff1f1ce23467db" name="src/tracing/tracing_private.h" role="src" /> + <file md5sum="e513c3d6d69b1287c56eafd19249c939" name="src/tracing/trace_textual.c" role="src" /> <file md5sum="13b0dca161acbf3c2f80c0b110b134e8" name="src/tracing/trace_textual.h" role="src" /> - <file md5sum="01b597a9e411bdf892f04d9e02cf7637" name="src/tracing/trace_computerized.c" role="src" /> + <file md5sum="472f6849d0d31d1bf1e7cc85e2ce8eae" name="src/tracing/trace_computerized.c" role="src" /> <file md5sum="caf12732954476c16d0057cafee32451" name="src/tracing/trace_computerized.h" role="src" /> - <file md5sum="fa3bb1b9024a231a99c0a55aecacf7ea" name="src/tracing/trace_html.c" role="src" /> + <file md5sum="71502b397cd6af39d732d42e7f0b07fc" name="src/tracing/trace_html.c" role="src" /> <file md5sum="cb9721509e7356c52dd87d724c5b6ddc" name="src/tracing/trace_html.h" role="src" /> - <file md5sum="cfe3eb16db5d2ff168aa678cfc9c940a" name="config.m4" role="src" /> + <file md5sum="cca6e2df21e532cae882f6bed08392af" name="config.m4" role="src" /> <file md5sum="7bc1315e7ae78f0f512cdacfc4717112" name="config.w32" role="src" /> <file md5sum="8f9a93feba6ff23c4bc1bc2929babcc4" name="CREDITS" role="doc" /> <file md5sum="92d94a330d34ee6edc2638450736f119" name="LICENSE" role="doc" /> - <file md5sum="90ee2ad77c70828965d4d9b60fbbd1de" name="xdebug.ini" role="doc" /> + <file md5sum="44cd8e7d81b979e9210d3435cd36217b" name="xdebug.ini" role="doc" /> <file md5sum="82ad7174e13d1bb8c64835f8cefeb494" name="Makefile.frag" role="src" /> - <file md5sum="935f1fad118f9542b9f968e29f504de7" name="CONTRIBUTING.rst" role="doc" /> - <file md5sum="10e4e8f9ef7aa548bd000e265ebb0df0" name="README.rst" role="doc" /> - <file md5sum="8a50eb9f2f429d6632addc0cb62f40d1" name="run-xdebug-tests.php" role="src" /> - <file md5sum="53b9d4d3f7196d827cb63c704cbcc382" name="xdebug.c" role="src" /> - <file md5sum="6ce3929afe3b6d7f2fa8652188c7bfc4" name="php_xdebug.h" role="src" /> + <file md5sum="64abbe2be689c4cb55ca64bc1a1a0f5a" name="CONTRIBUTING.rst" role="doc" /> + <file md5sum="225ebff41647c56edec110dd491fce14" name="README.rst" role="doc" /> + <file md5sum="e65f24fefd613e74fe334232853295be" name="run-xdebug-tests.php" role="src" /> + <file md5sum="870420e3e59ebc6e6624d870dc47fa4a" name="xdebug.c" role="src" /> + <file md5sum="6a1af35d701e57b259908c79caf1c5ed" name="php_xdebug.h" role="src" /> <file md5sum="ada484ed09ba0ed095502d343714fce7" name="php_xdebug_arginfo.h" role="src" /> </dir> </contents> <dependencies> <required> <php> - <min>7.2.0</min> - <max>8.1.99</max> + <min>8.0.0</min> + <max>8.2.99</max> </php> <pearinstaller> <min>1.9.1</min> @@ -173,6 +210,188 @@ <zendextsrcrelease /> <changelog> <release> + <date>2022-11-10</date> + <time>09:56:57</time> + <version> + <release>3.2.0RC2</release> + <api>3.2.0RC2</api> + </version> + <stability> + <release>beta</release> + <api>beta</api> + </stability> + <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD style</license> + <notes> +Thu, Nov 10, 2022 - Xdebug 3.2.0RC2 + += Fixed bugs: + + - Fixed issue #2100: "Fatal error: debuginfo() must return an array" when Exception is thrown from debugInfo in PHP 8.x + - Fixed issue #2101: When a temporary breakpoint is hit, breakpoint_list should show it as disabled + - Fixed issue #2126: Problems with retrieving global variables + - Fixed issue #2127: Tracing does not handle NUL char in anonymous closure scope + - Fixed issue #2129: Cannot read snapshot Gzip-compressed data is corrupt + - Fixed issue #2133: Warning with regards to extra NUL character in xdebug_setcookie call + - Fixed issue #2134: Xdebug stops at the line where the exception is created, not where it is thrown + - Fixed issue #2135: Xdebug stops twice at the same line after a call breakpoint or xdebug_break() + - Fixed issue #2136: Duplicate line/conditional breakpoints are not rejected + </notes> + </release> + <release> + <date>2022-10-10</date> + <time>15:52:03</time> + <version> + <release>3.2.0RC1</release> + <api>3.2.0RC1</api> + </version> + <stability> + <release>beta</release> + <api>beta</api> + </stability> + <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD style</license> + <notes> +Mon, Oct 10, 2022 - Xdebug 3.2.0RC1 + += Fixed bugs: + + - Fixed issue #2113: Crash at step_into after thrown exception with return value debugging en + - Fixed issue #2117: Removed emulated properties for closures, as PHP 8.2 adds debug information for them + - Fixed issue #2121: Xdebug does not use local independent float-to-string functions + - Fixed issue #2122: Local variables are not available when using start_upon_error + - Fixed issue #2123: Add warning in log and diagnositics information when a breakpoint is set on a non-existing file + - Fixed issue #2124: Xdebug incorrectly reports that there are no children for static closure properties, even thought there are + - Fixed issue #2125: Crash with PHP 8.2 on 32-bit due to change in "not set" value with CATCH opcode + </notes> + </release> + <release> + <date>2022-08-24</date> + <time>09:21:42</time> + <version> + <release>3.2.0alpha3</release> + <api>3.2.0alpha3</api> + </version> + <stability> + <release>beta</release> + <api>beta</api> + </stability> + <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD style</license> + <notes> +Wed, Aug 24, 2022 - Xdebug 3.2.0alpha3 + ++ Improvements: + + - Fixed issue #2112: Force 'return_value' breakpoint information and step to 'on' temporarily + </notes> + </release> + <release> + <date>2022-07-25</date> + <time>10:07:50</time> + <version> + <release>3.2.0alpha2</release> + <api>3.2.0alpha2</api> + </version> + <stability> + <release>beta</release> + <api>beta</api> + </stability> + <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD style</license> + <notes> +Mon, Jul 25, 2022 - Xdebug 3.2.0alpha2 + += Fixed bugs: + + - Fixed issue #2105: 3.2.0alpha1 package misses the php-header.h file + </notes> + </release> + <release> + <date>2022-07-20</date> + <time>15:57:59</time> + <version> + <release>3.2.0alpha1</release> + <api>3.2.0alpha1</api> + </version> + <stability> + <release>beta</release> + <api>beta</api> + </stability> + <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD style</license> + <notes> +Wed, Jul 20, 2022 - Xdebug 3.2.0alpha1 + ++ New features: + + - Fixed issue #1819: Allow a list of headers in 'xdebug.client_discovery_header' + - Fixed issue #2079: Add pseudo hosts xdebug://gateway and xdebug://nameserver + - Fixed issue #2087: Introduce step for the return state and virtual property for return value + - Fixed issue #2104: Add support for PHP 8.2 "SensitiveParameter" attribute + ++ Improvements: + + - Fixed issue #2086: Include return value in return breakpoint interruption response + +- Removed features: + + - Fixed issue #2014: Drop support for PHP 7.2 + - Fixed issue #2102: Drop support for PHP 7.3 + - Fixed issue #2103: Drop support for PHP 7.4 + += Fixed bugs: + + - Fixed issue #2002: xdebug_trace_handler_t handler members are not always checked for NULL when executing + - Fixed issue #2045: Inapproriate frowny face + - Fixed issue #2062: Profiler can't able to write cachegrind file at /tmp + - Fixed issue #2089: Alpine Linux does not support res_ninit + - Fixed issue #2093: Fatal error: linux/rtnetlink.h: No such file or directory linux/rtnetlink.h + - Fixed issue #2098: With breakpoint_include_return_value enabled step_out break at every function + </notes> + </release> + <release> + <date>2022-11-08</date> + <time>13:08:25</time> + <version> + <release>3.1.6</release> + <api>3.1.6</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD style</license> + <notes> +Tue, Nov 08, 2022 - Xdebug 3.1.6 + += Fixed bugs: + + - Fixed issue #2100: "Fatal error: debuginfo() must return an array" when Exception is thrown from debugInfo in PHP 8.x + - Fixed issue #2101: When a temporary breakpoint is hit, breakpoint_list should show it as disabled + - Fixed issue #2129: Cannot read snapshot Gzip-compressed data is corrupt + </notes> + </release> + <release> + <date>2022-06-06</date> + <time>16:30:05</time> + <version> + <release>3.1.5</release> + <api>3.1.5</api> + </version> + <stability> + <release>stable</release> + <api>stable</api> + </stability> + <license uri="http://www.opensource.org/licenses/bsd-license.php">BSD style</license> + <notes> +Mon, Jun 06, 2022 - Xdebug 3.1.5 + += Fixed bugs: + + - Fixed issue #2056: Install documentation gives wrong arch for installation on M1 Macs + - Fixed issue #2082: phpize --clean removes required clocks.m4 file + - Fixed issue #2083: Constant defined with an enum case produce double "facet" attribute in context_get response + - Fixed issue #2085: Crash when used with source guardian encoded files + - Fixed issue #2090: Segfault in __callStatic() after FFI initialization + </notes> + </release> + <release> <date>2022-04-04</date> <time>11:33:07</time> <version> @@ -364,7 +583,7 @@ Sun, Sep 05, 2021 - Xdebug 3.1.0beta1 + New features: - + - Fixed issue #1738: Add xdebug_notify() function to send data through DBGp to a debugging client - Fixed issue #1853: Enable profile compression for cachegrind files - Fixed issue #1898: API for querying the currently active mode(s) @@ -404,7 +623,7 @@ - Fixed issue #2011: Closures as protected properties have double facet XML attribute + Documentation - + - Fixed issue #1537: Add links to documentation to various different "features" after wizard has run </notes> </release> @@ -2757,7 +2976,7 @@ + New settings: - xdebug.collect_assignments, which enables the emitting of variable assignments in function traces. - - xdebug.file_line_format, to generate a link with a specific format for + - xdebug.file_line_format, to generate a link with a specific format for every filename that Xdebug outputs. - xdebug.overload_var_dump, which allows you to turn off Xdebug's version of var_dump(). @@ -2984,7 +3203,7 @@ + Changes: - Improved code coverage performance dramatically. - PHP 5.3 compatibility (no namespaces yet though). - + = Fixed bugs: - Fixed bug #301: Loading would cause SIGBUS on Solaris 10 SPARC. (Patch by Sean Chalmers) @@ -3034,7 +3253,7 @@ - Fixed bug #280: var_dump() doesn't display key of array as expected. - Fixed bug #278: Code Coverage Issue. - Fixed bug #273: Remote debugging: context_get does not return context id. - - Fixed bug #270: Debugger aborts when PHP's eval() is encountered. + - Fixed bug #270: Debugger aborts when PHP's eval() is encountered. - Fixed bug #265: XDebug breaks error_get_last() . - Fixed bug #261: Code coverage issues by overloading zend_assign_dim. @@ -3343,11 +3562,11 @@ + Added new features: - Implemented FR #161: var_dump doesn't show lengths for strings. - Implemented FR #158: Function calls from the {main} scope always have the - line number 0. + line number 0. - Implemented FR #156: it's impossible to know the time taken by the last func call in xdebug trace mode 0. - Implemented FR #153: xdebug_get_declared_vars(). - + = Fixed bugs: - Fixed shutdown crash with ZTS on Win32 - Fixed bad memory leak when a E_ERROR of exceeding memory_limit was @@ -3437,11 +3656,11 @@ <notes> + Added new features: - DBGP: Added error messages to returned errors (in most cases) - + + Added new functions: - xdebug_debug_zval() to debug zvals by printing its refcounts and is_ref values. - + = Changed features: - xdebug_code_coverage_stop() will now clean up the code coverage array, unless you specify FALSE as parameter. @@ -3526,7 +3745,7 @@ - xdebug.extended_info: turns off the generation of extended opcodes that are needed for stepping and breakpoints for the remote debugger. This is useful incase you want to profile memory usage as the generation of this - extended info increases memory usage of oparrrays by about 33%. + extended info increases memory usage of oparrrays by about 33%. - xdebug.profiler_output_dir: profiler output directory. - xdebug.profiler_enable: enable the profiler. - xdebug.show_local_vars: turn off the showing of local variables in the @@ -3709,7 +3928,7 @@ + Additions to the remote debugger: "eval" (evaluate any PHP code from the debugger client). (Derick) + Added profiling support to xdebug. This introduces 3 new functions, - xdebug_start_profiling() that begins profiling process, + xdebug_start_profiling() that begins profiling process, xdebug_stop_profiling() that ends the profiling process and xdebug_dump_function_trace() that dumps the profiling data. (Ilia) + Implemented the "kill" (kills the running script) and "delete" (removes
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/CONTRIBUTING.rst
Added
@@ -0,0 +1,108 @@ +Contributing +============ + +Xdebug is hosted on Github. The source code can be browsed there and can be +checked out with:: + + git clone git://github.com/xdebug/xdebug.git + +If you think you want to fix a bug or work on a new feature, then you need to +follow the instructions below. Please reach out first to discuss your +suggested changes as well. + +Initial Set-up +-------------- + +- Fork Xdebug on GitHub. +- Make sure you have configured your Author Name and Author Email with GIT. + Xdebug doesn't accept contributions from accounts with unnatural names. +- Clone the repository:: + + git clone git@github.com:{your username}/xdebug.git + +- Change into the ``xdebug`` repository:: + + cd xdebug + +- Add the original repository as ``upstream`` remote:: + + git remote add upstream git://github.com/xdebug/xdebug.git + git fetch upstream + +- Add a tracking branch for Xdebug 3.1:: + + git checkout --track origin/xdebug_3_1 + +Branches +-------- + +There are two branches in operation: + +``master`` + This is were all new feature Pull Requests should be targeted at +``xdebug_3_1`` + This is were all bug fix Pull Requests should be targeted at. The + maintainer will add them to ``master`` too when merging the Pull Request. + +Working on a Pull Request +------------------------- + +- Make sure that your ``master`` and ``xdebug_3_1`` branches are up to date + with the ``upstream`` repository. +- Create an issue in the `issue tracker <https://bugs.xdebug.org>`_ (if none + exists yet). +- Switch to the right target branch (``master`` for features, ``xdebug_3_1`` + for bug fixes). +- Create a feature branch:: + + git checkout -b issue{issue number}-{description} + + For example:: + + git checkout -b issue1893-crash-with-fiber + +- For a bug fix, write one or more test cases to verify that the problem + currently exists, and also to define what the output should be. Xdebug uses + PHP's `phpt tests <https://qa.php.net/write-test.php>`_. The ``README.rst`` + file contains information on how to run the tests. + + Each of Xdebug's modes has a specific directory where to place tests. For + example, for code coverage that is ``tests/coverage``. Test case names + should follow the following pattern:: + + tests/{feature-group}bug0{issue-number}.phpt + + If you need more than one test, append ``-001`` after the issue number. + + Pull Requests without tests won't be accepted. + +- Fix and/or write the code. + +- Before you submit a PR, make sure each commit is a single logical unit. The + main commit that implements the issue, should have as commit message ``Fixed + issue #1893: `` followed by the Summary of the issue in the issue tracker. The + message should state what the change was about. For example:: + + Fixed issue #1893: Crash with ext-fiber with xdebug.mode=coverage + +- Before you submit a PR, make sure to rebase first on the branch that you + will be targeting, for example to rebase against the current bug fix + branch:: + + git fetch upstream && git rebase upstream/xdebug_3_1 + +- Push your changes to your remote repository:: + + git push origin {branch-name} + + For example:: + + git push origin issue1893-crash-with-fiber + +- Once you're satisfied, generate a pull request. Make sure that the title is + in one line, it's fine if it's a few characters larger than what GitHub + likes. Do not let the title spill over into the description with ``...```. + + In the description, explain what you changed, and why, and how your solution + is the right one. Feel free to include questions, and pointers to specific + things that need close review.
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/CREDITS
Changed
(renamed from xdebug-3.1.5/CREDITS)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/LICENSE
Changed
(renamed from xdebug-3.1.5/LICENSE)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/Makefile.frag
Changed
(renamed from xdebug-3.1.5/Makefile.frag)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/README.rst
Added
@@ -0,0 +1,149 @@ +Xdebug +====== + +.. image:: https://github.com/xdebug/xdebug/workflows/Build/badge.svg + :target: https://github.com/xdebug/xdebug/actions?query=workflow%3ABuild +.. image:: https://ci.appveyor.com/api/projects/status/glp9xfsmt1p25nkn?svg=true + :target: https://ci.appveyor.com/project/derickr/xdebug +.. image:: https://circleci.com/gh/xdebug/xdebug/tree/master.svg?style=svg + :target: https://circleci.com/gh/xdebug/xdebug + +.. image:: https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg + :target: https://stand-with-ukraine.pp.ua/ + +Xdebug is a debugging tool for PHP. It provides step-debugging and a whole +range of development helpers, such as stack traces, a code profiler, features to +dump the full execution of your script to a file, and more. + +|Repography logo| / Recent activity |Time period| +----- +|recent-activity_timeline| |recent-activity_prs| |recent-activity_words| |recent-activity_users| + +.. |Time period| image:: https://images.repography.com/0/xdebug/xdebug/recent-activity/ef1290ac5bfa674f07dcfa4f915ce6b3_badge.svg + :alt: Time period + :target: https://repography.com +.. |Repography logo| image:: https://images.repography.com/logo.svg + :alt: Repography logo + :target: https://repography.com +.. |recent-activity_timeline| image:: https://images.repography.com/0/xdebug/xdebug/recent-activity/ef1290ac5bfa674f07dcfa4f915ce6b3_timeline.svg + :alt: Timeline graph + :target: https://github.com/xdebug/xdebug/commits +.. |recent-activity_prs| image:: https://images.repography.com/0/xdebug/xdebug/recent-activity/ef1290ac5bfa674f07dcfa4f915ce6b3_prs.svg + :alt: Pull request status graph + :target: https://github.com/xdebug/xdebug/pulls +.. |recent-activity_words| image:: https://images.repography.com/0/xdebug/xdebug/recent-activity/ef1290ac5bfa674f07dcfa4f915ce6b3_words.svg + :alt: Trending topics + :target: https://github.com/xdebug/xdebug/commits +.. |recent-activity_users| image:: https://images.repography.com/0/xdebug/xdebug/recent-activity/ef1290ac5bfa674f07dcfa4f915ce6b3_users.svg + :alt: Top contributors + :target: https://github.com/xdebug/xdebug/graphs/contributors + +Requirements +------------ + +Xdebug requires a `supported version <https://www.php.net/supported-versions.php>`_ of PHP. For +installation it requires the `pecl` tool (available through the `php-pear` +package), unless your Linux distribution has an Xdebug package (`php-xdebug`). + +Installation +------------ + +On most Linux distributions you can install Xdebug through its package +manager. You can also compile from source with the `pecl` tool through `pecl +install xdebug`. The latter also works for MacOS as long as PHP is installed +with Homebrew. + +On Windows, you need to `download <https://xdebug.org/download#releases>`_ a +binary. Use the `Wizard <https://xdebug.org/wizard>`_. + +Unless you have installed Xdebug with a package manager on Linux, you also +need to add the following line to your `php.ini` file, or create a new Xdebug +specific ini file `xdebug.ini` in the `conf.d` directory. In either case, it +needs the following line added:: + + zend_extension=xdebug + +For more extensive installation instructions, see the documentation at +https://xdebug.org/docs/install + +Configuration +------------- + +Most features in Xdebug have to be opted in into. Each feature has a specific +opt-in. For example to use the `step debugger +<https://xdebug.org/docs/remote>`_ you need to set `xdebug.remote_enable=1` in +your configuration file. The step debugger requires an IDE (client), of which +there are many `available <https://xdebug.org/docs/remote#clients>`_. + +The documentation has instructions for each of Xdebug's features: +https://xdebug.org/docs/ and a full list of `settings +<https://xdebug.org/docs/all_settings>`_ is also available there. + +Contributing +------------ + +Xdebug is written in C, and extensive knowledge of PHP's internals is +necessary to be able to contribute. Contributing guidance is available +`separately <https://github.com/xdebug/xdebug/blob/master/CONTRIBUTING.rst>`_. + +Before you begin to contribute, please reach out first. Either through email +(address at the bottom), an issue in the `issue tracker +<https://bugs.xdebug.org>`_ or preferably through IRC on Freenode's #xdebug +channel. + +Testing +------- + +If you are familiar with compiling PHP extension from source, have a local +checkout of Xdebug's GitHub repository, and have compiled Xdebug in that +directory following the instructions under `installation +<https://xdebug.org/docs/install#source>`_ you can run Xdebug's tests by +running:: + + php run-xdebug-tests.php + +The test framework requires that the PHP binary on the path has Xdebug loaded, +with remote debugging enabled through `xdebug.mode=debug`. It is possible +to skip remote debugging tests by exporting the `SKIP_DBGP_TESTS=1` environment +variable. + +The `SKIP_UNPARALLEL_TESTS=1` can be used to skip tests that can not run in +parallel environments, and the `SKIP_SLOW_TESTS=1` environment variable to skip +slow tests. The `OPCACHE` environment variable can either be `yes` or `no` and +controls whether the test framework enables or disables OpCache. + +Licensing +--------- + +Xdebug is released under `The Xdebug License +<https://github.com/xdebug/xdebug/blob/master/LICENSE>`_, which is based on +`The PHP License <https://github.com/php/php-src/blob/master/LICENSE>`_. It is +an Open Source license (though not explicitly endorsed by the Open Source +Initiative). + +Further Reading +--------------- + +Xdebug has extensive documentation on its `website <https://xdebug.org/docs>`_. +There are over a hundred settings and many functions documented. Please have a +look through the wealth of information that Xdebug can provide to make your +every day development with PHP easier. + +Support +------- + +For questions regarding Xdebug, please use `StackOverflow +<https://stackoverflow.com/questions/tagged/xdebug>`_, and tag your question +with `xdebug`. + +You can also find ad-hoc and sporadic support on IRC: ``freenode/#xdebug``. +You can do that with your favourite client, or by using their `webchat +<http://webchat.freenode.net/?channels=#xdebug>`_. + +If you think that you encountered a bug, please file a detailed bug report +at https://bugs.xdebug.org. You are required to create an account, this is +so that you can be contacted for additional information and to keep out +spam. + + +Derick Rethans — derick@xdebug.org
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/config.m4
Added
@@ -0,0 +1,133 @@ +dnl config.m4 for extension Xdebug + +PHP_ARG_ENABLE(xdebug, whether to enable Xdebug support, + --enable-xdebug Enable Xdebug support) + +PHP_ARG_ENABLE(xdebug-dev, whether to enable Xdebug developer build flags, + --enable-xdebug-dev Xdebug: Enable developer flags,, no) + +PHP_ARG_WITH(xdebug-compression, whether to compress profiler files (requires zlib), + --without-xdebug-compression Xdebug: Disable compression through zlib,yes,no) + +m4_include(m4/pkg.m4) +m4_include(m4/clocks.m4) + +if test "$PHP_XDEBUG" != "no"; then + AC_MSG_CHECKING(Check for supported PHP versions) + PHP_XDEBUG_FOUND_VERSION=`${PHP_CONFIG} --version` + PHP_XDEBUG_FOUND_VERNUM=`echo "${PHP_XDEBUG_FOUND_VERSION}" | $AWK 'BEGIN { FS = "."; } { printf "%d", ($1 * 100 + $2) * 100 + $3;}'` + if test "$PHP_XDEBUG_FOUND_VERNUM" -lt "80000"; then + AC_MSG_ERROR(not supported. Need a PHP version >= 8.0.0 and < 8.3.0 (found $PHP_XDEBUG_FOUND_VERSION)) + else + if test "$PHP_XDEBUG_FOUND_VERNUM" -ge "80300"; then + AC_MSG_ERROR(not supported. Need a PHP version >= 8.0.0 and < 8.3.0 (found $PHP_XDEBUG_FOUND_VERSION)) + else + AC_MSG_RESULT(supported ($PHP_XDEBUG_FOUND_VERSION)) + fi + fi + + AC_DEFINE(HAVE_XDEBUG,1, ) + + old_CPPFLAGS=$CPPFLAGS + CPPFLAGS="$INCLUDES $CPPFLAGS" + + AC_XDEBUG_CLOCK + + AC_CHECK_HEADERS(netinet/in.h poll.h sys/poll.h) + case $host_os in + linux*) + AC_CHECK_HEADERS(linux/rtnetlink.h, , + case $host_os in + linux-musl*) + AC_MSG_ERROR(rtnetlink.h is required, install the linux-headers package: apk add --update linux-headers) + esac + AC_MSG_ERROR(rtnetlink.h is required, please make sure it is available by installing the correct package) + ) + esac + + PHP_CHECK_FUNC(res_ninit, resolv) + PHP_CHECK_FUNC(res_nclose, resolv) + + PHP_CHECK_LIBRARY(m, cos, PHP_ADD_LIBRARY(m,, XDEBUG_SHARED_LIBADD) ) + + if test "$PHP_XDEBUG_COMPRESSION" != "no"; then + PKG_CHECK_MODULES(ZLIB, zlib >= 1.2.9, + PHP_EVAL_LIBLINE($ZLIB_LIBS, XDEBUG_SHARED_LIBADD) + PHP_EVAL_INCLINE($ZLIB_CFLAGS) + + AC_DEFINE(HAVE_XDEBUG_ZLIB,1, ) + , ) + fi + + CPPFLAGS=$old_CPPFLAGS + + if test "$PHP_XDEBUG_DEV" = "yes"; then + AX_CHECK_COMPILE_FLAG(-Wbool-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wbool-conversion") + AX_CHECK_COMPILE_FLAG(-Wdeclaration-after-statement, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wdeclaration-after-statement") + AX_CHECK_COMPILE_FLAG(-Wdiscarded-qualifiers, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wdiscarded-qualifiers") + AX_CHECK_COMPILE_FLAG(-Wduplicate-enum, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wduplicate-enum") + AX_CHECK_COMPILE_FLAG(-Wempty-body, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wempty-body") + AX_CHECK_COMPILE_FLAG(-Wenum-compare, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wenum-compare") + AX_CHECK_COMPILE_FLAG(-Werror, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Werror") + AX_CHECK_COMPILE_FLAG(-Wextra, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wextra") + AX_CHECK_COMPILE_FLAG(-Wformat-nonliteral, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wformat-nonliteral") + AX_CHECK_COMPILE_FLAG(-Wformat-security, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wformat-security") + AX_CHECK_COMPILE_FLAG(-Wheader-guard, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wheader-guard") + AX_CHECK_COMPILE_FLAG(-Wincompatible-pointer-types-discards-qualifiers, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wincompatible-pointer-types-discards-qualifiers") + AX_CHECK_COMPILE_FLAG(-Wimplicit-fallthrough, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wimplicit-fallthrough") + AX_CHECK_COMPILE_FLAG(-Winit-self, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Winit-self") + AX_CHECK_COMPILE_FLAG(-Wlogical-not-parentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wlogical-not-parentheses") + AX_CHECK_COMPILE_FLAG(-Wlogical-op, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wlogical-op") + AX_CHECK_COMPILE_FLAG(-Wlogical-op-parentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wlogical-op-parentheses") + AX_CHECK_COMPILE_FLAG(-Wloop-analysis, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wloop-analysis") + AX_CHECK_COMPILE_FLAG(-Wmaybe-uninitialized, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmaybe-uninitialized") + AX_CHECK_COMPILE_FLAG(-Wmissing-format-attribute, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wmissing-format-attribute") + AX_CHECK_COMPILE_FLAG(-Wno-missing-field-initializers, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-missing-field-initializers") + AX_CHECK_COMPILE_FLAG(-Wno-sign-compare, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-sign-compare") + AX_CHECK_COMPILE_FLAG(-Wno-unused-but-set-variable, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-but-set-variable") + AX_CHECK_COMPILE_FLAG(-Wno-unused-parameter, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-unused-parameter") + AX_CHECK_COMPILE_FLAG(-Wno-variadic-macros, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wno-variadic-macros") + AX_CHECK_COMPILE_FLAG(-Wparentheses, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wparentheses") + AX_CHECK_COMPILE_FLAG(-Wpointer-bool-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wpointer-bool-conversion") + AX_CHECK_COMPILE_FLAG(-Wsizeof-array-argument, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wsizeof-array-argument") + AX_CHECK_COMPILE_FLAG(-Wstring-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wstring-conversion") + AX_CHECK_COMPILE_FLAG(-Wwrite-strings, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wwrite-strings") + AX_CHECK_COMPILE_FLAG(-Wpointer-arith, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wpointer-arith") + AX_CHECK_COMPILE_FLAG(-fdiagnostics-show-option, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fdiagnostics-show-option") + AX_CHECK_COMPILE_FLAG(-fno-exceptions, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fno-exceptions") + AX_CHECK_COMPILE_FLAG(-fno-omit-frame-pointer, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fno-omit-frame-pointer") + AX_CHECK_COMPILE_FLAG(-fno-optimize-sibling-calls, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fno-optimize-sibling-calls") + AX_CHECK_COMPILE_FLAG(-fsanitize-address, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fsanitize-address") + AX_CHECK_COMPILE_FLAG(-fstack-protector, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fstack-protector") + + MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS" + STD_CFLAGS="-g -O0 -Wall" + fi + + PHP_XDEBUG_CFLAGS="$STD_CFLAGS $MAINTAINER_CFLAGS" + + XDEBUG_BASE_SOURCES="src/base/base.c src/base/filter.c" + XDEBUG_LIB_SOURCES="src/lib/usefulstuff.c src/lib/compat.c src/lib/crc32.c src/lib/file.c src/lib/hash.c src/lib/headers.c src/lib/lib.c src/lib/llist.c src/lib/log.c src/lib/set.c src/lib/str.c src/lib/timing.c src/lib/var.c src/lib/var_export_html.c src/lib/var_export_line.c src/lib/var_export_text.c src/lib/var_export_xml.c src/lib/xml.c" + + XDEBUG_COVERAGE_SOURCES="src/coverage/branch_info.c src/coverage/code_coverage.c" + XDEBUG_DEBUGGER_SOURCES="src/debugger/com.c src/debugger/debugger.c src/debugger/handler_dbgp.c src/debugger/handlers.c src/debugger/ip_info.c" + XDEBUG_DEVELOP_SOURCES="src/develop/develop.c src/develop/monitor.c src/develop/php_functions.c src/develop/stack.c src/develop/superglobals.c" + XDEBUG_GCSTATS_SOURCES="src/gcstats/gc_stats.c" + XDEBUG_PROFILER_SOURCES="src/profiler/profiler.c" + XDEBUG_TRACING_SOURCES="src/tracing/trace_computerized.c src/tracing/trace_html.c src/tracing/trace_textual.c src/tracing/tracing.c" + + PHP_NEW_EXTENSION(xdebug, xdebug.c $XDEBUG_BASE_SOURCES $XDEBUG_LIB_SOURCES $XDEBUG_COVERAGE_SOURCES $XDEBUG_DEBUGGER_SOURCES $XDEBUG_DEVELOP_SOURCES $XDEBUG_GCSTATS_SOURCES $XDEBUG_PROFILER_SOURCES $XDEBUG_TRACING_SOURCES, $ext_shared,,$PHP_XDEBUG_CFLAGS,,yes) + PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/base) + PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/lib) + PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/coverage) + PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/debugger) + PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/develop) + PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/gcstats) + PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/profiler) + PHP_ADD_BUILD_DIR(PHP_EXT_BUILDDIR(xdebug)/src/tracing) + PHP_SUBST(XDEBUG_SHARED_LIBADD) + PHP_ADD_MAKEFILE_FRAGMENT + + PHP_ADD_INCLUDE($ext_srcdir/src) + PHP_ADD_INCLUDE($ext_builddir/src) +fi
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/config.w32
Changed
(renamed from xdebug-3.1.5/config.w32)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/contrib/tracefile-analyser.php
Changed
(renamed from xdebug-3.1.5/contrib/tracefile-analyser.php)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/contrib/xt.vim
Changed
(renamed from xdebug-3.1.5/contrib/xt.vim)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/m4/clocks.m4
Changed
(renamed from xdebug-3.1.5/m4/clocks.m4)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/m4/pkg.m4
Changed
(renamed from xdebug-3.1.5/m4/pkg.m4)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/php_xdebug.h
Added
@@ -0,0 +1,111 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef PHP_XDEBUG_H +#define PHP_XDEBUG_H + +#define XDEBUG_NAME "Xdebug" +#define XDEBUG_VERSION "3.2.0" +#define XDEBUG_AUTHOR "Derick Rethans" +#define XDEBUG_COPYRIGHT "Copyright (c) 2002-2022 by Derick Rethans" +#define XDEBUG_COPYRIGHT_SHORT "Copyright (c) 2002-2022" +#define XDEBUG_URL "https://xdebug.org" +#define XDEBUG_URL_FAQ "https://xdebug.org/docs/faq#api" + +#include "lib/php-header.h" + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "base/base_globals.h" +#include "coverage/branch_info.h" +#include "coverage/code_coverage.h" +#include "debugger/debugger.h" +#include "develop/develop.h" +#include "lib/lib.h" +#include "gcstats/gc_stats.h" +#include "profiler/profiler.h" +#include "tracing/tracing.h" +#include "lib/compat.h" +#include "lib/hash.h" +#include "lib/llist.h" +#include "lib/vector.h" +#include "lib/timing.h" + +extern zend_module_entry xdebug_module_entry; +#define phpext_xdebug_ptr &xdebug_module_entry + +#define OUTPUT_NOT_CHECKED -1 +#define OUTPUT_IS_TTY 1 +#define OUTPUT_NOT_TTY 0 + +#ifdef PHP_WIN32 +#define PHP_XDEBUG_API __declspec(dllexport) +#else +#define PHP_XDEBUG_API +#endif + +#ifdef ZTS +#include "TSRM.h" +#endif + +#include "main/SAPI.h" + +#define XDEBUG_ALLOWED_HALT_LEVELS (E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE ) + +PHP_MINIT_FUNCTION(xdebug); +PHP_MSHUTDOWN_FUNCTION(xdebug); +PHP_RINIT_FUNCTION(xdebug); +PHP_RSHUTDOWN_FUNCTION(xdebug); +PHP_MINFO_FUNCTION(xdebug); +ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xdebug); + +int xdebug_is_output_tty(); + +ZEND_BEGIN_MODULE_GLOBALS(xdebug) + struct { + xdebug_base_globals_t base; + xdebug_coverage_globals_t coverage; + xdebug_debugger_globals_t debugger; + xdebug_develop_globals_t develop; + xdebug_gc_stats_globals_t gc_stats; + xdebug_library_globals_t library; + xdebug_profiler_globals_t profiler; + xdebug_tracing_globals_t tracing; + } globals; + struct { + xdebug_base_settings_t base; + xdebug_coverage_settings_t coverage; + xdebug_debugger_settings_t debugger; + xdebug_develop_settings_t develop; + xdebug_gc_stats_settings_t gc_stats; + xdebug_library_settings_t library; + xdebug_profiler_settings_t profiler; + xdebug_tracing_settings_t tracing; + } settings; +ZEND_END_MODULE_GLOBALS(xdebug) + +#ifdef ZTS +#define XG(v) TSRMG(xdebug_globals_id, zend_xdebug_globals *, v) +#else +#define XG(v) (xdebug_globals.v) +#endif + +#define XG_BASE(v) (XG(globals.base.v)) +#define XINI_BASE(v) (XG(settings.base.v)) + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/php_xdebug_arginfo.h
Changed
(renamed from xdebug-3.1.5/php_xdebug_arginfo.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/run-xdebug-tests.php
Added
@@ -0,0 +1,4041 @@ +#!/usr/bin/env php +<?php +/* + +----------------------------------------------------------------------+ + | Copyright (c) The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | https://php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Authors: Ilia Alshanetsky <iliaa@php.net> | + | Preston L. Bannister <pbannister@php.net> | + | Marcus Boerger <helly@php.net> | + | Derick Rethans <derick@php.net> | + | Sander Roobol <sander@php.net> | + | Andrea Faulds <ajf@ajf.me> | + | (based on version by: Stig Bakken <ssb@php.net>) | + | (based on the PHP 3 test framework by Rasmus Lerdorf) | + +----------------------------------------------------------------------+ + */ + +/* $Id: ff8fc1a09b14846e2a5daa9b51cc2b6e97f3ac3c $ */ + +/* Temporary variables while this file is being refactored. */ +/** @var ?JUnit */ +$junit = null; + +/* End temporary variables. */ + +/* Let there be no top-level code beyond this point: + * Only functions and classes, thanks! + * + * Minimum required PHP version: 7.4.0 + */ + +function show_usage(): void +{ + echo <<<HELP +Synopsis: + php run-tests.php options files directories + +Options: + -j<workers> Run up to <workers> simultaneous testing processes in parallel for + quicker testing on systems with multiple logical processors. + Note that this is experimental feature. + + -l <file> Read the testfiles to be executed from <file>. After the test + has finished all failed tests are written to the same <file>. + If the list is empty and no further test is specified then + all tests are executed (same as: -r <file> -w <file>). + + -r <file> Read the testfiles to be executed from <file>. + + -w <file> Write a list of all failed tests to <file>. + + -a <file> Same as -w but append rather then truncating <file>. + + -W <file> Write a list of all tests and their result status to <file>. + + -c <file> Look for php.ini in directory <file> or use <file> as ini. + + -n Pass -n option to the php binary (Do not use a php.ini). + + -d foo=bar Pass -d option to the php binary (Define INI entry foo + with value 'bar'). + + -g Comma separated list of groups to show during test run + (possible values: PASS, FAIL, XFAIL, XLEAK, SKIP, BORK, WARN, LEAK, REDIRECT). + + -m Test for memory leaks with Valgrind (equivalent to -M memcheck). + + -M <tool> Test for errors with Valgrind tool. + + -p <php> Specify PHP executable to run. + + -P Use PHP_BINARY as PHP executable to run (default). + + -q Quiet, no user interaction (same as environment NO_INTERACTION). + + -s <file> Write output to <file>. + + -x Sets 'SKIP_SLOW_TESTS' environmental variable. + + --offline Sets 'SKIP_ONLINE_TESTS' environmental variable. + + --verbose + -v Verbose mode. + + --help + -h This Help. + + --temp-source <sdir> --temp-target <tdir> --temp-urlbase <url> + Write temporary files to <tdir> by replacing <sdir> from the + filenames to generate with <tdir>. In general you want to make + <sdir> the path to your source files and <tdir> some patch in + your web page hierarchy with <url> pointing to <tdir>. + + --keep-all|php|skip|after|clean + Do not delete 'all' files, 'php' test file, 'skip', 'after', + or 'clean' file. + + --set-timeout <n> + Set timeout for individual tests, where <n> is the number of + seconds. The default value is 60 seconds, or 300 seconds when + testing for memory leaks. + + --context <n> + Sets the number of lines of surrounding context to print for diffs. + The default value is 3. + + --show-all|php|skip|clean|after|exp|diff|out|mem + Show 'all' files, 'php' test file, 'skip', 'after', or 'clean' file. + You can also use this to show the output 'out', the expected result + 'exp', the difference between them 'diff' or the valgrind log + 'mem'. The result types get written independent of the log format, + however 'diff' only exists when a test fails. + + --show-slow <n> + Show all tests that took longer than <n> milliseconds to run. + + --no-clean Do not execute clean section if any. + + --color + --no-color Do/Don't colorize the result type in the test result. + + --repeat n + Run the tests multiple times in the same process and check the + output of the last execution (CLI SAPI only). + + --bless Bless failed tests using scripts/dev/bless_tests.php. + +HELP; +} + +/** + * One function to rule them all, one function to find them, one function to + * bring them all and in the darkness bind them. + * This is the entry point and exit point überfunction. It contains all the + * code that was previously found at the top level. It could and should be + * refactored to be smaller and more manageable. + */ +function main(): void +{ + /* This list was derived in a naïve mechanical fashion. If a member + * looks like it doesn't belong, it probably doesn't; cull at will. + */ + global $DETAILED, $PHP_FAILED_TESTS, $SHOW_ONLY_GROUPS, $argc, $argv, $cfg, + $cfgfiles, $cfgtypes, $conf_passed, $end_time, $environment, + $exts_skipped, $exts_tested, $exts_to_test, $failed_tests_file, + $ignored_by_ext, $ini_overwrites, $is_switch, $colorize, + $log_format, $matches, $no_clean, $no_file_cache, + $optionals, $pass_option_n, $pass_options, + $pattern_match, $php, $php_cgi, $phpdbg, $preload, $redir_tests, + $repeat, $result_tests_file, $slow_min_ms, $start_time, $switch, + $temp_source, $temp_target, $test_cnt, $test_dirs, + $test_files, $test_idx, $test_list, $test_results, $testfile, + $user_tests, $valgrind, $sum_results, $shuffle, $file_cache, $num_repeats, + $bless; + // Parallel testing + global $workers, $workerID; + global $context_line_count; + + // Temporary for the duration of refactoring + /** @var JUnit */ + global $junit; + + define('IS_WINDOWS', substr(PHP_OS, 0, 3) == "WIN"); + + $workerID = 0; + if (getenv("TEST_PHP_WORKER")) { + $workerID = intval(getenv("TEST_PHP_WORKER")); + run_worker(); + return; + } + + define('INIT_DIR', getcwd()); + + // Change into the PHP source directory. + if (getenv('TEST_PHP_SRCDIR')) { + @chdir(getenv('TEST_PHP_SRCDIR')); + } + + define('TEST_PHP_SRCDIR', getcwd()); + + check_proc_open_function_exists(); + + // If timezone is not set, use UTC. + if (ini_get('date.timezone') == '') { + date_default_timezone_set('UTC'); + } + + // Delete some security related environment variables + putenv('SSH_CLIENT=deleted'); + putenv('SSH_AUTH_SOCK=deleted'); + putenv('SSH_TTY=deleted'); + putenv('SSH_CONNECTION=deleted'); + + set_time_limit(0); + + ini_set('pcre.backtrack_limit', PHP_INT_MAX); + + init_output_buffers(); + + error_reporting(E_ALL); + + $environment = $_ENV ?? ; + + // Some configurations like php.ini-development set variables_order="GPCS" + // not "EGPCS", in which case $_ENV is NOT populated. Detect if the $_ENV + // was empty and handle it by explicitly populating through getenv(). + if (empty($environment)) { + $environment = getenv(); + } + + if (empty($environment'TEMP')) { + $environment'TEMP' = sys_get_temp_dir(); + + if (empty($environment'TEMP')) { + // For example, OpCache on Windows will fail in this case because + // child processes (for tests) will not get a TEMP variable, so + // GetTempPath() will fallback to c:\windows, while GetTempPath() + // will return %TEMP% for parent (likely a different path). The + // parent will initialize the OpCache in that path, and child will + // fail to reattach to the OpCache because it will be using the + // wrong path. + die("TEMP environment is NOT set"); + } else { + if (count($environment) == 1) { + // Not having other environment variables, only having TEMP, is + // probably ok, but strange and may make a difference in the + // test pass rate, so warn the user. + echo "WARNING: Only 1 environment variable will be available to tests(TEMP environment variable)" . PHP_EOL; + } + } + } + + if (IS_WINDOWS && empty($environment"SystemRoot")) { + $environment"SystemRoot" = getenv("SystemRoot"); + } + + $php = null; + $php_cgi = null; + $phpdbg = null; + + if (getenv('TEST_PHP_LOG_FORMAT')) { + $log_format = strtoupper(getenv('TEST_PHP_LOG_FORMAT')); + } else { + $log_format = 'LEODS'; + } + + // Check whether a detailed log is wanted. + if (getenv('TEST_PHP_DETAILED')) { + $DETAILED = getenv('TEST_PHP_DETAILED'); + } else { + $DETAILED = 0; + } + + $junit = new JUnit($environment, $workerID); + + if (getenv('SHOW_ONLY_GROUPS')) { + $SHOW_ONLY_GROUPS = explode(",", getenv('SHOW_ONLY_GROUPS')); + } else { + $SHOW_ONLY_GROUPS = ; + } + + // Check whether user test dirs are requested. + if (getenv('TEST_PHP_USER')) { + $user_tests = explode(',', getenv('TEST_PHP_USER')); + } else { + $user_tests = ; + } + + $exts_to_test = ; + $ini_overwrites = + 'output_handler=', + 'open_basedir=', + 'disable_functions=', + 'output_buffering=Off', + 'error_reporting=' . E_ALL, + 'display_errors=1', + 'display_startup_errors=1', + 'log_errors=0', + 'log_errors_max_len=0', + 'html_errors=0', + 'track_errors=0', + 'report_memleaks=1', + 'report_zend_debug=0', + 'docref_root=', + 'docref_ext=.html', + 'error_prepend_string=', + 'error_append_string=', + 'auto_prepend_file=', + 'auto_append_file=', + 'ignore_repeated_errors=0', + 'precision=14', + 'serialize_precision=-1', + 'memory_limit=128M', + 'opcache.fast_shutdown=0', + 'opcache.file_update_protection=0', + 'opcache.revalidate_freq=0', + 'opcache.jit_hot_loop=1', + 'opcache.jit_hot_func=1', + 'opcache.jit_hot_return=1', + 'opcache.jit_hot_side_exit=1', + 'zend.assertions=1', + 'zend.exception_ignore_args=0', + 'zend.exception_string_param_max_len=15', + 'short_open_tag=0', + ; + + $no_file_cache = '-d opcache.file_cache= -d opcache.file_cache_only=0'; + + define('TRAVIS_CI', (bool) getenv('TRAVIS')); + + // Determine the tests to be run. + + $test_files = ; + $redir_tests = ; + $test_results = ; + $PHP_FAILED_TESTS = + 'BORKED' => , + 'FAILED' => , + 'WARNED' => , + 'LEAKED' => , + 'XFAILED' => , + 'XLEAKED' => , + 'SLOW' => + ; + + // If parameters given assume they represent selected tests to run. + $result_tests_file = false; + $failed_tests_file = false; + $pass_option_n = false; + $pass_options = ''; + + $output_file = INIT_DIR . '/php_test_results_' . date('Ymd_Hi') . '.txt'; + + $just_save_results = false; + $valgrind = null; + $temp_source = null; + $temp_target = null; + $conf_passed = null; + $no_clean = false; + $colorize = true; + if (function_exists('sapi_windows_vt100_support') && !sapi_windows_vt100_support(STDOUT, true)) { + $colorize = false; + } + if (array_key_exists('NO_COLOR', $environment)) { + $colorize = false; + } + $selected_tests = false; + $slow_min_ms = INF; + $preload = false; + $file_cache = null; + $shuffle = false; + $bless = false; + $workers = null; + $context_line_count = 3; + $num_repeats = 1; + + $cfgtypes = 'show', 'keep'; + $cfgfiles = 'skip', 'php', 'after', 'clean', 'out', 'diff', 'exp', 'mem'; + $cfg = ; + + foreach ($cfgtypes as $type) { + $cfg$type = ; + + foreach ($cfgfiles as $file) { + $cfg$type$file = false; + } + } + + if (!isset($argc, $argv) || !$argc) { + $argv = __FILE__; + $argc = 1; + } + + if (getenv('TEST_PHP_ARGS')) { + $argv = array_merge($argv, explode(' ', getenv('TEST_PHP_ARGS'))); + $argc = count($argv); + } + + for ($i = 1; $i < $argc; $i++) { + $is_switch = false; + $switch = substr($argv$i, 1, 1); + $repeat = substr($argv$i, 0, 1) == '-'; + + while ($repeat) { + if (!$is_switch) { + $switch = substr($argv$i, 1, 1); + } + + $is_switch = true; + + if ($repeat) { + foreach ($cfgtypes as $type) { + if (strpos($switch, '--' . $type) === 0) { + foreach ($cfgfiles as $file) { + if ($switch == '--' . $type . '-' . $file) { + $cfg$type$file = true; + $is_switch = false; + break; + } + } + } + } + } + + if (!$is_switch) { + $is_switch = true; + break; + } + + $repeat = false; + + switch ($switch) { + case 'j': + $workers = substr($argv$i, 2); + if (!preg_match('/^\d+$/', $workers) || $workers == 0) { + error("'$workers' is not a valid number of workers, try e.g. -j16 for 16 workers"); + } + $workers = intval($workers, 10); + // Don't use parallel testing infrastructure if there is only one worker. + if ($workers === 1) { + $workers = null; + } + break; + case 'r': + case 'l': + $test_list = file($argv++$i); + if ($test_list) { + foreach ($test_list as $test) { + $matches = ; + if (preg_match('/^#.*\(.*)\\:\s+(.*)$/', $test, $matches)) { + $redir_tests = $matches1, $matches2; + } else { + if (strlen($test)) { + $test_files = trim($test); + } + } + } + } + if ($switch != 'l') { + break; + } + $i--; + // no break + case 'w': + $failed_tests_file = fopen($argv++$i, 'w+t'); + break; + case 'a': + $failed_tests_file = fopen($argv++$i, 'a+t'); + break; + case 'W': + $result_tests_file = fopen($argv++$i, 'w+t'); + break; + case 'c': + $conf_passed = $argv++$i; + break; + case 'd': + $ini_overwrites = $argv++$i; + break; + case 'g': + $SHOW_ONLY_GROUPS = explode(",", $argv++$i); + break; + //case 'h' + case '--keep-all': + foreach ($cfgfiles as $file) { + $cfg'keep'$file = true; + } + break; + //case 'l' + case 'm': + $valgrind = new RuntestsValgrind($environment); + break; + case 'M': + $valgrind = new RuntestsValgrind($environment, $argv++$i); + break; + case 'n': + if (!$pass_option_n) { + $pass_options .= ' -n'; + } + $pass_option_n = true; + break; + case 'e': + $pass_options .= ' -e'; + break; + case '--preload': + $preload = true; + $environment'SKIP_PRELOAD' = 1; + break; + case '--file-cache-prime': + $file_cache = 'prime'; + break; + case '--file-cache-use': + $file_cache = 'use'; + break; + case '--no-clean': + $no_clean = true; + break; + case '--color': + $colorize = true; + break; + case '--no-color': + $colorize = false; + break; + case 'p': + $php = $argv++$i; + putenv("TEST_PHP_EXECUTABLE=$php"); + $environment'TEST_PHP_EXECUTABLE' = $php; + break; + case 'P': + $php = PHP_BINARY; + putenv("TEST_PHP_EXECUTABLE=$php"); + $environment'TEST_PHP_EXECUTABLE' = $php; + break; + case 'q': + putenv('NO_INTERACTION=1'); + $environment'NO_INTERACTION' = 1; + break; + //case 'r' + case 's': + $output_file = $argv++$i; + $just_save_results = true; + break; + case '--set-timeout': + $timeout = $argv++$i ?? ''; + if (!preg_match('/^\d+$/', $timeout)) { + error("'$timeout' is not a valid number of seconds, try e.g. --set-timeout 60 for 1 minute"); + } + $environment'TEST_TIMEOUT' = intval($timeout, 10); + break; + case '--context': + $context_line_count = $argv++$i ?? ''; + if (!preg_match('/^\d+$/', $context_line_count)) { + error("'$context_line_count' is not a valid number of lines of context, try e.g. --context 3 for 3 lines"); + } + $context_line_count = intval($context_line_count, 10); + break; + case '--show-all': + foreach ($cfgfiles as $file) { + $cfg'show'$file = true; + } + break; + case '--show-slow': + $slow_min_ms = $argv++$i ?? ''; + if (!preg_match('/^\d+$/', $slow_min_ms)) { + error("'$slow_min_ms' is not a valid number of milliseconds, try e.g. --show-slow 1000 for 1 second"); + } + $slow_min_ms = intval($slow_min_ms, 10); + break; + case '--temp-source': + $temp_source = $argv++$i; + break; + case '--temp-target': + $temp_target = $argv++$i; + break; + case 'v': + case '--verbose': + $DETAILED = true; + break; + case 'x': + $environment'SKIP_SLOW_TESTS' = 1; + break; + case '--offline': + $environment'SKIP_ONLINE_TESTS' = 1; + break; + case '--shuffle': + $shuffle = true; + break; + case '--asan': + case '--msan': + $environment'USE_ZEND_ALLOC' = 0; + $environment'USE_TRACKED_ALLOC' = 1; + $environment'SKIP_ASAN' = 1; + $environment'SKIP_PERF_SENSITIVE' = 1; + if ($switch === '--msan') { + $environment'SKIP_MSAN' = 1; + } + + $lsanSuppressions = __DIR__ . '/azure/lsan-suppressions.txt'; + if (file_exists($lsanSuppressions)) { + $environment'LSAN_OPTIONS' = 'suppressions=' . $lsanSuppressions + . ':print_suppressions=0'; + } + break; + case '--repeat': + $num_repeats = (int) $argv++$i; + $environment'SKIP_REPEAT' = 1; + break; + case '--bless': + $bless = true; + break; + //case 'w' + case '-': + // repeat check with full switch + $switch = $argv$i; + if ($switch != '-') { + $repeat = true; + } + break; + case '--version': + echo '$Id: ff8fc1a09b14846e2a5daa9b51cc2b6e97f3ac3c $' . "\n"; + exit(1); + + default: + echo "Illegal switch '$switch' specified!\n"; + // no break + case 'h': + case '-help': + case '--help': + show_usage(); + exit(1); + } + } + + if (!$is_switch) { + $selected_tests = true; + $testfile = realpath($argv$i); + + if (!$testfile && strpos($argv$i, '*') !== false && function_exists('glob')) { + if (substr($argv$i, -5) == '.phpt') { + $pattern_match = glob($argv$i); + } else { + if (preg_match("/\*$/", $argv$i)) { + $pattern_match = glob($argv$i . '.phpt'); + } else { + die('Cannot find test file "' . $argv$i . '".' . PHP_EOL); + } + } + + if (is_array($pattern_match)) { + $test_files = array_merge($test_files, $pattern_match); + } + } else { + if (is_dir($testfile)) { + find_files($testfile); + } else { + if (substr($testfile, -5) == '.phpt') { + $test_files = $testfile; + } else { + die('Cannot find test file "' . $argv$i . '".' . PHP_EOL); + } + } + } + } + } + + if ($selected_tests && count($test_files) === 0) { + echo "No tests found.\n"; + return; + } + + if (!$php) { + $php = getenv('TEST_PHP_EXECUTABLE'); + } + if (!$php) { + $php = PHP_BINARY; + } + + if (!$php_cgi) { + $php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE'); + } + if (!$php_cgi) { + $php_cgi = get_binary($php, 'php-cgi', 'sapi/cgi/php-cgi'); + } + + if (!$phpdbg) { + $phpdbg = getenv('TEST_PHPDBG_EXECUTABLE'); + } + if (!$phpdbg) { + $phpdbg = get_binary($php, 'phpdbg', 'sapi/phpdbg/phpdbg'); + } + + putenv("TEST_PHP_EXECUTABLE=$php"); + $environment'TEST_PHP_EXECUTABLE' = $php; + putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi"); + $environment'TEST_PHP_CGI_EXECUTABLE' = $php_cgi; + putenv("TEST_PHPDBG_EXECUTABLE=$phpdbg"); + $environment'TEST_PHPDBG_EXECUTABLE' = $phpdbg; + + if ($conf_passed !== null) { + if (IS_WINDOWS) { + $pass_options .= " -c " . escapeshellarg($conf_passed); + } else { + $pass_options .= " -c '" . realpath($conf_passed) . "'"; + } + } + + $test_files = array_unique($test_files); + $test_files = array_merge($test_files, $redir_tests); + + // Run selected tests. + $test_cnt = count($test_files); + + verify_config(); + write_information(); + + if ($test_cnt) { + putenv('NO_INTERACTION=1'); + usort($test_files, "test_sort"); + $start_time = time(); + + echo "Running selected tests.\n"; + + $test_idx = 0; + run_all_tests($test_files, $environment); + $end_time = time(); + + if ($failed_tests_file) { + fclose($failed_tests_file); + } + + if ($result_tests_file) { + fclose($result_tests_file); + } + + if (0 == count($test_results)) { + echo "No tests were run.\n"; + return; + } + + compute_summary(); + echo "====================================================================="; + echo get_summary(false); + + if ($output_file != '' && $just_save_results) { + save_results($output_file, /* prompt_to_save_results: */ false); + } + } else { + // Compile a list of all test files (*.phpt). + $test_files = ; + $exts_tested = count($exts_to_test); + $exts_skipped = 0; + $ignored_by_ext = 0; + sort($exts_to_test); + $test_dirs = ; + $optionals = 'Zend', 'tests', 'ext', 'sapi'; + + foreach ($optionals as $dir) { + if (is_dir($dir)) { + $test_dirs = $dir; + } + } + + // Convert extension names to lowercase + foreach ($exts_to_test as $key => $val) { + $exts_to_test$key = strtolower($val); + } + + foreach ($test_dirs as $dir) { + find_files(TEST_PHP_SRCDIR . "/{$dir}", $dir == 'ext'); + } + + foreach ($user_tests as $dir) { + find_files($dir, $dir == 'ext'); + } + + $test_files = array_unique($test_files); + usort($test_files, "test_sort"); + + $start_time = time(); + show_start($start_time); + + $test_cnt = count($test_files); + $test_idx = 0; + run_all_tests($test_files, $environment); + $end_time = time(); + + if ($failed_tests_file) { + fclose($failed_tests_file); + } + + if ($result_tests_file) { + fclose($result_tests_file); + } + + // Summarize results + + if (0 == count($test_results)) { + echo "No tests were run.\n"; + return; + } + + compute_summary(); + + show_end($end_time); + show_summary(); + + save_results($output_file, /* prompt_to_save_results: */ true); + } + + $junit->saveXML(); + if ($bless) { + bless_failed_tests($PHP_FAILED_TESTS'FAILED'); + } + if (getenv('REPORT_EXIT_STATUS') !== '0' && getenv('REPORT_EXIT_STATUS') !== 'no' && + ($sum_results'FAILED' || $sum_results'BORKED' || $sum_results'LEAKED')) { + exit(1); + } +} + +if (!function_exists("hrtime")) { + /** + * @return array|float|int + */ + function hrtime(bool $as_num = false) + { + $t = microtime(true); + + if ($as_num) { + return $t * 1000000000; + } + + $s = floor($t); + return 0 => $s, 1 => ($t - $s) * 1000000000; + } +} + +function verify_config(): void +{ + global $php; + + if (empty($php) || !file_exists($php)) { + error('environment variable TEST_PHP_EXECUTABLE must be set to specify PHP executable!'); + } + + if (!is_executable($php)) { + error("invalid PHP executable specified by TEST_PHP_EXECUTABLE = $php"); + } +} + +function write_information(): void +{ + global $php, $php_cgi, $phpdbg, $php_info, $user_tests, $ini_overwrites, $pass_options, $exts_to_test, $valgrind, $no_file_cache; + + // Get info from php + $info_file = __DIR__ . '/run-test-info.php'; + @unlink($info_file); + $php_info = '<?php echo " +PHP_SAPI : " , PHP_SAPI , " +PHP_VERSION : " , phpversion() , " +ZEND_VERSION: " , zend_version() , " +PHP_OS : " , PHP_OS , " - " , php_uname() , " +INI actual : " , realpath(get_cfg_var("cfg_file_path")) , " +More .INIs : " , (function_exists(\'php_ini_scanned_files\') ? str_replace("\n","", php_ini_scanned_files()) : "** not determined **"); ?>'; + save_text($info_file, $php_info); + $info_params = ; + settings2array($ini_overwrites, $info_params); + $info_params = settings2params($info_params); + $php_info = `$php $pass_options $info_params $no_file_cache "$info_file"`; + define('TESTED_PHP_VERSION', `$php -n -r "echo PHP_VERSION;"`); + + if ($php_cgi && $php != $php_cgi) { + $php_info_cgi = `$php_cgi $pass_options $info_params $no_file_cache -q "$info_file"`; + $php_info_sep = "\n---------------------------------------------------------------------"; + $php_cgi_info = "$php_info_sep\nPHP : $php_cgi $php_info_cgi$php_info_sep"; + } else { + $php_cgi_info = ''; + } + + if ($phpdbg) { + $phpdbg_info = `$phpdbg $pass_options $info_params $no_file_cache -qrr "$info_file"`; + $php_info_sep = "\n---------------------------------------------------------------------"; + $phpdbg_info = "$php_info_sep\nPHP : $phpdbg $phpdbg_info$php_info_sep"; + } else { + $phpdbg_info = ''; + } + + if (function_exists('opcache_invalidate')) { + opcache_invalidate($info_file, true); + } + @unlink($info_file); + + // load list of enabled and loadable extensions + save_text($info_file, <<<'PHP' + <?php + echo str_replace("Zend OPcache", "opcache", implode(",", get_loaded_extensions())); + $ext_dir = ini_get("extension_dir"); + foreach (scandir($ext_dir) as $file) { + if (!preg_match('/^(?:php_)?(_a-zA-Z0-9+)\.(?:so|dll)$/', $file, $matches)) { + continue; + } + $ext = $matches1; + if (!extension_loaded($ext) && @dl($file)) { + echo ",", $ext; + } + } + ?> + PHP); + $exts_to_test = explode(',', `$php $pass_options $info_params $no_file_cache "$info_file"`); + // check for extensions that need special handling and regenerate + $info_params_ex = + 'session' => 'session.auto_start=0', + 'tidy' => 'tidy.clean_output=0', + 'zlib' => 'zlib.output_compression=Off', + 'xdebug' => 'xdebug.mode=off','xdebug.start_with_request=default','xdebug.log_level=20', + ; + + foreach ($info_params_ex as $ext => $ini_overwrites_ex) { + if (in_array($ext, $exts_to_test)) { + $ini_overwrites = array_merge($ini_overwrites, $ini_overwrites_ex); + } + } + + if (function_exists('opcache_invalidate')) { + opcache_invalidate($info_file, true); + } + @unlink($info_file); + + // Write test context information. + echo " +===================================================================== +PHP : $php $php_info $php_cgi_info $phpdbg_info +CWD : " . TEST_PHP_SRCDIR . " +Extra dirs : "; + foreach ($user_tests as $test_dir) { + echo "{$test_dir}\n "; + } + echo " +VALGRIND : " . ($valgrind ? $valgrind->getHeader() : 'Not used') . " +===================================================================== +"; +} + +function save_results(string $output_file, bool $prompt_to_save_results): void +{ + global $sum_results, $failed_test_summary, + $PHP_FAILED_TESTS, $php; + + if (getenv('NO_INTERACTION') || TRAVIS_CI) { + return; + } + + if ($prompt_to_save_results) { + /* We got failed Tests, offer the user to save a QA report */ + $fp = fopen("php://stdin", "r+"); + if ($sum_results'FAILED' || $sum_results'BORKED' || $sum_results'WARNED' || $sum_results'LEAKED') { + echo "\nYou may have found a problem in PHP."; + } + echo "\nThis report can be saved and used to open an issue on the bug tracker at\n"; + echo "https://github.com/php/php-src/issues\n"; + echo "This gives us a better understanding of PHP's behavior.\n"; + echo "Do you want to save this report in a file? Yn: "; + flush(); + + $user_input = fgets($fp, 10); + fclose($fp); + if (!(strlen(trim($user_input)) == 0 || strtolower($user_input0) == 'y')) { + return; + } + } + /** + * Collect information about the host system for our report + * Fetch phpinfo() output so that we can see the PHP environment + * Make an archive of all the failed tests + */ + $failed_tests_data = ''; + $sep = "\n" . str_repeat('=', 80) . "\n"; + $failed_tests_data .= $failed_test_summary . "\n"; + $failed_tests_data .= get_summary(true) . "\n"; + + if ($sum_results'FAILED') { + foreach ($PHP_FAILED_TESTS'FAILED' as $test_info) { + $failed_tests_data .= $sep . $test_info'name' . $test_info'info'; + $failed_tests_data .= $sep . file_get_contents(realpath($test_info'output')); + $failed_tests_data .= $sep . file_get_contents(realpath($test_info'diff')); + $failed_tests_data .= $sep . "\n\n"; + } + } + + $failed_tests_data .= "\n" . $sep . 'BUILD ENVIRONMENT' . $sep; + $failed_tests_data .= "OS:\n" . PHP_OS . " - " . php_uname() . "\n\n"; + $ldd = $autoconf = $sys_libtool = $libtool = $compiler = 'N/A'; + + if (!IS_WINDOWS) { + /* If PHP_AUTOCONF is set, use it; otherwise, use 'autoconf'. */ + if (getenv('PHP_AUTOCONF')) { + $autoconf = shell_exec(getenv('PHP_AUTOCONF') . ' --version'); + } else { + $autoconf = shell_exec('autoconf --version'); + } + + /* Always use the generated libtool - Mac OSX uses 'glibtool' */ + $libtool = shell_exec(INIT_DIR . '/libtool --version'); + + /* Use shtool to find out if there is glibtool present (MacOSX) */ + $sys_libtool_path = shell_exec(__DIR__ . '/build/shtool path glibtool libtool'); + + if ($sys_libtool_path) { + $sys_libtool = shell_exec(str_replace("\n", "", $sys_libtool_path) . ' --version'); + } + + /* Try the most common flags for 'version' */ + $flags = '-v', '-V', '--version'; + $cc_status = 0; + + foreach ($flags as $flag) { + system(getenv('CC') . " $flag >/dev/null 2>&1", $cc_status); + if ($cc_status == 0) { + $compiler = shell_exec(getenv('CC') . " $flag 2>&1"); + break; + } + } + + $ldd = shell_exec("ldd $php 2>/dev/null"); + } + + $failed_tests_data .= "Autoconf:\n$autoconf\n"; + $failed_tests_data .= "Bundled Libtool:\n$libtool\n"; + $failed_tests_data .= "System Libtool:\n$sys_libtool\n"; + $failed_tests_data .= "Compiler:\n$compiler\n"; + $failed_tests_data .= "Bison:\n" . shell_exec('bison --version 2>/dev/null') . "\n"; + $failed_tests_data .= "Libraries:\n$ldd\n"; + $failed_tests_data .= "\n"; + $failed_tests_data .= $sep . "PHPINFO" . $sep; + $failed_tests_data .= shell_exec($php . ' -ddisplay_errors=stderr -dhtml_errors=0 -i 2> /dev/null'); + + file_put_contents($output_file, $failed_tests_data); + echo "Report saved to: ", $output_file, "\n"; +} + +function get_binary(string $php, string $sapi, string $sapi_path): ?string +{ + $dir = dirname($php); + if (IS_WINDOWS && file_exists("$dir/$sapi.exe")) { + return realpath("$dir/$sapi.exe"); + } + // Sources tree + if (file_exists("$dir/../../$sapi_path")) { + return realpath("$dir/../../$sapi_path"); + } + // Installation tree, preserve command prefix/suffix + $inst = str_replace('php', $sapi, basename($php)); + if (file_exists("$dir/$inst")) { + return realpath("$dir/$inst"); + } + return null; +} + +function find_files(string $dir, bool $is_ext_dir = false, bool $ignore = false): void +{ + global $test_files, $exts_to_test, $ignored_by_ext, $exts_skipped; + + $o = opendir($dir) or error("cannot open directory: $dir"); + + while (($name = readdir($o)) !== false) { + if (is_dir("{$dir}/{$name}") && !in_array($name, '.', '..', '.svn')) { + $skip_ext = ($is_ext_dir && !in_array(strtolower($name), $exts_to_test)); + if ($skip_ext) { + $exts_skipped++; + } + find_files("{$dir}/{$name}", false, $ignore || $skip_ext); + } + + // Cleanup any left-over tmp files from last run. + if (substr($name, -4) == '.tmp') { + @unlink("$dir/$name"); + continue; + } + + // Otherwise we're only interested in *.phpt files. + // (but not those starting with a dot, which are hidden on + // many platforms) + if (substr($name, -5) == '.phpt' && substr($name, 0, 1) !== '.') { + if ($ignore) { + $ignored_by_ext++; + } else { + $testfile = realpath("{$dir}/{$name}"); + $test_files = $testfile; + } + } + } + + closedir($o); +} + +/** + * @param array|string $name + */ +function test_name($name): string +{ + if (is_array($name)) { + return $name0 . ':' . $name1; + } else { + return $name; + } +} +/** + * @param array|string $a + * @param array|string $b + */ +function test_sort($a, $b): int +{ + $a = test_name($a); + $b = test_name($b); + + $ta = strpos($a, TEST_PHP_SRCDIR . "/tests") === 0 ? 1 + (strpos($a, + TEST_PHP_SRCDIR . "/tests/run-test") === 0 ? 1 : 0) : 0; + $tb = strpos($b, TEST_PHP_SRCDIR . "/tests") === 0 ? 1 + (strpos($b, + TEST_PHP_SRCDIR . "/tests/run-test") === 0 ? 1 : 0) : 0; + + if ($ta == $tb) { + return strcmp($a, $b); + } else { + return $tb - $ta; + } +} + +// +// Write the given text to a temporary file, and return the filename. +// + +function save_text(string $filename, string $text, ?string $filename_copy = null): void +{ + global $DETAILED; + + if ($filename_copy && $filename_copy != $filename) { + if (file_put_contents($filename_copy, $text) === false) { + error("Cannot open file '" . $filename_copy . "' (save_text)"); + } + } + + if (file_put_contents($filename, $text) === false) { + error("Cannot open file '" . $filename . "' (save_text)"); + } + + if (1 < $DETAILED) { + echo " +FILE $filename {{{ +$text +}}} +"; + } +} + +// +// Write an error in a format recognizable to Emacs or MSVC. +// + +function error_report(string $testname, string $logname, string $tested): void +{ + $testname = realpath($testname); + $logname = realpath($logname); + + switch (strtoupper(getenv('TEST_PHP_ERROR_STYLE'))) { + case 'MSVC': + echo $testname . "(1) : $tested\n"; + echo $logname . "(1) : $tested\n"; + break; + case 'EMACS': + echo $testname . ":1: $tested\n"; + echo $logname . ":1: $tested\n"; + break; + } +} + +/** + * @return false|string + */ +function system_with_timeout( + string $commandline, + ?array $env = null, + ?string $stdin = null, + bool $captureStdIn = true, + bool $captureStdOut = true, + bool $captureStdErr = true +) { + global $valgrind; + + $data = ''; + + $bin_env = ; + foreach ((array) $env as $key => $value) { + $bin_env$key = $value; + } + + $descriptorspec = ; + if ($captureStdIn) { + $descriptorspec0 = 'pipe', 'r'; + } + if ($captureStdOut) { + $descriptorspec1 = 'pipe', 'w'; + } + if ($captureStdErr) { + $descriptorspec2 = 'pipe', 'w'; + } + $proc = proc_open($commandline, $descriptorspec, $pipes, TEST_PHP_SRCDIR, $bin_env, 'suppress_errors' => true); + + if (!$proc) { + return false; + } + + if ($captureStdIn) { + if (!is_null($stdin)) { + fwrite($pipes0, $stdin); + } + fclose($pipes0); + unset($pipes0); + } + + $timeout = $valgrind ? 300 : ($env'TEST_TIMEOUT' ?? 60); + + while (true) { + /* hide errors from interrupted syscalls */ + $r = $pipes; + $w = null; + $e = null; + + $n = @stream_select($r, $w, $e, $timeout); + + if ($n === false) { + break; + } elseif ($n === 0) { + /* timed out */ + $data .= "\n ** ERROR: process timed out **\n"; + proc_terminate($proc, 9); + return $data; + } elseif ($n > 0) { + if ($captureStdOut) { + $line = fread($pipes1, 8192); + } elseif ($captureStdErr) { + $line = fread($pipes2, 8192); + } else { + $line = ''; + } + if (strlen($line) == 0) { + /* EOF */ + break; + } + $data .= $line; + } + } + + $stat = proc_get_status($proc); + + if ($stat'signaled') { + $data .= "\nTermsig=" . $stat'stopsig' . "\n"; + } + if ($stat"exitcode" > 128 && $stat"exitcode" < 160) { + $data .= "\nTermsig=" . ($stat"exitcode" - 128) . "\n"; + } else if (defined('PHP_WINDOWS_VERSION_MAJOR') && (($stat"exitcode" >> 28) & 0b1111) === 0b1100) { + // https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/87fba13e-bf06-450e-83b1-9241dc81e781 + $data .= "\nTermsig=" . $stat"exitcode" . "\n"; + } + + proc_close($proc); + return $data; +} + +/** + * @param string|array|null $redir_tested + */ +function run_all_tests(array $test_files, array $env, $redir_tested = null): void +{ + global $test_results, $failed_tests_file, $result_tests_file, $php, $test_idx, $file_cache; + global $preload; + // Parallel testing + global $PHP_FAILED_TESTS, $workers, $workerID, $workerSock; + + if ($file_cache !== null || $preload) { + /* Automatically skip opcache tests in --file-cache and --preload mode, + * because opcache generally expects these to run under a default configuration. */ + $test_files = array_filter($test_files, function($test) use($preload) { + if (!is_string($test)) { + return true; + } + if (false !== strpos($test, 'ext/opcache')) { + return false; + } + if ($preload && false !== strpos($test, 'ext/zend_test/tests/observer')) { + return false; + } + return true; + }); + } + + /* Ignore -jN if there is only one file to analyze. */ + if ($workers !== null && count($test_files) > 1 && !$workerID) { + run_all_tests_parallel($test_files, $env, $redir_tested); + return; + } + + foreach ($test_files as $name) { + if (is_array($name)) { + $index = "# $name1: $name0"; + + if ($redir_tested) { + $name = $name0; + } + } elseif ($redir_tested) { + $index = "# $redir_tested: $name"; + } else { + $index = $name; + } + $test_idx++; + + if ($workerID) { + $PHP_FAILED_TESTS = 'BORKED' => , 'FAILED' => , 'WARNED' => , 'LEAKED' => , 'XFAILED' => , 'XLEAKED' => , 'SLOW' => ; + ob_start(); + } + + $result = run_test($php, $name, $env); + if ($workerID) { + $resultText = ob_get_clean(); + } + + if (!is_array($name) && $result != 'REDIR') { + if ($workerID) { + send_message($workerSock, + "type" => "test_result", + "name" => $name, + "index" => $index, + "result" => $result, + "text" => $resultText, + "PHP_FAILED_TESTS" => $PHP_FAILED_TESTS + ); + continue; + } + + $test_results$index = $result; + if ($failed_tests_file && ($result == 'XFAILED' || $result == 'XLEAKED' || $result == 'FAILED' || $result == 'WARNED' || $result == 'LEAKED')) { + fwrite($failed_tests_file, "$index\n"); + } + if ($result_tests_file) { + fwrite($result_tests_file, "$result\t$index\n"); + } + } + } +} + +/** The heart of parallel testing. + * @param string|array|null $redir_tested + */ +function run_all_tests_parallel(array $test_files, array $env, $redir_tested): void +{ + global $workers, $test_idx, $test_cnt, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $SHOW_ONLY_GROUPS, $valgrind; + + global $junit; + + // The PHP binary running run-tests.php, and run-tests.php itself + // This PHP executable is *not* necessarily the same as the tested version + $thisPHP = PHP_BINARY; + $thisScript = __FILE__; + + $workerProcs = ; + $workerSocks = ; + + // Each test may specify a list of conflict keys. While a test that conflicts with + // key K is running, no other test that conflicts with K may run. Conflict keys are + // specified either in the --CONFLICTS-- section, or CONFLICTS file inside a directory. + $dirConflictsWith = ; + $fileConflictsWith = ; + $sequentialTests = ; + foreach ($test_files as $i => $file) { + $contents = file_get_contents($file); + if (preg_match('/^--CONFLICTS--(.+?)^--/ms', $contents, $matches)) { + $conflicts = parse_conflicts($matches1); + } else { + // Cache per-directory conflicts in a separate map, so we compute these only once. + $dir = dirname($file); + if (!isset($dirConflictsWith$dir)) { + $dirConflicts = ; + if (file_exists($dir . '/CONFLICTS')) { + $contents = file_get_contents($dir . '/CONFLICTS'); + $dirConflicts = parse_conflicts($contents); + } + $dirConflictsWith$dir = $dirConflicts; + } + $conflicts = $dirConflictsWith$dir; + } + + // For tests conflicting with "all", no other tests may run in parallel. We'll run these + // tests separately at the end, when only one worker is left. + if (in_array('all', $conflicts, true)) { + $sequentialTests = $file; + unset($test_files$i); + } + + $fileConflictsWith$file = $conflicts; + } + + // Some tests assume that they are executed in a certain order. We will be popping from + // $test_files, so reverse its order here. This makes sure that order is preserved at least + // for tests with a common conflict key. + $test_files = array_reverse($test_files); + + // To discover parallelization issues it is useful to randomize the test order. + if ($shuffle) { + shuffle($test_files); + } + + // Don't start more workers than test files. + $workers = max(1, min($workers, count($test_files))); + + echo "Spawning $workers workers... "; + + // We use sockets rather than STDIN/STDOUT for comms because on Windows, + // those can't be non-blocking for some reason. + $listenSock = stream_socket_server("tcp://127.0.0.1:0") or error("Couldn't create socket on localhost."); + $sockName = stream_socket_get_name($listenSock, false); + // PHP is terrible and returns IPv6 addresses not enclosed by + $portPos = strrpos($sockName, ":"); + $sockHost = substr($sockName, 0, $portPos); + if (false !== strpos($sockHost, ":")) { + $sockHost = "$sockHost"; + } + $sockPort = substr($sockName, $portPos + 1); + $sockUri = "tcp://$sockHost:$sockPort"; + $totalFileCount = count($test_files); + + $startTime = microtime(true); + for ($i = 1; $i <= $workers; $i++) { + $proc = proc_open( + $thisPHP, $thisScript, + , // Inherit our stdin, stdout and stderr + $pipes, + null, + $GLOBALS'environment' + + "TEST_PHP_WORKER" => $i, + "TEST_PHP_URI" => $sockUri, + , + + "suppress_errors" => true, + 'create_new_console' => true, + + ); + if ($proc === false) { + kill_children($workerProcs); + error("Failed to spawn worker $i"); + } + $workerProcs$i = $proc; + } + + for ($i = 1; $i <= $workers; $i++) { + $workerSock = stream_socket_accept($listenSock, 5); + if ($workerSock === false) { + kill_children($workerProcs); + error("Failed to accept connection from worker."); + } + + $greeting = base64_encode(serialize( + "type" => "hello", + "GLOBALS" => $GLOBALS, + "constants" => + "INIT_DIR" => INIT_DIR, + "TEST_PHP_SRCDIR" => TEST_PHP_SRCDIR, + "TRAVIS_CI" => TRAVIS_CI + + )) . "\n"; + + stream_set_timeout($workerSock, 5); + if (fwrite($workerSock, $greeting) === false) { + kill_children($workerProcs); + error("Failed to send greeting to worker."); + } + + $rawReply = fgets($workerSock); + if ($rawReply === false) { + kill_children($workerProcs); + error("Failed to read greeting reply from worker."); + } + + $reply = unserialize(base64_decode($rawReply)); + if (!$reply || $reply"type" !== "hello_reply") { + kill_children($workerProcs); + error("Greeting reply from worker unexpected or could not be decoded: '$rawReply'"); + } + + stream_set_timeout($workerSock, 0); + stream_set_blocking($workerSock, false); + + $workerID = $reply"workerID"; + $workerSocks$workerID = $workerSock; + } + printf("Done in %.2fs\n", microtime(true) - $startTime); + echo "=====================================================================\n"; + echo "\n"; + + $rawMessageBuffers = ; + $testsInProgress = 0; + + // Map from conflict key to worker ID. + $activeConflicts = ; + // Tests waiting due to conflicts. Map from conflict key to array. + $waitingTests = ; + +escape: + while ($test_files || $sequentialTests || $testsInProgress > 0) { + $toRead = array_values($workerSocks); + $toWrite = null; + $toExcept = null; + if (stream_select($toRead, $toWrite, $toExcept, 10)) { + foreach ($toRead as $workerSock) { + $i = array_search($workerSock, $workerSocks); + if ($i === false) { + kill_children($workerProcs); + error("Could not find worker stdout in array of worker stdouts, THIS SHOULD NOT HAPPEN."); + } + while (false !== ($rawMessage = fgets($workerSock))) { + // work around fgets truncating things + if (($rawMessageBuffers$i ?? '') !== '') { + $rawMessage = $rawMessageBuffers$i . $rawMessage; + $rawMessageBuffers$i = ''; + } + if (substr($rawMessage, -1) !== "\n") { + $rawMessageBuffers$i = $rawMessage; + continue; + } + + $message = unserialize(base64_decode($rawMessage)); + if (!$message) { + kill_children($workerProcs); + $stuff = fread($workerSock, 65536); + error("Could not decode message from worker $i: '$rawMessage$stuff'"); + } + + switch ($message"type") { + case "tests_finished": + $testsInProgress--; + foreach ($activeConflicts as $key => $workerId) { + if ($workerId === $i) { + unset($activeConflicts$key); + if (isset($waitingTests$key)) { + while ($test = array_pop($waitingTests$key)) { + $test_files = $test; + } + unset($waitingTests$key); + } + } + } + $junit->mergeResults($message"junit"); + // no break + case "ready": + // Schedule sequential tests only once we are down to one worker. + if (count($workerProcs) === 1 && $sequentialTests) { + $test_files = array_merge($test_files, $sequentialTests); + $sequentialTests = ; + } + // Batch multiple tests to reduce communication overhead. + // - When valgrind is used, communication overhead is relatively small, + // so just use a batch size of 1. + // - If this is running a small enough number of tests, + // reduce the batch size to give batches to more workers. + $files = ; + $maxBatchSize = $valgrind ? 1 : ($shuffle ? 4 : 32); + $averageFilesPerWorker = max(1, (int) ceil($totalFileCount / count($workerProcs))); + $batchSize = min($maxBatchSize, $averageFilesPerWorker); + while (count($files) <= $batchSize && $file = array_pop($test_files)) { + foreach ($fileConflictsWith$file as $conflictKey) { + if (isset($activeConflicts$conflictKey)) { + $waitingTests$conflictKey = $file; + continue 2; + } + } + $files = $file; + } + if ($files) { + foreach ($files as $file) { + foreach ($fileConflictsWith$file as $conflictKey) { + $activeConflicts$conflictKey = $i; + } + } + $testsInProgress++; + send_message($workerSocks$i, + "type" => "run_tests", + "test_files" => $files, + "env" => $env, + "redir_tested" => $redir_tested + ); + } else { + proc_terminate($workerProcs$i); + unset($workerProcs$i); + unset($workerSocks$i); + goto escape; + } + break; + case "test_result": + list($name, $index, $result, $resultText) = $message"name", $message"index", $message"result", $message"text"; + foreach ($message"PHP_FAILED_TESTS" as $category => $tests) { + $PHP_FAILED_TESTS$category = array_merge($PHP_FAILED_TESTS$category, $tests); + } + $test_idx++; + + if (!$SHOW_ONLY_GROUPS) { + clear_show_test(); + } + + echo $resultText; + + if (!$SHOW_ONLY_GROUPS) { + show_test($test_idx, count($workerProcs) . "/$workers concurrent test workers running"); + } + + if (!is_array($name) && $result != 'REDIR') { + $test_results$index = $result; + + if ($failed_tests_file && ($result == 'XFAILED' || $result == 'XLEAKED' || $result == 'FAILED' || $result == 'WARNED' || $result == 'LEAKED')) { + fwrite($failed_tests_file, "$index\n"); + } + if ($result_tests_file) { + fwrite($result_tests_file, "$result\t$index\n"); + } + } + break; + case "error": + kill_children($workerProcs); + error("Worker $i reported error: $messagemsg"); + break; + case "php_error": + kill_children($workerProcs); + $error_consts = + 'E_ERROR', + 'E_WARNING', + 'E_PARSE', + 'E_NOTICE', + 'E_CORE_ERROR', + 'E_CORE_WARNING', + 'E_COMPILE_ERROR', + 'E_COMPILE_WARNING', + 'E_USER_ERROR', + 'E_USER_WARNING', + 'E_USER_NOTICE', + 'E_STRICT', // TODO Cleanup when removed from Zend Engine. + 'E_RECOVERABLE_ERROR', + 'E_DEPRECATED', + 'E_USER_DEPRECATED' + ; + $error_consts = array_combine(array_map('constant', $error_consts), $error_consts); + error("Worker $i reported unexpected {$error_consts$message'errno'}: $messageerrstr in $messageerrfile on line $messageerrline"); + // no break + default: + kill_children($workerProcs); + error("Unrecognised message type '$messagetype' from worker $i"); + } + } + } + } + } + + if (!$SHOW_ONLY_GROUPS) { + clear_show_test(); + } + + kill_children($workerProcs); + + if ($testsInProgress < 0) { + error("$testsInProgress test batches “in progress”, which is less than zero. THIS SHOULD NOT HAPPEN."); + } +} + +function send_message($stream, array $message): void +{ + $blocking = stream_get_meta_data($stream)"blocked"; + stream_set_blocking($stream, true); + fwrite($stream, base64_encode(serialize($message)) . "\n"); + stream_set_blocking($stream, $blocking); +} + +function kill_children(array $children): void +{ + foreach ($children as $child) { + if ($child) { + proc_terminate($child); + } + } +} + +function run_worker(): void +{ + global $workerID, $workerSock; + + global $junit; + + $sockUri = getenv("TEST_PHP_URI"); + + $workerSock = stream_socket_client($sockUri, $_, $_, 5) or error("Couldn't connect to $sockUri"); + + $greeting = fgets($workerSock); + $greeting = unserialize(base64_decode($greeting)) or die("Could not decode greeting\n"); + if ($greeting"type" !== "hello") { + error("Unexpected greeting of type $greetingtype"); + } + + set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) use ($workerSock): bool { + if (error_reporting() & $errno) { + send_message($workerSock, compact('errno', 'errstr', 'errfile', 'errline') + + 'type' => 'php_error' + ); + } + + return true; + }); + + foreach ($greeting"GLOBALS" as $var => $value) { + if ($var !== "workerID" && $var !== "workerSock" && $var !== "GLOBALS") { + $GLOBALS$var = $value; + } + } + foreach ($greeting"constants" as $const => $value) { + define($const, $value); + } + + send_message($workerSock, + "type" => "hello_reply", + "workerID" => $workerID + ); + + send_message($workerSock, + "type" => "ready" + ); + + while (($command = fgets($workerSock))) { + $command = unserialize(base64_decode($command)); + $command"env""TEST_PHP_WORKER" = getenv('TEST_PHP_WORKER'); + + switch ($command"type") { + case "run_tests": + run_all_tests($command"test_files", $command"env", $command"redir_tested"); + send_message($workerSock, + "type" => "tests_finished", + "junit" => $junit->isEnabled() ? $junit : null, + ); + $junit->clear(); + break; + default: + send_message($workerSock, + "type" => "error", + "msg" => "Unrecognised message type: $commandtype" + ); + break 2; + } + } +} + +// +// Show file or result block +// +function show_file_block(string $file, string $block, ?string $section = null): void +{ + global $cfg; + global $colorize; + + if ($cfg'show'$file) { + if (is_null($section)) { + $section = strtoupper($file); + } + if ($section === 'DIFF' && $colorize) { + // '-' is Light Red for removal, '+' is Light Green for addition + $block = preg_replace('/^0-9+\-\s.*$/m', "\e1;31m\\0\e0m", $block); + $block = preg_replace('/^0-9+\+\s.*$/m', "\e1;32m\\0\e0m", $block); + } + + echo "\n========" . $section . "========\n"; + echo rtrim($block); + echo "\n========DONE========\n"; + } +} + +function skip_test(string $tested, string $tested_file, string $shortname, string $reason) { + global $junit; + + show_result('SKIP', $tested, $tested_file, "reason: $reason"); + $junit->initSuite($junit->getSuiteName($shortname)); + $junit->markTestAs('SKIP', $shortname, $tested, 0, $reason); + return 'SKIPPED'; +} + +// +// Run an individual test case. +// +/** + * @param string|array $file + */ +function run_test(string $php, $file, array $env): string +{ + global $log_format, $ini_overwrites, $PHP_FAILED_TESTS; + global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx; + global $valgrind, $temp_source, $temp_target, $cfg, $environment; + global $no_clean; + global $SHOW_ONLY_GROUPS; + global $no_file_cache; + global $slow_min_ms; + global $preload, $file_cache; + global $num_repeats; + // Parallel testing + global $workerID; + + // Temporary + /** @var JUnit */ + global $junit; + + static $skipCache; + if (!$skipCache) { + $enableSkipCache = !($env'DISABLE_SKIP_CACHE' ?? '0'); + $skipCache = new SkipCache($enableSkipCache, $cfg'keep''skip'); + } + + $temp_filenames = null; + $org_file = $file; + $orig_php = $php; + + $php_cgi = $env'TEST_PHP_CGI_EXECUTABLE' ?? null; + $phpdbg = $env'TEST_PHPDBG_EXECUTABLE' ?? null; + + if (is_array($file)) { + $file = $file0; + } + + if ($DETAILED) { + echo " +================= +TEST $file +"; + } + + $shortname = str_replace(TEST_PHP_SRCDIR . '/', '', $file); + $tested_file = $shortname; + + try { + $test = new TestFile($file, (bool)$IN_REDIRECT); + } catch (BorkageException $ex) { + show_result("BORK", $ex->getMessage(), $tested_file); + $PHP_FAILED_TESTS'BORKED' = + 'name' => $file, + 'test_name' => '', + 'output' => '', + 'diff' => '', + 'info' => "{$ex->getMessage()} $file", + ; + + $junit->markTestAs('BORK', $shortname, $tested_file, 0, $ex->getMessage()); + return 'BORKED'; + } + + $tested = $test->getName(); + + if ($num_repeats > 1 && $test->hasSection('FILE_EXTERNAL')) { + return skip_test($tested, $tested_file, $shortname, 'Test with FILE_EXTERNAL might not be repeatable'); + } + + if ($test->hasSection('CAPTURE_STDIO')) { + $capture = $test->getSection('CAPTURE_STDIO'); + $captureStdIn = stripos($capture, 'STDIN') !== false; + $captureStdOut = stripos($capture, 'STDOUT') !== false; + $captureStdErr = stripos($capture, 'STDERR') !== false; + } else { + $captureStdIn = true; + $captureStdOut = true; + $captureStdErr = true; + } + if ($captureStdOut && $captureStdErr) { + $cmdRedirect = ' 2>&1'; + } else { + $cmdRedirect = ''; + } + + /* For GET/POST/PUT tests, check if cgi sapi is available and if it is, use it. */ + if ($test->isCGI()) { + if (!$php_cgi) { + return skip_test($tested, $tested_file, $shortname, 'CGI not available'); + } + $php = $php_cgi . ' -C '; + $uses_cgi = true; + if ($num_repeats > 1) { + return skip_test($tested, $tested_file, $shortname, 'CGI does not support --repeat'); + } + } + + /* For phpdbg tests, check if phpdbg sapi is available and if it is, use it. */ + $extra_options = ''; + if ($test->hasSection('PHPDBG')) { + if (isset($phpdbg)) { + $php = $phpdbg . ' -qIb'; + + // Additional phpdbg command line options for sections that need to + // be run straight away. For example, EXTENSIONS, SKIPIF, CLEAN. + $extra_options = '-rr'; + } else { + return skip_test($tested, $tested_file, $shortname, 'phpdbg not available'); + } + if ($num_repeats > 1) { + return skip_test($tested, $tested_file, $shortname, 'phpdbg does not support --repeat'); + } + } + + if ($num_repeats > 1) { + if ($test->hasSection('CLEAN')) { + return skip_test($tested, $tested_file, $shortname, 'Test with CLEAN might not be repeatable'); + } + if ($test->hasSection('STDIN')) { + return skip_test($tested, $tested_file, $shortname, 'Test with STDIN might not be repeatable'); + } + if ($test->hasSection('CAPTURE_STDIO')) { + return skip_test($tested, $tested_file, $shortname, 'Test with CAPTURE_STDIO might not be repeatable'); + } + } + + if (!$SHOW_ONLY_GROUPS && !$workerID) { + show_test($test_idx, $shortname); + } + + if (is_array($IN_REDIRECT)) { + $temp_dir = $test_dir = $IN_REDIRECT'dir'; + } else { + $temp_dir = $test_dir = realpath(dirname($file)); + } + + if ($temp_source && $temp_target) { + $temp_dir = str_replace($temp_source, $temp_target, $temp_dir); + } + + $main_file_name = basename($file, 'phpt'); + + $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'diff'; + $log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'log'; + $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'exp'; + $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'out'; + $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'mem'; + $sh_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'sh'; + $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; + $test_file = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'php'; + $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; + $test_skipif = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'skip.php'; + $temp_after = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'after.php'; + $test_after = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'after.php'; + $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; + $test_clean = $test_dir . DIRECTORY_SEPARATOR . $main_file_name . 'clean.php'; + $preload_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'preload.php'; + $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name . 'post'; + $tmp_relative_file = str_replace(__DIR__ . DIRECTORY_SEPARATOR, '', $test_file) . 't'; + + if ($temp_source && $temp_target) { + $temp_skipif .= 's'; + $temp_file .= 's'; + $temp_clean .= 's'; + $copy_file = $temp_dir . DIRECTORY_SEPARATOR . basename(is_array($file) ? $file1 : $file) . '.phps'; + + if (!is_dir(dirname($copy_file))) { + mkdir(dirname($copy_file), 0777, true) or error("Cannot create output directory - " . dirname($copy_file)); + } + + if ($test->hasSection('FILE')) { + save_text($copy_file, $test->getSection('FILE')); + } + + $temp_filenames = + 'file' => $copy_file, + 'diff' => $diff_filename, + 'log' => $log_filename, + 'exp' => $exp_filename, + 'out' => $output_filename, + 'mem' => $memcheck_filename, + 'sh' => $sh_filename, + 'php' => $temp_file, + 'skip' => $temp_skipif, + 'after' => $temp_after, + 'clean' => $temp_clean + ; + } + + if (is_array($IN_REDIRECT)) { + $tested = $IN_REDIRECT'prefix' . ' ' . $tested; + $tested_file = $tmp_relative_file; + $shortname = str_replace(TEST_PHP_SRCDIR . '/', '', $tested_file); + } + + // unlink old test results + @unlink($diff_filename); + @unlink($log_filename); + @unlink($exp_filename); + @unlink($output_filename); + @unlink($memcheck_filename); + @unlink($sh_filename); + @unlink($temp_file); + @unlink($test_file); + @unlink($temp_skipif); + @unlink($test_skipif); + @unlink($tmp_post); + @unlink($temp_after); + @unlink($test_after); + @unlink($temp_clean); + @unlink($test_clean); + @unlink($preload_filename); + + // Reset environment from any previous test. + $env'REDIRECT_STATUS' = ''; + $env'QUERY_STRING' = ''; + $env'PATH_TRANSLATED' = ''; + $env'SCRIPT_FILENAME' = ''; + $env'REQUEST_METHOD' = ''; + $env'CONTENT_TYPE' = ''; + $env'CONTENT_LENGTH' = ''; + $env'TZ' = ''; + + if ($test->sectionNotEmpty('ENV')) { + $env_str = str_replace('{PWD}', dirname($file), $test->getSection('ENV')); + foreach (explode("\n", $env_str) as $e) { + $e = explode('=', trim($e), 2); + + if (!empty($e0) && isset($e1)) { + $env$e0 = $e1; + } + } + } + + // Default ini settings + $ini_settings = $workerID ? 'opcache.cache_id' => "worker$workerID" : ; + + // Additional required extensions + $extensions = ; + if ($test->hasSection('EXTENSIONS')) { + $extensions = preg_split("/\n\r+/", trim($test->getSection('EXTENSIONS'))); + } + if (is_array($IN_REDIRECT) && $IN_REDIRECT'EXTENSIONS' != ) { + $extensions = array_merge($extensions, $IN_REDIRECT'EXTENSIONS'); + } + + /* Load required extensions */ + if ($extensions != ) { + $ext_params = ; + settings2array($ini_overwrites, $ext_params); + $ext_params = settings2params($ext_params); + $ext_dir, $loaded = $skipCache->getExtensions("$orig_php $pass_options $extra_options $ext_params $no_file_cache"); + $ext_prefix = IS_WINDOWS ? "php_" : ""; + $missing = ; + foreach ($extensions as $req_ext) { + if (!in_array(strtolower($req_ext), $loaded)) { + if ($req_ext == 'opcache' || $req_ext == 'xdebug') { + $ext_file = $ext_dir . DIRECTORY_SEPARATOR . $ext_prefix . $req_ext . '.' . PHP_SHLIB_SUFFIX; + $ini_settings'zend_extension' = $ext_file; + } else { + $ext_file = $ext_dir . DIRECTORY_SEPARATOR . $ext_prefix . $req_ext . '.' . PHP_SHLIB_SUFFIX; + $ini_settings'extension' = $ext_file; + } + if (!is_readable($ext_file)) { + $missing = $req_ext; + } + } + } + if ($missing) { + $message = 'Required extension' . (count($missing) > 1 ? 's' : '') + . ' missing: ' . implode(', ', $missing); + return skip_test($tested, $tested_file, $shortname, $message); + } + } + + // additional ini overwrites + //$ini_overwrites = 'setting=value'; + settings2array($ini_overwrites, $ini_settings); + + if (getenv('OPCACHE') !== false) { + if (getenv('OPCACHE') == 'yes') { + $ini_settings'opcache.enable' = 1; + $ini_settings'opcache.enable_cli' = 1; + $ini_settings'opcache.optimization_level' = -1; + } else { + $ini_settings'opcache.enable' = 0; + $ini_settings'opcache.enable_cli' = 0; + $ini_settings'opcache.optimization_level' = 0; + } + } + + $orig_ini_settings = settings2params($ini_settings); + + if ($file_cache !== null) { + $ini_settings'opcache.file_cache' = '/tmp'; + // Make sure warnings still show up on the second run. + $ini_settings'opcache.record_warnings' = '1'; + // File cache is currently incompatible with JIT. + $ini_settings'opcache.jit' = '0'; + if ($file_cache === 'use') { + // Disable timestamp validation in order to fetch from file cache, + // even though all the files are re-created. + $ini_settings'opcache.validate_timestamps' = '0'; + } + } else if ($num_repeats > 1) { + // Make sure warnings still show up on the second run. + $ini_settings'opcache.record_warnings' = '1'; + } + + // Any special ini settings + // these may overwrite the test defaults... + if ($test->hasSection('INI')) { + $ini = str_replace('{PWD}', dirname($file), $test->getSection('INI')); + $ini = str_replace('{RUNID}', getenv('UNIQ_RUN_ID'), $ini); + $ini = str_replace('{TEST_PHP_WORKER}', getenv('TEST_PHP_WORKER'), $ini); + $ini = str_replace('{TMP}', sys_get_temp_dir(), $ini); + $replacement = IS_WINDOWS ? '"' . PHP_BINARY . ' -r \"while ($in = fgets(STDIN)) echo $in;\" > $1"' : 'tee $1 >/dev/null'; + $ini = preg_replace('/{MAIL:(\S+)}/', $replacement, $ini); + settings2array(preg_split("/\n\r+/", $ini), $ini_settings); + + if ($num_repeats > 1 && isset($ini_settings'opcache.opt_debug_level')) { + return skip_test($tested, $tested_file, $shortname, 'opt_debug_level tests are not repeatable'); + } + } + + $ini_settings = settings2params($ini_settings); + + $env'TEST_PHP_EXTRA_ARGS' = $pass_options . ' ' . $ini_settings; + + // Check if test should be skipped. + $info = ''; + $warn = false; + + if ($test->sectionNotEmpty('SKIPIF')) { + show_file_block('skip', $test->getSection('SKIPIF')); + $extra = !IS_WINDOWS ? + "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; + + if ($valgrind) { + $env'USE_ZEND_ALLOC' = '0'; + $env'ZEND_DONT_UNLOAD_MODULES' = 1; + } + + if (!array_key_exists('XDEBUG_MODE', $env)) { + $env'XDEBUG_MODE' = ""; + } + + /* Remove auto prepend and append settings for SKIPIF */ + $skipif_ini_settings = $orig_ini_settings; + $skipif_ini_settings = preg_replace( '@-d \"auto_prepend_file=.*?\" @', '', $skipif_ini_settings ); + $skipif_ini_settings = preg_replace( '@-d \"auto_append_file=.*?\" @', '', $skipif_ini_settings ); + $skipif_ini_settings = preg_replace( '@-d \"xdebug\.log=.*?\" @', '', $skipif_ini_settings ); + $skipif_ini_settings .= " -d track_errors=0 -d xdebug.mode=off"; + + $junit->startTimer($shortname); + + $startTime = microtime(true); + $commandLine = "$extra $php $pass_options $extra_options -q $skipif_ini_settings $no_file_cache -d display_errors=1 -d display_startup_errors=0"; + $output = $skipCache->checkSkip($commandLine, $test->getSection('SKIPIF'), $test_skipif, $temp_skipif, $env); + + $time = microtime(true) - $startTime; + $junit->stopTimer($shortname); + + if ($time > $slow_min_ms / 1000) { + $PHP_FAILED_TESTS'SLOW' = + 'name' => $file, + 'test_name' => 'SKIPIF of ' . $tested . " $tested_file", + 'output' => '', + 'diff' => '', + 'info' => $time, + ; + } + + if (!$cfg'keep''skip') { + @unlink($test_skipif); + } + + if (!strncasecmp('skip', $output, 4)) { + if (preg_match('/^skip\s*(.+)/i', $output, $m)) { + show_result('SKIP', $tested, $tested_file, "reason: $m1", $temp_filenames); + } else { + show_result('SKIP', $tested, $tested_file, '', $temp_filenames); + } + + $message = !empty($m1) ? $m1 : ''; + $junit->markTestAs('SKIP', $shortname, $tested, null, $message); + return 'SKIPPED'; + } + + + if (!strncasecmp('info', $output, 4) && preg_match('/^info\s*(.+)/i', $output, $m)) { + $info = " (info: $m1)"; + } elseif (!strncasecmp('warn', $output, 4) && preg_match('/^warn\s+(.+)/i', $output, $m)) { + $warn = true; /* only if there is a reason */ + $info = " (warn: $m1)"; + } elseif (!strncasecmp('xfail', $output, 5)) { + // Pretend we have an XFAIL section + $test->setSection('XFAIL', ltrim(substr($output, 5))); + } elseif ($output !== '') { + show_result("BORK", $output, $tested_file, 'reason: invalid output from SKIPIF', $temp_filenames); + $PHP_FAILED_TESTS'BORKED' = + 'name' => $file, + 'test_name' => '', + 'output' => '', + 'diff' => '', + 'info' => "$output $file", + ; + + $junit->markTestAs('BORK', $shortname, $tested, null, $output); + return 'BORKED'; + } + } + + if (!extension_loaded("zlib") && $test->hasAnySections("GZIP_POST", "DEFLATE_POST")) { + $message = "ext/zlib required"; + show_result('SKIP', $tested, $tested_file, "reason: $message", $temp_filenames); + $junit->markTestAs('SKIP', $shortname, $tested, null, $message); + return 'SKIPPED'; + } + + if ($test->hasSection('REDIRECTTEST')) { + $test_files = ; + + $IN_REDIRECT = eval($test->getSection('REDIRECTTEST')); + $IN_REDIRECT'via' = "via $shortname\n\t"; + $IN_REDIRECT'dir' = realpath(dirname($file)); + $IN_REDIRECT'prefix' = $tested; + $IN_REDIRECT'EXTENSIONS' = $extensions; + + if (!empty($IN_REDIRECT'TESTS')) { + if (is_array($org_file)) { + $test_files = $org_file1; + } else { + $GLOBALS'test_files' = $test_files; + find_files($IN_REDIRECT'TESTS'); + + foreach ($GLOBALS'test_files' as $f) { + $test_files = $f, $file; + } + } + $test_cnt += count($test_files) - 1; + $test_idx--; + + show_redirect_start($IN_REDIRECT'TESTS', $tested, $tested_file); + + // set up environment + $redirenv = array_merge($environment, $IN_REDIRECT'ENV'); + $redirenv'REDIR_TEST_DIR' = realpath($IN_REDIRECT'TESTS') . DIRECTORY_SEPARATOR; + + usort($test_files, "test_sort"); + run_all_tests($test_files, $redirenv, $tested); + + show_redirect_ends($IN_REDIRECT'TESTS', $tested, $tested_file); + + // a redirected test never fails + $IN_REDIRECT = false; + + $junit->markTestAs('PASS', $shortname, $tested); + return 'REDIR'; + } else { + $bork_info = "Redirect info must contain exactly one TEST string to be used as redirect directory."; + show_result("BORK", $bork_info, '', '', $temp_filenames); + $PHP_FAILED_TESTS'BORKED' = + 'name' => $file, + 'test_name' => '', + 'output' => '', + 'diff' => '', + 'info' => "$bork_info $file", + ; + } + } + + if (is_array($org_file) || $test->hasSection('REDIRECTTEST')) { + if (is_array($org_file)) { + $file = $org_file0; + } + + $bork_info = "Redirected test did not contain redirection info"; + show_result("BORK", $bork_info, '', '', $temp_filenames); + $PHP_FAILED_TESTS'BORKED' = + 'name' => $file, + 'test_name' => '', + 'output' => '', + 'diff' => '', + 'info' => "$bork_info $file", + ; + + $junit->markTestAs('BORK', $shortname, $tested, null, $bork_info); + + return 'BORKED'; + } + + // We've satisfied the preconditions - run the test! + if ($test->hasSection('FILE')) { + show_file_block('php', $test->getSection('FILE'), 'TEST'); + save_text($test_file, $test->getSection('FILE'), $temp_file); + } else { + $test_file = $temp_file = ""; + } + + if ($test->hasSection('GET')) { + $query_string = trim($test->getSection('GET')); + } else { + $query_string = ''; + } + + $env'REDIRECT_STATUS' = '1'; + if (empty($env'QUERY_STRING')) { + $env'QUERY_STRING' = $query_string; + } + if (empty($env'PATH_TRANSLATED')) { + $env'PATH_TRANSLATED' = $test_file; + } + if (empty($env'SCRIPT_FILENAME')) { + $env'SCRIPT_FILENAME' = $test_file; + } + + if ($test->hasSection('COOKIE')) { + $env'HTTP_COOKIE' = trim($test->getSection('COOKIE')); + } else { + $env'HTTP_COOKIE' = ''; + } + + $args = $test->hasSection('ARGS') ? ' -- ' . $test->getSection('ARGS') : ''; + + if ($preload && !empty($test_file)) { + save_text($preload_filename, "<?php opcache_compile_file('$test_file');"); + $local_pass_options = $pass_options; + unset($pass_options); + $pass_options = $local_pass_options; + $pass_options .= " -d opcache.preload=" . $preload_filename; + } + + if ($test->sectionNotEmpty('POST_RAW')) { + $post = trim($test->getSection('POST_RAW')); + $raw_lines = explode("\n", $post); + + $request = ''; + $started = false; + + foreach ($raw_lines as $line) { + if (empty($env'CONTENT_TYPE') && preg_match('/^Content-Type:(.*)/i', $line, $res)) { + $env'CONTENT_TYPE' = trim(str_replace("\r", '', $res1)); + continue; + } + + if ($started) { + $request .= "\n"; + } + + $started = true; + $request .= $line; + } + + $env'CONTENT_LENGTH' = strlen($request); + $env'REQUEST_METHOD' = 'POST'; + + if (empty($request)) { + $junit->markTestAs('BORK', $shortname, $tested, null, 'empty $request'); + return 'BORKED'; + } + + save_text($tmp_post, $request); + $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\""; + } elseif ($test->sectionNotEmpty('PUT')) { + $post = trim($test->getSection('PUT')); + $raw_lines = explode("\n", $post); + + $request = ''; + $started = false; + + foreach ($raw_lines as $line) { + if (empty($env'CONTENT_TYPE') && preg_match('/^Content-Type:(.*)/i', $line, $res)) { + $env'CONTENT_TYPE' = trim(str_replace("\r", '', $res1)); + continue; + } + + if ($started) { + $request .= "\n"; + } + + $started = true; + $request .= $line; + } + + $env'CONTENT_LENGTH' = strlen($request); + $env'REQUEST_METHOD' = 'PUT'; + + if (empty($request)) { + $junit->markTestAs('BORK', $shortname, $tested, null, 'empty $request'); + return 'BORKED'; + } + + save_text($tmp_post, $request); + $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\""; + } elseif ($test->sectionNotEmpty('POST')) { + $post = trim($test->getSection('POST')); + $content_length = strlen($post); + save_text($tmp_post, $post); + + $env'REQUEST_METHOD' = 'POST'; + if (empty($env'CONTENT_TYPE')) { + $env'CONTENT_TYPE' = 'application/x-www-form-urlencoded'; + } + + if (empty($env'CONTENT_LENGTH')) { + $env'CONTENT_LENGTH' = $content_length; + } + + $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\""; + } elseif ($test->sectionNotEmpty('GZIP_POST')) { + $post = trim($test->getSection('GZIP_POST')); + $post = gzencode($post, 9, FORCE_GZIP); + $env'HTTP_CONTENT_ENCODING' = 'gzip'; + + save_text($tmp_post, $post); + $content_length = strlen($post); + + $env'REQUEST_METHOD' = 'POST'; + $env'CONTENT_TYPE' = 'application/x-www-form-urlencoded'; + $env'CONTENT_LENGTH' = $content_length; + + $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\""; + } elseif ($test->sectionNotEmpty('DEFLATE_POST')) { + $post = trim($test->getSection('DEFLATE_POST')); + $post = gzcompress($post, 9); + $env'HTTP_CONTENT_ENCODING' = 'deflate'; + save_text($tmp_post, $post); + $content_length = strlen($post); + + $env'REQUEST_METHOD' = 'POST'; + $env'CONTENT_TYPE' = 'application/x-www-form-urlencoded'; + $env'CONTENT_LENGTH' = $content_length; + + $cmd = "$php $pass_options $ini_settings -f \"$test_file\"$cmdRedirect < \"$tmp_post\""; + } else { + $env'REQUEST_METHOD' = 'GET'; + $env'CONTENT_TYPE' = ''; + $env'CONTENT_LENGTH' = ''; + + $repeat_option = $num_repeats > 1 ? "--repeat $num_repeats" : ""; + $cmd = "$php $pass_options $repeat_option $ini_settings -f \"$test_file\" $args$cmdRedirect"; + } + + $orig_cmd = $cmd; + if ($valgrind) { + $env'USE_ZEND_ALLOC' = '0'; + $env'ZEND_DONT_UNLOAD_MODULES' = 1; + + $cmd = $valgrind->wrapCommand($cmd, $memcheck_filename, strpos($test_file, "pcre") !== false); + } + + if (!array_key_exists('XDEBUG_MODE', $env)) { + $env'XDEBUG_MODE' = ""; + } + + if ($DETAILED) { + echo " +CONTENT_LENGTH = " . $env'CONTENT_LENGTH' . " +CONTENT_TYPE = " . $env'CONTENT_TYPE' . " +PATH_TRANSLATED = " . $env'PATH_TRANSLATED' . " +QUERY_STRING = " . $env'QUERY_STRING' . " +REDIRECT_STATUS = " . $env'REDIRECT_STATUS' . " +REQUEST_METHOD = " . $env'REQUEST_METHOD' . " +SCRIPT_FILENAME = " . $env'SCRIPT_FILENAME' . " +HTTP_COOKIE = " . $env'HTTP_COOKIE' . " +COMMAND $cmd +"; + } + + $junit->startTimer($shortname); + $hrtime = hrtime(); + $startTime = $hrtime0 * 1000000000 + $hrtime1; + + $stdin = $test->hasSection('STDIN') ? $test->getSection('STDIN') : null; + $out = system_with_timeout($cmd, $env, $stdin, $captureStdIn, $captureStdOut, $captureStdErr); + + $junit->stopTimer($shortname); + $hrtime = hrtime(); + $time = $hrtime0 * 1000000000 + $hrtime1 - $startTime; + if ($time >= $slow_min_ms * 1000000) { + $PHP_FAILED_TESTS'SLOW' = + 'name' => $file, + 'test_name' => $tested . " $tested_file", + 'output' => '', + 'diff' => '', + 'info' => $time / 1000000000, + ; + } + + // Things to run after the test (like, final) + if ($test->sectionNotEmpty('AFTER')) { + show_file_block('after', $test->getSection('AFTER')); + save_text($test_clean, trim($test->getSection('AFTER')), $temp_clean); + + $extra = !IS_WINDOWS ? + "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; + $out .= system_with_timeout("$extra $orig_php $pass_options -q $orig_ini_settings $no_file_cache \"$test_clean\"", $env); + } + + // Remember CLEAN output to report borked test if it otherwise passes. + $clean_output = null; + if ($test->sectionNotEmpty('CLEAN') && (!$no_clean || $cfg'keep''clean')) { + show_file_block('clean', $test->getSection('CLEAN')); + save_text($test_clean, trim($test->getSection('CLEAN')), $temp_clean); + + if (!$no_clean) { + $extra = !IS_WINDOWS ? + "unset REQUEST_METHOD; unset QUERY_STRING; unset PATH_TRANSLATED; unset SCRIPT_FILENAME; unset REQUEST_METHOD;" : ""; + $clean_output = system_with_timeout("$extra $orig_php $pass_options -q $orig_ini_settings $no_file_cache \"$test_clean\"", $env); + } + + if (!$cfg'keep''clean') { + @unlink($test_clean); + } + } + + $leaked = false; + $passed = false; + + if ($valgrind) { // leak check + $leaked = filesize($memcheck_filename) > 0; + + if (!$leaked) { + @unlink($memcheck_filename); + } + } + + if ($num_repeats > 1) { + // In repeat mode, retain the output before the first execution, + // and of the last execution. Do this early, because the trimming below + // makes the newline handling complicated. + $separator1 = "Executing for the first time...\n"; + $separator1_pos = strpos($out, $separator1); + if ($separator1_pos !== false) { + $separator2 = "Finished execution, repeating...\n"; + $separator2_pos = strrpos($out, $separator2); + if ($separator2_pos !== false) { + $out = substr($out, 0, $separator1_pos) + . substr($out, $separator2_pos + strlen($separator2)); + } else { + $out = substr($out, 0, $separator1_pos) + . substr($out, $separator1_pos + strlen($separator1)); + } + } + } + + // Does the output match what is expected? + $output = preg_replace("/\r\n/", "\n", trim($out)); + + /* when using CGI, strip the headers from the output */ + $headers = ; + + if (!empty($uses_cgi) && preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $out, $match)) { + $output = trim($match2); + $rh = preg_split("/\n\r+/", $match1); + + foreach ($rh as $line) { + if (strpos($line, ':') !== false) { + $line = explode(':', $line, 2); + $headerstrim($line0) = trim($line1); + } + } + } + + $wanted_headers = null; + $output_headers = null; + $failed_headers = false; + + if ($test->hasSection('EXPECTHEADERS')) { + $want = ; + $wanted_headers = ; + $lines = preg_split("/\n\r+/", $test->getSection('EXPECTHEADERS')); + + foreach ($lines as $line) { + if (strpos($line, ':') !== false) { + $line = explode(':', $line, 2); + $wanttrim($line0) = trim($line1); + $wanted_headers = trim($line0) . ': ' . trim($line1); + } + } + + $output_headers = ; + + foreach ($want as $k => $v) { + if (isset($headers$k)) { + $output_headers = $k . ': ' . $headers$k; + } + + if (!isset($headers$k) || $headers$k != $v) { + $failed_headers = true; + } + } + + ksort($wanted_headers); + $wanted_headers = implode("\n", $wanted_headers); + ksort($output_headers); + $output_headers = implode("\n", $output_headers); + } + + show_file_block('out', $output); + + if ($preload) { + $output = trim(preg_replace("/\n?Warning: Can't preload ^\n*\n?/", "", $output)); + } + + if ($test->hasAnySections('EXPECTF', 'EXPECTREGEX')) { + if ($test->hasSection('EXPECTF')) { + $wanted = trim($test->getSection('EXPECTF')); + } else { + $wanted = trim($test->getSection('EXPECTREGEX')); + } + + show_file_block('exp', $wanted); + $wanted_re = preg_replace('/\r\n/', "\n", $wanted); + + if ($test->hasSection('EXPECTF')) { + // do preg_quote, but miss out any %r delimited sections + $temp = ""; + $r = "%r"; + $startOffset = 0; + $length = strlen($wanted_re); + while ($startOffset < $length) { + $start = strpos($wanted_re, $r, $startOffset); + if ($start !== false) { + // we have found a start tag + $end = strpos($wanted_re, $r, $start + 2); + if ($end === false) { + // unbalanced tag, ignore it. + $end = $start = $length; + } + } else { + // no more %r sections + $start = $end = $length; + } + // quote a non re portion of the string + $temp .= preg_quote(substr($wanted_re, $startOffset, $start - $startOffset), '/'); + // add the re unquoted. + if ($end > $start) { + $temp .= '(' . substr($wanted_re, $start + 2, $end - $start - 2) . ')'; + } + $startOffset = $end + 2; + } + $wanted_re = $temp; + + // Stick to basics + $wanted_re = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $wanted_re); + $wanted_re = str_replace('%s', '^\r\n+', $wanted_re); + $wanted_re = str_replace('%S', '^\r\n*', $wanted_re); + $wanted_re = str_replace('%a', '.+', $wanted_re); + $wanted_re = str_replace('%A', '.*', $wanted_re); + $wanted_re = str_replace('%w', '\s*', $wanted_re); + $wanted_re = str_replace('%i', '+-?\d+', $wanted_re); + $wanted_re = str_replace('%d', '\d+', $wanted_re); + $wanted_re = str_replace('%x', '0-9a-fA-F+', $wanted_re); + $wanted_re = str_replace('%f', '+-?\.?\d+\.?\d*(?:Ee+-?\d+)?', $wanted_re); + $wanted_re = str_replace('%c', '.', $wanted_re); + $wanted_re = str_replace('%0', '\x00', $wanted_re); + // %f allows two points "-.0.0" but that is the best *simple* expression + } + + if (preg_match("/^$wanted_re\$/s", $output)) { + $passed = true; + } + } else { + $wanted = trim($test->getSection('EXPECT')); + $wanted = preg_replace('/\r\n/', "\n", $wanted); + show_file_block('exp', $wanted); + + // compare and leave on success + if (!strcmp($output, $wanted)) { + $passed = true; + } + + $wanted_re = null; + } + + if ($passed) { + if (!$cfg'keep''php' && !$leaked) { + @unlink($test_file); + @unlink($preload_filename); + } + @unlink($tmp_post); + + if (!$leaked && !$failed_headers) { + // If the test passed and CLEAN produced output, report test as borked. + if ($clean_output) { + show_result("BORK", $output, $tested_file, 'reason: invalid output from CLEAN', $temp_filenames); + $PHP_FAILED_TESTS'BORKED' = + 'name' => $file, + 'test_name' => '', + 'output' => '', + 'diff' => '', + 'info' => "$clean_output $file", + ; + + $junit->markTestAs('BORK', $shortname, $tested, null, $clean_output); + return 'BORKED'; + } + + if ($test->hasSection('XFAIL')) { + $warn = true; + $info = " (warn: XFAIL section but test passes)"; + } elseif ($test->hasSection('XLEAK')) { + $warn = true; + $info = " (warn: XLEAK section but test passes)"; + } else { + show_result("PASS", $tested, $tested_file, '', $temp_filenames); + $junit->markTestAs('PASS', $shortname, $tested); + return 'PASSED'; + } + } + } + + // Test failed so we need to report details. + if ($failed_headers) { + $passed = false; + $wanted = $wanted_headers . "\n--HEADERS--\n" . $wanted; + $output = $output_headers . "\n--HEADERS--\n" . $output; + + if (isset($wanted_re)) { + $wanted_re = preg_quote($wanted_headers . "\n--HEADERS--\n", '/') . $wanted_re; + } + } + + $restype = ; + + if ($leaked) { + $restype = $test->hasSection('XLEAK') ? + 'XLEAK' : 'LEAK'; + } + + if ($warn) { + $restype = 'WARN'; + } + + if (!$passed) { + if ($test->hasSection('XFAIL')) { + $restype = 'XFAIL'; + $info = ' XFAIL REASON: ' . rtrim($test->getSection('XFAIL')); + } elseif ($test->hasSection('XLEAK')) { + $restype = 'XLEAK'; + $info = ' XLEAK REASON: ' . rtrim($test->getSection('XLEAK')); + } else { + $restype = 'FAIL'; + } + } + + if (!$passed) { + // write .exp + if (strpos($log_format, 'E') !== false && file_put_contents($exp_filename, $wanted) === false) { + error("Cannot create expected test output - $exp_filename"); + } + + // write .out + if (strpos($log_format, 'O') !== false && file_put_contents($output_filename, $output) === false) { + error("Cannot create test output - $output_filename"); + } + + // write .diff + $diff = generate_diff($wanted, $wanted_re, $output); + if (is_array($IN_REDIRECT)) { + $orig_shortname = str_replace(TEST_PHP_SRCDIR . '/', '', $file); + $diff = "# original source file: $orig_shortname\n" . $diff; + } + show_file_block('diff', $diff); + if (strpos($log_format, 'D') !== false && file_put_contents($diff_filename, $diff) === false) { + error("Cannot create test diff - $diff_filename"); + } + + // write .log + if (strpos($log_format, 'L') !== false && file_put_contents($log_filename, " +---- EXPECTED OUTPUT +$wanted +---- ACTUAL OUTPUT +$output +---- FAILED +") === false) { + error("Cannot create test log - $log_filename"); + error_report($file, $log_filename, $tested); + } + } + + if (!$passed || $leaked) { + // write .sh + if (strpos($log_format, 'S') !== false) { + $env_lines = ; + foreach ($env as $env_var => $env_val) { + $env_lines = "export $env_var=" . escapeshellarg($env_val ?? ""); + } + $exported_environment = $env_lines ? "\n" . implode("\n", $env_lines) . "\n" : ""; + $sh_script = <<<SH +#!/bin/sh +{$exported_environment} +case "$1" in +"gdb") + gdb --args {$orig_cmd} + ;; +"lldb") + lldb -- {$orig_cmd} + ;; +"valgrind") + USE_ZEND_ALLOC=0 valgrind $2 {$orig_cmd} + ;; +"rr") + rr record $2 {$orig_cmd} + ;; +*) + {$orig_cmd} + ;; +esac +SH; + if (file_put_contents($sh_filename, $sh_script) === false) { + error("Cannot create test shell script - $sh_filename"); + } + chmod($sh_filename, 0755); + } + } + + if ($valgrind && $leaked && $cfg"show""mem") { + show_file_block('mem', file_get_contents($memcheck_filename)); + } + + show_result(implode('&', $restype), $tested, $tested_file, $info, $temp_filenames); + + foreach ($restype as $type) { + $PHP_FAILED_TESTS$type . 'ED' = + 'name' => $file, + 'test_name' => (is_array($IN_REDIRECT) ? $IN_REDIRECT'via' : '') . $tested . " $tested_file", + 'output' => $output_filename, + 'diff' => $diff_filename, + 'info' => $info, + ; + } + + $diff = empty($diff) ? '' : preg_replace('/\e/', '<esc>', $diff); + + $junit->markTestAs($restype, $shortname, $tested, null, $info, $diff); + + return $restype0 . 'ED'; +} + +/** + * @return bool|int + */ +function comp_line(string $l1, string $l2, bool $is_reg) +{ + if ($is_reg) { + return preg_match('/^' . $l1 . '$/s', $l2); + } else { + return !strcmp($l1, $l2); + } +} + +function count_array_diff( + array $ar1, + array $ar2, + bool $is_reg, + array $w, + int $idx1, + int $idx2, + int $cnt1, + int $cnt2, + int $steps +): int { + $equal = 0; + + while ($idx1 < $cnt1 && $idx2 < $cnt2 && comp_line($ar1$idx1, $ar2$idx2, $is_reg)) { + $idx1++; + $idx2++; + $equal++; + $steps--; + } + if (--$steps > 0) { + $eq1 = 0; + $st = $steps / 2; + + for ($ofs1 = $idx1 + 1; $ofs1 < $cnt1 && $st-- > 0; $ofs1++) { + $eq = @count_array_diff($ar1, $ar2, $is_reg, $w, $ofs1, $idx2, $cnt1, $cnt2, $st); + + if ($eq > $eq1) { + $eq1 = $eq; + } + } + + $eq2 = 0; + $st = $steps; + + for ($ofs2 = $idx2 + 1; $ofs2 < $cnt2 && $st-- > 0; $ofs2++) { + $eq = @count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $ofs2, $cnt1, $cnt2, $st); + if ($eq > $eq2) { + $eq2 = $eq; + } + } + + if ($eq1 > $eq2) { + $equal += $eq1; + } elseif ($eq2 > 0) { + $equal += $eq2; + } + } + + return $equal; +} + +function generate_array_diff(array $ar1, array $ar2, bool $is_reg, array $w): array +{ + global $context_line_count; + $idx1 = 0; + $cnt1 = @count($ar1); + $idx2 = 0; + $cnt2 = @count($ar2); + $diff = ; + $old1 = ; + $old2 = ; + $number_len = max(3, strlen((string)max($cnt1 + 1, $cnt2 + 1))); + $line_number_spec = '%0' . $number_len . 'd'; + + /** Mapping from $idx2 to $idx1, including indexes of idx2 that are identical to idx1 as well as entries that don't have matches */ + $mapping = ; + + while ($idx1 < $cnt1 && $idx2 < $cnt2) { + $mapping$idx2 = $idx1; + if (comp_line($ar1$idx1, $ar2$idx2, $is_reg)) { + $idx1++; + $idx2++; + continue; + } else { + $c1 = @count_array_diff($ar1, $ar2, $is_reg, $w, $idx1 + 1, $idx2, $cnt1, $cnt2, 10); + $c2 = @count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $idx2 + 1, $cnt1, $cnt2, 10); + + if ($c1 > $c2) { + $old1$idx1 = sprintf("{$line_number_spec}- ", $idx1 + 1) . $w$idx1++; + } elseif ($c2 > 0) { + $old2$idx2 = sprintf("{$line_number_spec}+ ", $idx2 + 1) . $ar2$idx2++; + } else { + $old1$idx1 = sprintf("{$line_number_spec}- ", $idx1 + 1) . $w$idx1++; + $old2$idx2 = sprintf("{$line_number_spec}+ ", $idx2 + 1) . $ar2$idx2++; + } + $last_printed_context_line = $idx1; + } + } + $mapping$idx2 = $idx1; + + reset($old1); + $k1 = key($old1); + $l1 = -2; + reset($old2); + $k2 = key($old2); + $l2 = -2; + $old_k1 = -1; + $add_context_lines = function (int $new_k1) use (&$old_k1, &$diff, $w, $context_line_count, $number_len) { + if ($old_k1 >= $new_k1 || !$context_line_count) { + return; + } + $end = $new_k1 - 1; + $range_end = min($end, $old_k1 + $context_line_count); + if ($old_k1 >= 0) { + while ($old_k1 < $range_end) { + $diff = str_repeat(' ', $number_len + 2) . $w$old_k1++; + } + } + if ($end - $context_line_count > $old_k1) { + $old_k1 = $end - $context_line_count; + if ($old_k1 > 0) { + // Add a '--' to mark sections where the common areas were truncated + $diff = '--'; + } + } + $old_k1 = max($old_k1, 0); + while ($old_k1 < $end) { + $diff = str_repeat(' ', $number_len + 2) . $w$old_k1++; + } + $old_k1 = $new_k1; + }; + + while ($k1 !== null || $k2 !== null) { + if ($k1 == $l1 + 1 || $k2 === null) { + $add_context_lines($k1); + $l1 = $k1; + $diff = current($old1); + $old_k1 = $k1; + $k1 = next($old1) ? key($old1) : null; + } elseif ($k2 == $l2 + 1 || $k1 === null) { + $add_context_lines($mapping$k2); + $l2 = $k2; + $diff = current($old2); + $k2 = next($old2) ? key($old2) : null; + } elseif ($k1 < $mapping$k2) { + $add_context_lines($k1); + $l1 = $k1; + $diff = current($old1); + $k1 = next($old1) ? key($old1) : null; + } else { + $add_context_lines($mapping$k2); + $l2 = $k2; + $diff = current($old2); + $k2 = next($old2) ? key($old2) : null; + } + } + + while ($idx1 < $cnt1) { + $add_context_lines($idx1 + 1); + $diff = sprintf("{$line_number_spec}- ", $idx1 + 1) . $w$idx1++; + } + + while ($idx2 < $cnt2) { + if (isset($mapping$idx2)) { + $add_context_lines($mapping$idx2 + 1); + } + $diff = sprintf("{$line_number_spec}+ ", $idx2 + 1) . $ar2$idx2++; + } + $add_context_lines(min($old_k1 + $context_line_count + 1, $cnt1 + 1)); + if ($context_line_count && $old_k1 < $cnt1 + 1) { + // Add a '--' to mark sections where the common areas were truncated + $diff = '--'; + } + + return $diff; +} + +function generate_diff(string $wanted, ?string $wanted_re, string $output): string +{ + $w = explode("\n", $wanted); + $o = explode("\n", $output); + $r = is_null($wanted_re) ? $w : explode("\n", $wanted_re); + $diff = generate_array_diff($r, $o, !is_null($wanted_re), $w); + + return implode(PHP_EOL, $diff); +} + +function error(string $message): void +{ + echo "ERROR: {$message}\n"; + exit(1); +} + +function settings2array(array $settings, &$ini_settings): void +{ + foreach ($settings as $setting) { + if (strpos($setting, '=') !== false) { + $setting = explode("=", $setting, 2); + $name = trim($setting0); + $value = trim($setting1); + + if ($name == 'extension' || $name == 'zend_extension') { + if (!isset($ini_settings$name)) { + $ini_settings$name = ; + } + + $ini_settings$name = $value; + } else { + $ini_settings$name = $value; + } + } + } +} + +function settings2params(array $ini_settings): string +{ + $settings = ''; + + foreach ($ini_settings as $name => $value) { + if (is_array($value)) { + foreach ($value as $val) { + $val = addslashes($val); + $settings .= " -d \"$name=$val\""; + } + } else { + if (IS_WINDOWS && !empty($value) && $value0 == '"') { + $len = strlen($value); + + if ($value$len - 1 == '"') { + $value0 = "'"; + $value$len - 1 = "'"; + } + } else { + $value = addslashes($value); + } + + $settings .= " -d \"$name=$value\""; + } + } + + return $settings; +} + +function compute_summary(): void +{ + global $n_total, $test_results, $ignored_by_ext, $sum_results, $percent_results; + + $n_total = count($test_results); + $n_total += $ignored_by_ext; + $sum_results = + 'PASSED' => 0, + 'WARNED' => 0, + 'SKIPPED' => 0, + 'FAILED' => 0, + 'BORKED' => 0, + 'LEAKED' => 0, + 'XFAILED' => 0, + 'XLEAKED' => 0 + ; + + foreach ($test_results as $v) { + $sum_results$v++; + } + + $sum_results'SKIPPED' += $ignored_by_ext; + $percent_results = ; + + foreach ($sum_results as $v => $n) { + $percent_results$v = (100.0 * $n) / $n_total; + } +} + +function get_summary(bool $show_ext_summary): string +{ + global $exts_skipped, $exts_tested, $n_total, $sum_results, $percent_results, $end_time, $start_time, $failed_test_summary, $PHP_FAILED_TESTS, $valgrind; + + $x_total = $n_total - $sum_results'SKIPPED' - $sum_results'BORKED'; + + if ($x_total) { + $x_warned = (100.0 * $sum_results'WARNED') / $x_total; + $x_failed = (100.0 * $sum_results'FAILED') / $x_total; + $x_xfailed = (100.0 * $sum_results'XFAILED') / $x_total; + $x_xleaked = (100.0 * $sum_results'XLEAKED') / $x_total; + $x_leaked = (100.0 * $sum_results'LEAKED') / $x_total; + $x_passed = (100.0 * $sum_results'PASSED') / $x_total; + } else { + $x_warned = $x_failed = $x_passed = $x_leaked = $x_xfailed = $x_xleaked = 0; + } + + $summary = ''; + + if ($show_ext_summary) { + $summary .= ' +===================================================================== +TEST RESULT SUMMARY +--------------------------------------------------------------------- +Exts skipped : ' . sprintf('%4d', $exts_skipped) . ' +Exts tested : ' . sprintf('%4d', $exts_tested) . ' +--------------------------------------------------------------------- +'; + } + + $summary .= ' +Number of tests : ' . sprintf('%4d', $n_total) . ' ' . sprintf('%8d', $x_total); + + if ($sum_results'BORKED') { + $summary .= ' +Tests borked : ' . sprintf('%4d (%5.1f%%)', $sum_results'BORKED', $percent_results'BORKED') . ' --------'; + } + + $summary .= ' +Tests skipped : ' . sprintf('%4d (%5.1f%%)', $sum_results'SKIPPED', $percent_results'SKIPPED') . ' -------- +Tests warned : ' . sprintf('%4d (%5.1f%%)', $sum_results'WARNED', $percent_results'WARNED') . ' ' . sprintf('(%5.1f%%)', $x_warned) . ' +Tests failed : ' . sprintf('%4d (%5.1f%%)', $sum_results'FAILED', $percent_results'FAILED') . ' ' . sprintf('(%5.1f%%)', $x_failed); + + if ($sum_results'XFAILED') { + $summary .= ' +Expected fail : ' . sprintf('%4d (%5.1f%%)', $sum_results'XFAILED', $percent_results'XFAILED') . ' ' . sprintf('(%5.1f%%)', $x_xfailed); + } + + if ($valgrind) { + $summary .= ' +Tests leaked : ' . sprintf('%4d (%5.1f%%)', $sum_results'LEAKED', $percent_results'LEAKED') . ' ' . sprintf('(%5.1f%%)', $x_leaked); + if ($sum_results'XLEAKED') { + $summary .= ' +Expected leak : ' . sprintf('%4d (%5.1f%%)', $sum_results'XLEAKED', $percent_results'XLEAKED') . ' ' . sprintf('(%5.1f%%)', $x_xleaked); + } + } + + $summary .= ' +Tests passed : ' . sprintf('%4d (%5.1f%%)', $sum_results'PASSED', $percent_results'PASSED') . ' ' . sprintf('(%5.1f%%)', $x_passed) . ' +--------------------------------------------------------------------- +Time taken : ' . sprintf('%4d seconds', $end_time - $start_time) . ' +===================================================================== +'; + $failed_test_summary = ''; + + if (count($PHP_FAILED_TESTS'SLOW')) { + usort($PHP_FAILED_TESTS'SLOW', function (array $a, array $b): int { + return $a'info' < $b'info' ? 1 : -1; + }); + + $failed_test_summary .= ' +===================================================================== +SLOW TEST SUMMARY +--------------------------------------------------------------------- +'; + foreach ($PHP_FAILED_TESTS'SLOW' as $failed_test_data) { + $failed_test_summary .= sprintf('(%.3f s) ', $failed_test_data'info') . $failed_test_data'test_name' . "\n"; + } + $failed_test_summary .= "=====================================================================\n"; + } + + if (count($PHP_FAILED_TESTS'XFAILED')) { + $failed_test_summary .= ' +===================================================================== +EXPECTED FAILED TEST SUMMARY +--------------------------------------------------------------------- +'; + foreach ($PHP_FAILED_TESTS'XFAILED' as $failed_test_data) { + $failed_test_summary .= $failed_test_data'test_name' . $failed_test_data'info' . "\n"; + } + $failed_test_summary .= "=====================================================================\n"; + } + + if (count($PHP_FAILED_TESTS'BORKED')) { + $failed_test_summary .= ' +===================================================================== +BORKED TEST SUMMARY +--------------------------------------------------------------------- +'; + foreach ($PHP_FAILED_TESTS'BORKED' as $failed_test_data) { + $failed_test_summary .= $failed_test_data'info' . "\n"; + } + + $failed_test_summary .= "=====================================================================\n"; + } + + if (count($PHP_FAILED_TESTS'FAILED')) { + $failed_test_summary .= ' +===================================================================== +FAILED TEST SUMMARY +--------------------------------------------------------------------- +'; + foreach ($PHP_FAILED_TESTS'FAILED' as $failed_test_data) { + $failed_test_summary .= $failed_test_data'test_name' . $failed_test_data'info' . "\n"; + } + $failed_test_summary .= "=====================================================================\n"; + } + if (count($PHP_FAILED_TESTS'WARNED')) { + $failed_test_summary .= ' +===================================================================== +WARNED TEST SUMMARY +--------------------------------------------------------------------- +'; + foreach ($PHP_FAILED_TESTS'WARNED' as $failed_test_data) { + $failed_test_summary .= $failed_test_data'test_name' . $failed_test_data'info' . "\n"; + } + + $failed_test_summary .= "=====================================================================\n"; + } + + if (count($PHP_FAILED_TESTS'LEAKED')) { + $failed_test_summary .= ' +===================================================================== +LEAKED TEST SUMMARY +--------------------------------------------------------------------- +'; + foreach ($PHP_FAILED_TESTS'LEAKED' as $failed_test_data) { + $failed_test_summary .= $failed_test_data'test_name' . $failed_test_data'info' . "\n"; + } + + $failed_test_summary .= "=====================================================================\n"; + } + + if (count($PHP_FAILED_TESTS'XLEAKED')) { + $failed_test_summary .= ' +===================================================================== +EXPECTED LEAK TEST SUMMARY +--------------------------------------------------------------------- +'; + foreach ($PHP_FAILED_TESTS'XLEAKED' as $failed_test_data) { + $failed_test_summary .= $failed_test_data'test_name' . $failed_test_data'info' . "\n"; + } + + $failed_test_summary .= "=====================================================================\n"; + } + + if ($failed_test_summary && !getenv('NO_PHPTEST_SUMMARY')) { + $summary .= $failed_test_summary; + } + + return $summary; +} + +function show_start($start_time): void +{ + echo "TIME START " . date('Y-m-d H:i:s', $start_time) . "\n=====================================================================\n"; +} + +function show_end($end_time): void +{ + echo "=====================================================================\nTIME END " . date('Y-m-d H:i:s', $end_time) . "\n"; +} + +function show_summary(): void +{ + echo get_summary(true); +} + +function show_redirect_start(string $tests, string $tested, string $tested_file): void +{ + global $SHOW_ONLY_GROUPS; + + if (!$SHOW_ONLY_GROUPS || in_array('REDIRECT', $SHOW_ONLY_GROUPS)) { + echo "REDIRECT $tests ($tested $tested_file) begin\n"; + } else { + clear_show_test(); + } +} + +function show_redirect_ends(string $tests, string $tested, string $tested_file): void +{ + global $SHOW_ONLY_GROUPS; + + if (!$SHOW_ONLY_GROUPS || in_array('REDIRECT', $SHOW_ONLY_GROUPS)) { + echo "REDIRECT $tests ($tested $tested_file) done\n"; + } else { + clear_show_test(); + } +} + +function show_test(int $test_idx, string $shortname): void +{ + global $test_cnt; + global $line_length; + + $str = "TEST $test_idx/$test_cnt $shortname\r"; + $line_length = strlen($str); + echo $str; + flush(); +} + +function clear_show_test(): void +{ + global $line_length; + // Parallel testing + global $workerID; + + if (!$workerID && isset($line_length)) { + // Write over the last line to avoid random trailing chars on next echo + echo str_repeat(" ", $line_length), "\r"; + } +} + +function parse_conflicts(string $text): array +{ + // Strip comments + $text = preg_replace('/#.*/', '', $text); + return array_map('trim', explode("\n", trim($text))); +} + +function show_result( + string $result, + string $tested, + string $tested_file, + string $extra = '', + ?array $temp_filenames = null +): void { + global $SHOW_ONLY_GROUPS, $colorize; + + if (!$SHOW_ONLY_GROUPS || in_array($result, $SHOW_ONLY_GROUPS)) { + if ($colorize) { + /* Use ANSI escape codes for coloring test result */ + switch ( $result ) { + case 'PASS': // Light Green + $color = "\e1;32m{$result}\e0m"; break; + case 'FAIL': + case 'BORK': + case 'LEAK': + case 'LEAK&FAIL': + // Light Red + $color = "\e1;31m{$result}\e0m"; break; + case 'SKIP': + // Dimmed + $color = "\e0;37m{$result}"; break; + default: // Yellow + $color = "\e1;33m{$result}\e0m"; break; + } + + echo "$color $tested $tested_file $extra\e0m\n"; + } else { + echo "$result $tested $tested_file $extra\n"; + } + } elseif (!$SHOW_ONLY_GROUPS) { + clear_show_test(); + } + +} + +class BorkageException extends Exception +{ +} + +class JUnit +{ + private bool $enabled = true; + private $fp = null; + private array $suites = ; + private array $rootSuite = self::EMPTY_SUITE + 'name' => 'php'; + + private const EMPTY_SUITE = + 'test_total' => 0, + 'test_pass' => 0, + 'test_fail' => 0, + 'test_error' => 0, + 'test_skip' => 0, + 'test_warn' => 0, + 'files' => , + 'execution_time' => 0, + ; + + /** + * @throws Exception + */ + public function __construct(array $env, int $workerID) + { + // Check whether a junit log is wanted. + $fileName = $env'TEST_PHP_JUNIT' ?? null; + if (empty($fileName)) { + $this->enabled = false; + return; + } + if (!$workerID && !$this->fp = fopen($fileName, 'w')) { + throw new Exception("Failed to open $fileName for writing."); + } + } + + public function isEnabled(): bool + { + return $this->enabled; + } + + public function clear(): void + { + $this->rootSuite = self::EMPTY_SUITE + 'name' => 'php'; + $this->suites = ; + } + + public function saveXML(): void + { + if (!$this->enabled) { + return; + } + + $xml = '<' . '?' . 'xml version="1.0" encoding="UTF-8"' . '?' . '>' . PHP_EOL; + $xml .= sprintf( + '<testsuites name="%s" tests="%s" failures="%d" errors="%d" skip="%d" time="%s">' . PHP_EOL, + $this->rootSuite'name', + $this->rootSuite'test_total', + $this->rootSuite'test_fail', + $this->rootSuite'test_error', + $this->rootSuite'test_skip', + $this->rootSuite'execution_time' + ); + $xml .= $this->getSuitesXML(); + $xml .= '</testsuites>'; + fwrite($this->fp, $xml); + } + + private function getSuitesXML(string $suite_name = '') + { + // FIXME: $suite_name gets overwritten + $result = ''; + + foreach ($this->suites as $suite_name => $suite) { + $result .= sprintf( + '<testsuite name="%s" tests="%s" failures="%d" errors="%d" skip="%d" time="%s">' . PHP_EOL, + $suite'name', + $suite'test_total', + $suite'test_fail', + $suite'test_error', + $suite'test_skip', + $suite'execution_time' + ); + + if (!empty($suite_name)) { + foreach ($suite'files' as $file) { + $result .= $this->rootSuite'files'$file'xml'; + } + } + + $result .= '</testsuite>' . PHP_EOL; + } + + return $result; + } + + public function markTestAs( + $type, + string $file_name, + string $test_name, + ?int $time = null, + string $message = '', + string $details = '' + ): void { + if (!$this->enabled) { + return; + } + + $suite = $this->getSuiteName($file_name); + + $this->record($suite, 'test_total'); + + $time = $time ?? $this->getTimer($file_name); + $this->record($suite, 'execution_time', $time); + + $escaped_details = htmlspecialchars($details, ENT_QUOTES, 'UTF-8'); + $escaped_details = preg_replace_callback('/\0-\x08\x0B\x0C\x0E-\x1F/', function ($c) { + return sprintf('0x%02x', ord($c0)); + }, $escaped_details); + $escaped_message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8'); + + $escaped_test_name = htmlspecialchars($file_name . ' (' . $test_name . ')', ENT_QUOTES); + $this->rootSuite'files'$file_name'xml' = "<testcase name='$escaped_test_name' time='$time'>\n"; + + if (is_array($type)) { + $output_type = $type0 . 'ED'; + $temp = array_intersect('XFAIL', 'XLEAK', 'FAIL', 'WARN', $type); + $type = reset($temp); + } else { + $output_type = $type . 'ED'; + } + + if ('PASS' == $type || 'XFAIL' == $type || 'XLEAK' == $type) { + $this->record($suite, 'test_pass'); + } elseif ('BORK' == $type) { + $this->record($suite, 'test_error'); + $this->rootSuite'files'$file_name'xml' .= "<error type='$output_type' message='$escaped_message'/>\n"; + } elseif ('SKIP' == $type) { + $this->record($suite, 'test_skip'); + $this->rootSuite'files'$file_name'xml' .= "<skipped>$escaped_message</skipped>\n"; + } elseif ('WARN' == $type) { + $this->record($suite, 'test_warn'); + $this->rootSuite'files'$file_name'xml' .= "<warning>$escaped_message</warning>\n"; + } elseif ('FAIL' == $type) { + $this->record($suite, 'test_fail'); + $this->rootSuite'files'$file_name'xml' .= "<failure type='$output_type' message='$escaped_message'>$escaped_details</failure>\n"; + } else { + $this->record($suite, 'test_error'); + $this->rootSuite'files'$file_name'xml' .= "<error type='$output_type' message='$escaped_message'>$escaped_details</error>\n"; + } + + $this->rootSuite'files'$file_name'xml' .= "</testcase>\n"; + } + + private function record(string $suite, string $param, $value = 1): void + { + $this->rootSuite$param += $value; + $this->suites$suite$param += $value; + } + + private function getTimer(string $file_name) + { + if (!$this->enabled) { + return 0; + } + + if (isset($this->rootSuite'files'$file_name'total')) { + return number_format($this->rootSuite'files'$file_name'total', 4); + } + + return 0; + } + + public function startTimer(string $file_name): void + { + if (!$this->enabled) { + return; + } + + if (!isset($this->rootSuite'files'$file_name'start')) { + $this->rootSuite'files'$file_name'start' = microtime(true); + + $suite = $this->getSuiteName($file_name); + $this->initSuite($suite); + $this->suites$suite'files'$file_name = $file_name; + } + } + + public function getSuiteName(string $file_name): string + { + return $this->pathToClassName(dirname($file_name)); + } + + private function pathToClassName(string $file_name): string + { + if (!$this->enabled) { + return ''; + } + + $ret = $this->rootSuite'name'; + $_tmp = ; + + // lookup whether we're in the PHP source checkout + $max = 5; + if (is_file($file_name)) { + $dir = dirname(realpath($file_name)); + } else { + $dir = realpath($file_name); + } + do { + array_unshift($_tmp, basename($dir)); + $chk = $dir . DIRECTORY_SEPARATOR . "main" . DIRECTORY_SEPARATOR . "php_version.h"; + $dir = dirname($dir); + } while (!file_exists($chk) && --$max > 0); + if (file_exists($chk)) { + if ($max) { + array_shift($_tmp); + } + foreach ($_tmp as $p) { + $ret .= "." . preg_replace(",^a-z0-9+,i", ".", $p); + } + return $ret; + } + + return $this->rootSuite'name' . '.' . str_replace(DIRECTORY_SEPARATOR, '-', '.', $file_name); + } + + public function initSuite(string $suite_name): void + { + if (!$this->enabled) { + return; + } + + if (!empty($this->suites$suite_name)) { + return; + } + + $this->suites$suite_name = self::EMPTY_SUITE + 'name' => $suite_name; + } + + /** + * @throws Exception + */ + public function stopTimer(string $file_name): void + { + if (!$this->enabled) { + return; + } + + if (!isset($this->rootSuite'files'$file_name'start')) { + throw new Exception("Timer for $file_name was not started!"); + } + + if (!isset($this->rootSuite'files'$file_name'total')) { + $this->rootSuite'files'$file_name'total' = 0; + } + + $start = $this->rootSuite'files'$file_name'start'; + $this->rootSuite'files'$file_name'total' += microtime(true) - $start; + unset($this->rootSuite'files'$file_name'start'); + } + + public function mergeResults(?JUnit $other): void + { + if (!$this->enabled || !$other) { + return; + } + + $this->mergeSuites($this->rootSuite, $other->rootSuite); + foreach ($other->suites as $name => $suite) { + if (!isset($this->suites$name)) { + $this->suites$name = $suite; + continue; + } + + $this->mergeSuites($this->suites$name, $suite); + } + } + + private function mergeSuites(array &$dest, array $source): void + { + $dest'test_total' += $source'test_total'; + $dest'test_pass' += $source'test_pass'; + $dest'test_fail' += $source'test_fail'; + $dest'test_error' += $source'test_error'; + $dest'test_skip' += $source'test_skip'; + $dest'test_warn' += $source'test_warn'; + $dest'execution_time' += $source'execution_time'; + $dest'files' += $source'files'; + } +} + +class SkipCache +{ + private bool $enable; + private bool $keepFile; + + private array $skips = ; + private array $extensions = ; + + private int $hits = 0; + private int $misses = 0; + private int $extHits = 0; + private int $extMisses = 0; + + public function __construct(bool $enable, bool $keepFile) + { + $this->enable = $enable; + $this->keepFile = $keepFile; + } + + public function checkSkip(string $php, string $code, string $checkFile, string $tempFile, array $env): string + { + // Extension tests frequently use something like <?php require 'skipif.inc'; + // for skip checks. This forces us to cache per directory to avoid pollution. + $dir = dirname($checkFile); + $key = "$php => $dir"; + + if (isset($this->skips$key$code)) { + $this->hits++; + if ($this->keepFile) { + save_text($checkFile, $code, $tempFile); + } + return $this->skips$key$code; + } + + save_text($checkFile, $code, $tempFile); + $result = trim(system_with_timeout("$php \"$checkFile\"", $env)); + if (strpos($result, 'nocache') === 0) { + $result = ''; + } else if ($this->enable) { + $this->skips$key$code = $result; + } + $this->misses++; + + if (!$this->keepFile) { + @unlink($checkFile); + } + + return $result; + } + + public function getExtensions(string $php): array + { + if (isset($this->extensions$php)) { + $this->extHits++; + return $this->extensions$php; + } + + $extDir = `$php -d display_errors=0 -r "echo ini_get('extension_dir');"`; + $extensions = explode(",", `$php -d display_errors=0 -r "echo implode(',', get_loaded_extensions());"`); + $extensions = array_map('strtolower', $extensions); + if (in_array('zend opcache', $extensions)) { + $extensions = 'opcache'; + } + + $result = $extDir, $extensions; + $this->extensions$php = $result; + $this->extMisses++; + + return $result; + } + +// public function __destruct() +// { +// echo "Skips: {$this->hits} hits, {$this->misses} misses.\n"; +// echo "Extensions: {$this->extHits} hits, {$this->extMisses} misses.\n"; +// echo "Cache distribution:\n"; +// +// foreach ($this->skips as $php => $cache) { +// echo "$php: " . count($cache) . "\n"; +// } +// } +} + +class RuntestsValgrind +{ + protected $version = ''; + protected $header = ''; + protected $version_3_8_0 = false; + protected $tool = null; + + public function getVersion(): string + { + return $this->version; + } + + public function getHeader(): string + { + return $this->header; + } + + public function __construct(array $environment, string $tool = 'memcheck') + { + $this->tool = $tool; + $header = system_with_timeout("valgrind --tool={$this->tool} --version", $environment); + if (!$header) { + error("Valgrind returned no version info for {$this->tool}, cannot proceed.\n". + "Please check if Valgrind is installed and the tool is named correctly."); + } + $count = 0; + $version = preg_replace("/valgrind-(\d+)\.(\d+)\.(\d+)(.\w_-+)?(\s+)/", '$1.$2.$3', $header, 1, $count); + if ($count != 1) { + error("Valgrind returned invalid version info (\"{$header}\") for {$this->tool}, cannot proceed."); + } + $this->version = $version; + $this->header = sprintf( + "%s (%s)", trim($header), $this->tool); + $this->version_3_8_0 = version_compare($version, '3.8.0', '>='); + } + + public function wrapCommand(string $cmd, string $memcheck_filename, bool $check_all): string + { + $vcmd = "valgrind -q --tool={$this->tool} --trace-children=yes"; + if ($check_all) { + $vcmd .= ' --smc-check=all'; + } + + /* --vex-iropt-register-updates=allregs-at-mem-access is necessary for phpdbg watchpoint tests */ + if ($this->version_3_8_0) { + return "$vcmd --vex-iropt-register-updates=allregs-at-mem-access --log-file=$memcheck_filename $cmd"; + } + return "$vcmd --vex-iropt-precise-memory-exns=yes --log-file=$memcheck_filename $cmd"; + } +} + +class TestFile +{ + private string $fileName; + + private array $sections = 'TEST' => ''; + + private const ALLOWED_SECTIONS = + 'EXPECT', 'EXPECTF', 'EXPECTREGEX', 'EXPECTREGEX_EXTERNAL', 'EXPECT_EXTERNAL', 'EXPECTF_EXTERNAL', 'EXPECTHEADERS', + 'POST', 'POST_RAW', 'GZIP_POST', 'DEFLATE_POST', 'PUT', 'GET', 'COOKIE', 'ARGS', + 'FILE', 'FILEEOF', 'FILE_EXTERNAL', 'REDIRECTTEST', + 'CAPTURE_STDIO', 'STDIN', 'CGI', 'PHPDBG', + 'INI', 'ENV', 'EXTENSIONS', + 'SKIPIF', 'XFAIL', 'XLEAK', 'AFTER', 'CLEAN', + 'CREDITS', 'DESCRIPTION', 'CONFLICTS', 'WHITESPACE_SENSITIVE', + ; + + /** + * @throws BorkageException + */ + public function __construct(string $fileName, bool $inRedirect) + { + $this->fileName = $fileName; + + $this->readFile(); + $this->validateAndProcess($inRedirect); + } + + public function hasSection(string $name): bool + { + return isset($this->sections$name); + } + + public function hasAllSections(string ...$names): bool + { + foreach ($names as $section) { + if (!isset($this->sections$section)) { + return false; + } + } + + return true; + } + + public function hasAnySections(string ...$names): bool + { + foreach ($names as $section) { + if (isset($this->sections$section)) { + return true; + } + } + + return false; + } + + public function sectionNotEmpty(string $name): bool + { + return !empty($this->sections$name); + } + + /** + * @throws Exception + */ + public function getSection(string $name): string + { + if (!isset($this->sections$name)) { + throw new Exception("Section $name not found"); + } + return $this->sections$name; + } + + public function getName(): string + { + return trim($this->getSection('TEST')); + } + + public function isCGI(): bool + { + return $this->sectionNotEmpty('CGI') + || $this->sectionNotEmpty('GET') + || $this->sectionNotEmpty('POST') + || $this->sectionNotEmpty('GZIP_POST') + || $this->sectionNotEmpty('DEFLATE_POST') + || $this->sectionNotEmpty('POST_RAW') + || $this->sectionNotEmpty('PUT') + || $this->sectionNotEmpty('COOKIE') + || $this->sectionNotEmpty('EXPECTHEADERS'); + } + + /** + * TODO Refactor to make it not needed + */ + public function setSection(string $name, string $value): void + { + $this->sections$name = $value; + } + + /** + * Load the sections of the test file + * @throws BorkageException + */ + private function readFile(): void + { + $fp = fopen($this->fileName, "rb") or error("Cannot open test file: {$this->fileName}"); + + if (!feof($fp)) { + $line = fgets($fp); + + if ($line === false) { + throw new BorkageException("cannot read test"); + } + } else { + throw new BorkageException("empty test {$this->fileName}"); + } + if (strncmp('--TEST--', $line, 8)) { + throw new BorkageException("tests must start with --TEST-- {$this->fileName}"); + } + + $section = 'TEST'; + $secfile = false; + $secdone = false; + + while (!feof($fp)) { + $line = fgets($fp); + + if ($line === false) { + break; + } + + // Match the beginning of a section. + if (preg_match('/^--(_A-Z+)--/', $line, $r)) { + $section = (string) $r1; + + if (isset($this->sections$section) && $this->sections$section) { + throw new BorkageException("duplicated $section section"); + } + + // check for unknown sections + if (!in_array($section, self::ALLOWED_SECTIONS)) { + throw new BorkageException('Unknown section "' . $section . '"'); + } + + $this->sections$section = ''; + $secfile = $section == 'FILE' || $section == 'FILEEOF' || $section == 'FILE_EXTERNAL'; + $secdone = false; + continue; + } + + // Add to the section text. + if (!$secdone) { + $this->sections$section .= $line; + } + + // End of actual test? + if ($secfile && preg_match('/^===DONE===\s*$/', $line)) { + $secdone = true; + } + } + + fclose($fp); + } + + /** + * @throws BorkageException + */ + private function validateAndProcess(bool $inRedirect): void + { + // the redirect section allows a set of tests to be reused outside of + // a given test dir + if ($this->hasSection('REDIRECTTEST')) { + if ($inRedirect) { + throw new BorkageException("Can't redirect a test from within a redirected test"); + } + return; + } + if (!$this->hasSection('PHPDBG') && $this->hasSection('FILE') + $this->hasSection('FILEEOF') + $this->hasSection('FILE_EXTERNAL') != 1) { + throw new BorkageException("missing section --FILE--"); + } + + if ($this->hasSection('FILEEOF')) { + $this->sections'FILE' = preg_replace("/\r\n+$/", '', $this->sections'FILEEOF'); + unset($this->sections'FILEEOF'); + } + + foreach ('FILE', 'EXPECT', 'EXPECTF', 'EXPECTREGEX' as $prefix) { + // For grepping: FILE_EXTERNAL, EXPECT_EXTERNAL, EXPECTF_EXTERNAL, EXPECTREGEX_EXTERNAL + $key = $prefix . '_EXTERNAL'; + + if ($this->hasSection($key)) { + // don't allow tests to retrieve files from anywhere but this subdirectory + $dir = dirname($this->fileName); + $fileName = $dir . '/' . trim(str_replace('..', '', $this->getSection($key))); + + if (file_exists($fileName)) { + $this->sections$prefix = file_get_contents($fileName); + } else { + throw new BorkageException("could not load --" . $key . "-- " . $dir . '/' . trim($fileName)); + } + } + } + + if (($this->hasSection('EXPECT') + $this->hasSection('EXPECTF') + $this->hasSection('EXPECTREGEX')) != 1) { + throw new BorkageException("missing section --EXPECT--, --EXPECTF-- or --EXPECTREGEX--"); + } + + if ($this->hasSection('PHPDBG') && !$this->hasSection('STDIN')) { + $this->sections'STDIN' = $this->sections'PHPDBG' . "\n"; + } + } +} + +function init_output_buffers(): void +{ + // Delete as much output buffers as possible. + while (@ob_end_clean()) { + } + + if (ob_get_level()) { + echo "Not all buffers were deleted.\n"; + } +} + +function check_proc_open_function_exists(): void +{ + if (!function_exists('proc_open')) { + echo <<<NO_PROC_OPEN_ERROR + ++-----------------------------------------------------------+ +| ! ERROR ! | +| The test-suite requires that proc_open() is available. | +| Please check if you disabled it in php.ini. | ++-----------------------------------------------------------+ + +NO_PROC_OPEN_ERROR; + exit(1); + } +} + +function bless_failed_tests(array $failedTests): void +{ + if (empty($failedTests)) { + return; + } + $args = + PHP_BINARY, + __DIR__ . '/scripts/dev/bless_tests.php', + ; + foreach ($failedTests as $test) { + $args = $test'name'; + } + proc_open($args, , $pipes); +} + +main();
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/base/base.c
Added
@@ -0,0 +1,1530 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "lib/php-header.h" +#include "TSRM.h" +#include "php_globals.h" +#include "zend_closures.h" +#include "zend_exceptions.h" +#if PHP_VERSION_ID >= 80200 +# include "zend_attributes.h" +#endif + +#include "zend_interfaces.h" + +#if PHP_VERSION_ID >= 80100 +# include "base_private.h" +# include "Zend/zend_fibers.h" +# include "Zend/zend_observer.h" +#endif + +#include "php_xdebug.h" +#include "php_xdebug_arginfo.h" + +#include "base.h" +#include "filter.h" +#include "develop/develop.h" +#include "develop/stack.h" +#include "gcstats/gc_stats.h" +#include "lib/lib_private.h" +#include "lib/log.h" +#include "lib/var_export_line.h" +#include "lib/var.h" +#include "profiler/profiler.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +#if PHP_VERSION_ID >= 80100 +void (*xdebug_old_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message); +void (*xdebug_new_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message); +static void xdebug_error_cb(int orig_type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message); +#else +void (*xdebug_old_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message); +void (*xdebug_new_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message); +static void xdebug_error_cb(int orig_type, const char *error_filename, const uint32_t error_lineno, zend_string *message); +#endif + +/* execution redirection functions */ +zend_op_array* (*old_compile_file)(zend_file_handle* file_handle, int type); +static void (*xdebug_old_execute_ex)(zend_execute_data *execute_data); +static void (*xdebug_old_execute_internal)(zend_execute_data *current_execute_data, zval *return_value); + +/* error_cb and execption hook overrides */ +void xdebug_base_use_original_error_cb(void); +void xdebug_base_use_xdebug_error_cb(void); +void xdebug_base_use_xdebug_throw_exception_hook(void); + +/* Forward declarations for function overides */ +PHP_FUNCTION(xdebug_set_time_limit); +PHP_FUNCTION(xdebug_error_reporting); +PHP_FUNCTION(xdebug_pcntl_exec); +PHP_FUNCTION(xdebug_pcntl_fork); + + +/* {{{ zend_op_array xdebug_compile_file (file_handle, type) + * This function provides a hook for the execution of bananas */ +static zend_op_array *xdebug_compile_file(zend_file_handle *file_handle, int type) +{ + zend_op_array *op_array; + + op_array = old_compile_file(file_handle, type); + + if (!op_array) { + return NULL; + } + + xdebug_coverage_compile_file(op_array); + xdebug_debugger_compile_file(op_array); + + return op_array; +} +/* }}} */ + +/* I don't like this API, but the function_stack_entry does not keep this as a + * pointer, and hence we need two APIs for freeing :-S */ +void xdebug_func_dtor_by_ref(xdebug_func *elem) +{ + if (elem->function) { + xdfree(elem->function); + } + if (elem->object_class) { + zend_string_release(elem->object_class); + } + if (elem->scope_class) { + zend_string_release(elem->scope_class); + } +} + +void xdebug_func_dtor(xdebug_func *elem) +{ + xdebug_func_dtor_by_ref(elem); + xdfree(elem); +} + +static void function_stack_entry_dtor(void *elem) +{ + unsigned int i; + function_stack_entry *e = elem; + + xdebug_func_dtor_by_ref(&e->function); + + if (e->filename) { + zend_string_release(e->filename); + } + + if (e->var) { + for (i = 0; i < e->varc; i++) { + if (e->vari.name) { + zend_string_release(e->vari.name); + } + zval_ptr_dtor(&(e->vari.data)); + } + xdfree(e->var); + } + + if (e->include_filename) { + zend_string_release(e->include_filename); + } + + if (e->declared_vars) { + xdebug_llist_destroy(e->declared_vars, NULL); + e->declared_vars = NULL; + } + + if (e->profile.call_list) { + xdebug_llist_destroy(e->profile.call_list, NULL); + e->profile.call_list = NULL; + } +} + +int xdebug_include_or_eval_handler(XDEBUG_OPCODE_HANDLER_ARGS) +{ + const zend_op *opline = execute_data->opline; + zval *inc_filename; + zval tmp_inc_filename; + int is_var; + + if (opline->extended_value != ZEND_EVAL) { + return xdebug_call_original_opcode_handler_if_set(opline->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); + } + + inc_filename = xdebug_get_zval(execute_data, opline->op1_type, &opline->op1, &is_var); + + /* If there is no inc_filename, we're just bailing out instead */ + if (!inc_filename) { + return xdebug_call_original_opcode_handler_if_set(opline->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); + } + + if (Z_TYPE_P(inc_filename) != IS_STRING) { + tmp_inc_filename = *inc_filename; + zval_copy_ctor(&tmp_inc_filename); + convert_to_string(&tmp_inc_filename); + inc_filename = &tmp_inc_filename; + } + + /* Now let's store this info */ + if (XG_BASE(last_eval_statement)) { + zend_string_release(XG_BASE(last_eval_statement)); + } + XG_BASE(last_eval_statement) = zend_string_init(Z_STRVAL_P(inc_filename), Z_STRLEN_P(inc_filename), 0); + + if (inc_filename == &tmp_inc_filename) { + zval_dtor(&tmp_inc_filename); + } + + return xdebug_call_original_opcode_handler_if_set(opline->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); +} + +static int find_line_number_for_current_execute_point(zend_execute_data *edata) +{ + zend_execute_data *ptr = edata; + + while (ptr && (!ptr->func || !ZEND_USER_CODE(ptr->func->type))) { + ptr = ptr->prev_execute_data; + } + + if (ptr && ptr->opline) { + return ptr->opline->lineno; + } + + return 0; +} + + +void xdebug_build_fname(xdebug_func *tmp, zend_execute_data *edata) +{ + memset(tmp, 0, sizeof(xdebug_func)); + + if (edata && edata->func && edata->func == (zend_function*) &zend_pass_function) { + tmp->type = XFUNC_ZEND_PASS; + tmp->function = xdstrdup("{zend_pass}"); + } else if (edata && edata->func) { + tmp->type = XFUNC_NORMAL; + if ((Z_TYPE(edata->This)) == IS_OBJECT) { + tmp->type = XFUNC_MEMBER; + if (edata->func->common.scope && strstr(edata->func->common.scope->name->val, "@anonymous") != NULL) { + char *tmp_object_class = xdebug_sprintf( + "{anonymous-class:%s:%d-%d}", + edata->func->common.scope->info.user.filename->val, + edata->func->common.scope->info.user.line_start, + edata->func->common.scope->info.user.line_end + ); + tmp->object_class = zend_string_init(tmp_object_class, strlen(tmp_object_class), 0); + xdfree(tmp_object_class); + } else { + if (edata->func->common.scope) { + tmp->scope_class = zend_string_copy(edata->func->common.scope->name); + } + tmp->object_class = zend_string_copy(edata->This.value.obj->ce->name); + } + } else { + if (edata->func->common.scope) { + tmp->type = XFUNC_STATIC_MEMBER; + tmp->object_class = zend_string_copy(edata->func->common.scope->name); + } + } + if (edata->func->common.function_name) { + if (edata->func->common.fn_flags & ZEND_ACC_CLOSURE) { + tmp->function = xdebug_wrap_closure_location_around_function_name(&edata->func->op_array, STR_NAME_VAL(edata->func->common.function_name)); + } else if (strncmp(edata->func->common.function_name->val, "call_user_func", 14) == 0) { + zend_string *fname = NULL; + int lineno = 0; + + if (edata->prev_execute_data && edata->prev_execute_data->func && edata->prev_execute_data->func->type == ZEND_USER_FUNCTION) { + fname = edata->prev_execute_data->func->op_array.filename; + } + + if (!fname) { + function_stack_entry *tmp_fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + + if (tmp_fse->filename) { + fname = tmp_fse->filename; + } + } + + if (!fname) { + /* It wasn't a special call_user_func after all */ + goto normal_after_all; + } + + lineno = find_line_number_for_current_execute_point(edata); + + tmp->function = xdebug_sprintf( + "%s:{%s:%d}", + edata->func->common.function_name->val, + ZSTR_VAL(fname), + lineno + ); + } else { +normal_after_all: + tmp->function = xdstrdup(edata->func->common.function_name->val); + } + } else if ( + edata && + edata->func && + edata->func->type == ZEND_EVAL_CODE && + edata->prev_execute_data && + edata->prev_execute_data->func && + edata->prev_execute_data->func->common.function_name && + ( + (strncmp(edata->prev_execute_data->func->common.function_name->val, "assert", 6) == 0) || + (strncmp(edata->prev_execute_data->func->common.function_name->val, "create_function", 15) == 0) + ) + ) { + tmp->type = XFUNC_NORMAL; + tmp->function = xdstrdup("{internal eval}"); + } else if ( + edata && + edata->prev_execute_data && + edata->prev_execute_data->func && + edata->prev_execute_data->func->type == ZEND_USER_FUNCTION && + edata->prev_execute_data->opline && + edata->prev_execute_data->opline->opcode == ZEND_INCLUDE_OR_EVAL + ) { + switch (edata->prev_execute_data->opline->extended_value) { + case ZEND_EVAL: + tmp->type = XFUNC_EVAL; + break; + case ZEND_INCLUDE: + tmp->type = XFUNC_INCLUDE; + break; + case ZEND_REQUIRE: + tmp->type = XFUNC_REQUIRE; + break; + case ZEND_INCLUDE_ONCE: + tmp->type = XFUNC_INCLUDE_ONCE; + break; + case ZEND_REQUIRE_ONCE: + tmp->type = XFUNC_REQUIRE_ONCE; + break; + default: + tmp->type = XFUNC_UNKNOWN; + break; + } + } else if ( + edata && + edata->prev_execute_data + ) { + xdebug_build_fname(tmp, edata->prev_execute_data); + } else { + tmp->type = XFUNC_UNKNOWN; + } + } +} + +// TODO: Remove +#define XINI_DEV(v) (XG(settings.develop.v)) + +#define NO_VARIADIC INT_MAX +#define DEBUG 0 + +static void collect_params_internal(function_stack_entry *fse, zend_execute_data *zdata, zend_op_array *op_array) +{ + int i; + int is_variadic = !!(zdata->func->common.fn_flags & ZEND_ACC_VARIADIC); + int is_trampoline = !!(zdata->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE); + int variadic_at_pos = NO_VARIADIC; + int variadic_sensitive = 0; + int names_expected = 0; + int arguments_sent = 0; + int arguments_storage = 0; + + arguments_sent = ZEND_CALL_NUM_ARGS(zdata); + if (arguments_sent > USHRT_MAX) { + return; + } + + names_expected = zdata->func->internal_function.num_args; + if (names_expected > arguments_sent) { + names_expected = arguments_sent; + } +#if DEBUG + fprintf(stderr, "\nF: %s\n - CALL_NUM_ARGS: %d, op_array->num_args: %d, is_variadic: %d, trampoline: %d\n", fse->function.function, ZEND_CALL_NUM_ARGS(zdata), op_array->num_args, is_variadic, is_trampoline); +#endif + + /* If this function is variadic, we have an extra name field in arg_info, and also an extra + * argument sent to the function. */ + if (is_variadic && !is_trampoline) { + names_expected++; + } + + /* Pick the highest of "expected arguments" and "arguments given" (also + * taking into account the extra one for variadics */ + if (names_expected > arguments_sent) { + arguments_storage = names_expected; + } else { + arguments_storage = arguments_sent; + } + + fse->varc = arguments_storage; + fse->var = xdmalloc(fse->varc * sizeof(xdebug_var_name)); + +#if DEBUG + fprintf(stderr, " - names_expected: %d, arguments_sent: %d, arguments_storage: %d, fse->varc: %d\n", names_expected, arguments_sent, arguments_storage, fse->varc); +#endif + + /* Initialise everything in storage */ + for (i = 0; i < fse->varc; i++) { + fse->vari.name = NULL; + ZVAL_UNDEF(&fse->vari.data); + fse->vari.is_variadic = 0; + } + + /* Collect Names */ + for (i = 0; i < names_expected; i++) { + if (op_array->arg_infoi.name) { + fse->vari.name = zend_string_init( + zdata->func->internal_function.arg_infoi.name, + strlen(zdata->func->internal_function.arg_infoi.name), + 0 + ); + + /* If an argument is a variadic, then we mark that on this 'name', + * and also remember which position the variadic started */ + if (ZEND_ARG_IS_VARIADIC(&op_array->arg_infoi) && variadic_at_pos == NO_VARIADIC) { + fse->vari.is_variadic = 1; + variadic_at_pos = i; + } + } + } + + /* Collect Arguments */ + for (i = 0; i < arguments_sent; i++) { +#if PHP_VERSION_ID >= 80200 + zend_attribute *attribute; +#else + void *attribute = NULL; +#endif + + /* The index in ZEND_CALL_ARG is 1-based */ +#if DEBUG + fprintf(stderr, "Copying argument %d\n", i); +#endif +#if PHP_VERSION_ID >= 80200 + attribute = zend_get_parameter_attribute_str( + zdata->func->common.attributes, + "sensitiveparameter", + sizeof("sensitiveparameter") - 1, + i + ); +#endif + if (attribute && fse->vari.is_variadic) { + variadic_sensitive = 1; + } +# if DEBUG + fprintf(stderr, "SENSTIVIVE %d ", attribute != NULL); +# endif + + if ((variadic_sensitive || attribute != NULL) && !fse->vari.is_variadic) { + ZVAL_STRING(&(fse->vari.data), "Sensitive Parameter"); + } else { + ZVAL_COPY(&(fse->vari.data), ZEND_CALL_ARG(zdata, i + 1)); + } +#if DEBUG + fprintf(stderr, "OK\n"); +#endif + } + + if (ZEND_CALL_INFO(zdata) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { + zend_string *name; + zval *param; + int i = fse->varc; + + fse->varc += zend_hash_num_elements(zdata->extra_named_params); + fse->var = xdrealloc(fse->var, fse->varc * sizeof(xdebug_var_name)); + + ZEND_HASH_FOREACH_STR_KEY_VAL(zdata->extra_named_params, name, param) { + fse->vari.name = zend_string_copy(name); + ZVAL_COPY(&(fse->vari.data), param); + fse->vari.is_variadic = 0; + i++; + } ZEND_HASH_FOREACH_END(); + } + +#if DEBUG + for (i = 0; i < fse->varc; i++) { + fprintf(stderr, "%2d %-20s %c %s\n", i, fse->vari.name ? ZSTR_VAL(fse->vari.name) : "---", fse->vari.is_variadic ? 'V' : ' ', xdebug_get_zval_value_line(&fse->vari.data, 0, NULL)->d); + } +#endif +} + +static void collect_params(function_stack_entry *fse, zend_execute_data *zdata, zend_op_array *op_array) +{ + int i; + int is_variadic = !!(zdata->func->common.fn_flags & ZEND_ACC_VARIADIC); + int is_trampoline = !!(zdata->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE); + int variadic_at_pos = NO_VARIADIC; + int variadic_sensitive = 0; + int names_expected = 0; + int arguments_sent = 0; + int arguments_storage = 0; + + arguments_sent = ZEND_CALL_NUM_ARGS(zdata); + + /* The op_array contains the number of * (named) arguments. */ + names_expected = op_array->num_args; + +#if DEBUG + fprintf(stderr, "\nF: %s\n - CALL_NUM_ARGS: %d, op_array->num_args: %d, is_variadic: %d, trampoline: %d\n", fse->function.function, ZEND_CALL_NUM_ARGS(zdata), op_array->num_args, is_variadic, is_trampoline); +#endif + + /* If this function is variadic, we have an extra name field in arg_info, and also an extra + * argument sent to the function. */ + if (is_variadic && !is_trampoline) { + names_expected++; + arguments_sent++; + } + + /* Pick the highest of "expected arguments" and "arguments given" (also + * taking into account the extra one for variadics */ + if (names_expected > arguments_sent) { + arguments_storage = names_expected; + } else { + arguments_storage = arguments_sent; + } + + fse->varc = arguments_storage; + fse->var = xdmalloc(fse->varc * sizeof(xdebug_var_name)); + +#if DEBUG + fprintf(stderr, " - names_expected: %d, arguments_sent: %d, arguments_storage: %d, fse->varc: %d\n", names_expected, arguments_sent, arguments_storage, fse->varc); +#endif + + /* Initialise everything in storage */ + for (i = 0; i < fse->varc; i++) { + fse->vari.name = NULL; + ZVAL_UNDEF(&fse->vari.data); + fse->vari.is_variadic = 0; + } + + /* Collect Names */ + for (i = 0; i < names_expected; i++) { + if (op_array->arg_infoi.name) { + fse->vari.name = zend_string_copy(op_array->arg_infoi.name); + } + + /* If an argument is a variadic, then we mark that on this 'name', + * and also remember which position the variadic started */ + if (ZEND_ARG_IS_VARIADIC(&op_array->arg_infoi) && variadic_at_pos == NO_VARIADIC) { + fse->vari.is_variadic = 1; + variadic_at_pos = i; + } + } + + /* Collect Arguments */ + for (i = 0; i < fse->varc; i++) { +#if PHP_VERSION_ID >= 80200 + zend_attribute *attribute; +#else + void *attribute = NULL; +#endif + + /* The index in ZEND_CALL_ARG is 1-based */ +#if DEBUG + fprintf(stderr, "Copying argument %d: ", i); +#endif + if (i < names_expected || is_trampoline) { +#if DEBUG + fprintf(stderr, "ARG "); +#endif +#if PHP_VERSION_ID >= 80200 + attribute = zend_get_parameter_attribute_str( + zdata->func->common.attributes, + "sensitiveparameter", + sizeof("sensitiveparameter") - 1, + i + ); +#endif + if (attribute && fse->vari.is_variadic) { + variadic_sensitive = 1; + } +# if DEBUG + fprintf(stderr, "SENSITIVE %d ", attribute != NULL); +# endif + + if ((variadic_sensitive || attribute != NULL) && !fse->vari.is_variadic) { + ZVAL_STRING(&(fse->vari.data), "Sensitive Parameter"); + } else { + ZVAL_COPY(&(fse->vari.data), ZEND_CALL_ARG(zdata, i + 1)); + } + } else { +#if DEBUG + fprintf(stderr, "VAR_NUM "); +#endif + if (variadic_sensitive) { + ZVAL_STRING(&(fse->vari.data), "Sensitive Parameter"); + } else { + ZVAL_COPY(&(fse->vari.data), ZEND_CALL_VAR_NUM(zdata, zdata->func->op_array.last_var + zdata->func->op_array.T + i - names_expected)); + } + } +#if DEBUG + fprintf(stderr, "OK\n"); +#endif + } + + if (ZEND_CALL_INFO(zdata) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) { + zend_string *name; + zval *param; + int i = fse->varc; + + fse->varc += zend_hash_num_elements(zdata->extra_named_params); + fse->var = xdrealloc(fse->var, fse->varc * sizeof(xdebug_var_name)); + + ZEND_HASH_FOREACH_STR_KEY_VAL(zdata->extra_named_params, name, param) { + fse->vari.name = zend_string_copy(name); + ZVAL_COPY(&(fse->vari.data), param); + fse->vari.is_variadic = 0; + i++; + } ZEND_HASH_FOREACH_END(); + } + +#if DEBUG + for (i = 0; i < fse->varc; i++) { + fprintf(stderr, "%2d %-20s %c %s\n", i, fse->vari.name ? ZSTR_VAL(fse->vari.name) : "---", fse->vari.is_variadic ? 'V' : ' ', xdebug_get_zval_value_line(&fse->vari.data, 0, NULL)->d); + } +#endif +} + +function_stack_entry *xdebug_add_stack_frame(zend_execute_data *zdata, zend_op_array *op_array, int type) +{ + zend_execute_data *edata; + zend_op **opline_ptr = NULL; + function_stack_entry *tmp; + zend_op *cur_opcode; + + if (type == XDEBUG_USER_DEFINED) { + edata = EG(current_execute_data)->prev_execute_data; + if (edata) { + opline_ptr = (zend_op**) &edata->opline; + } + } else { + edata = EG(current_execute_data); + opline_ptr = (zend_op**) &EG(current_execute_data)->opline; + } + zdata = EG(current_execute_data); + + tmp = (function_stack_entry*) xdebug_vector_push(XG_BASE(stack)); + tmp->level = XDEBUG_VECTOR_COUNT(XG_BASE(stack)); + tmp->user_defined = type; + tmp->op_array = op_array; + + XG_BASE(function_count)++; + tmp->function_nr = XG_BASE(function_count); + { + zend_execute_data *ptr = edata; + while (ptr && (!ptr->func || !ZEND_USER_CODE(ptr->func->type))) { + ptr = ptr->prev_execute_data; + } + if (ptr) { + tmp->filename = zend_string_copy(ptr->func->op_array.filename); + } + } + + if (!tmp->filename) { + /* Includes/main script etc */ + tmp->filename = (type == XDEBUG_USER_DEFINED && op_array && op_array->filename) ? zend_string_copy(op_array->filename) : NULL; + } + /* Call user function locations */ + if (!tmp->filename && XG_BASE(stack)) { + function_stack_entry *tail_fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + if (tail_fse->filename) { + tmp->filename = zend_string_copy(tail_fse->filename); + } + } + + if (!tmp->filename) { + tmp->filename = zend_string_init("Unknown", sizeof("Unknown") - 1, 0); + } + tmp->lineno = 0; + + tmp->prev_memory = XG_BASE(prev_memory); + tmp->memory = zend_memory_usage(0); + XG_BASE(prev_memory) = tmp->memory; + + /* Only get the time when it is actually going to be used. Profiling is not + * included, because it has its own points when it reads the current time. + * */ + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) || XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + tmp->nanotime = xdebug_get_nanotime(); + } else { + tmp->nanotime = 0; + } + + xdebug_build_fname(&(tmp->function), zdata); + if (!tmp->function.type) { + tmp->function.function = xdstrdup("{main}"); + tmp->function.object_class = NULL; + tmp->function.scope_class = NULL; + tmp->function.type = XFUNC_MAIN; + + } else if (tmp->function.type & XFUNC_INCLUDES) { + tmp->lineno = 0; + if (opline_ptr) { + cur_opcode = *opline_ptr; + if (cur_opcode) { + tmp->lineno = cur_opcode->lineno; + } + } + + if (tmp->function.type == XFUNC_EVAL && XG_BASE(last_eval_statement)) { + tmp->include_filename = zend_string_copy(XG_BASE(last_eval_statement)); + } else { + tmp->include_filename = zend_string_copy(zend_get_executed_filename_ex()); + } + } else { + tmp->lineno = find_line_number_for_current_execute_point(edata); + tmp->is_variadic = !!(zdata->func->common.fn_flags & ZEND_ACC_VARIADIC); + + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) || XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + if (ZEND_USER_CODE(zdata->func->type)) { + collect_params(tmp, zdata, op_array); + } else { + collect_params_internal(tmp, zdata, op_array); + } + } + } + + /* Now we have location and name, we can run the filter (for stack and tracing)*/ + xdebug_filter_run(tmp); + + /* Count code coverage line for call */ + xdebug_coverage_count_line_if_branch_check_active(op_array, tmp->filename, tmp->lineno); + + return tmp; +} + +static void xdebug_execute_ex(zend_execute_data *execute_data) +{ + zend_op_array *op_array = &(execute_data->func->op_array); + zend_execute_data *edata = execute_data->prev_execute_data; + function_stack_entry *fse; + int function_nr = 0; + char *code_coverage_function_name = NULL; + zend_string *code_coverage_filename = NULL; + int code_coverage_init = 0; + + /* For PHP 7, we need to reset the opline to the start, so that all opcode + * handlers are being hit. But not for generators, as that would make an + * endless loop. TODO: Fix RECV handling with generators. */ + if (!(EX(func)->op_array.fn_flags & ZEND_ACC_GENERATOR)) { + EX(opline) = EX(func)->op_array.opcodes; + } + + if (xdebug_debugger_bailout_if_no_exec_requested()) { + return; + } + + /* If we're evaluating for the debugger's eval capability, just bail out */ + if (op_array && op_array->filename && strcmp("xdebug://debug-eval", STR_NAME_VAL(op_array->filename)) == 0) { + xdebug_old_execute_ex(execute_data); + return; + } + + /* if we're in a ZEND_EXT_STMT, we ignore this function call as it's likely + that it's just being called to check for breakpoints with conditions */ + if (edata && edata->func && ZEND_USER_CODE(edata->func->type) && edata->opline && edata->opline->opcode == ZEND_EXT_STMT) { + xdebug_old_execute_ex(execute_data); + return; + } + + /* If the stack vector hasn't been initialised yet, we should abort immediately */ + if (!XG_BASE(stack)) { + xdebug_old_execute_ex(execute_data); + return; + } + + if (XG_BASE(in_execution) && XDEBUG_VECTOR_COUNT(XG_BASE(stack)) == 0) { + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + xdebug_debugger_set_program_name(op_array->filename); + xdebug_debug_init_if_requested_at_startup(); + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { + xdebug_gcstats_init_if_requested(op_array); + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + xdebug_profiler_init_if_requested(op_array); + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { + xdebug_tracing_init_if_requested(op_array); + } + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP) && (signed long) XDEBUG_VECTOR_COUNT(XG_BASE(stack)) >= XINI_BASE(max_nesting_level) && (XINI_BASE(max_nesting_level) != -1)) { + zend_throw_exception_ex(zend_ce_error, 0, "Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '" ZEND_LONG_FMT "' frames", XINI_BASE(max_nesting_level)); + } + + fse = xdebug_add_stack_frame(edata, op_array, XDEBUG_USER_DEFINED); + fse->function.internal = 0; + + /* A hack to make __call work with profiles. The function *is* user defined after all. */ + if (fse && xdebug_vector_element_is_valid(XG_BASE(stack), fse - 1) && fse->function.function && (strcmp(fse->function.function, "__call") == 0)) { + (fse - 1)->user_defined = XDEBUG_USER_DEFINED; + } + + function_nr = XG_BASE(function_count); + + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + xdebug_monitor_handler(fse); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { + xdebug_tracing_execute_ex(function_nr, fse); + } + + fse->execute_data = EG(current_execute_data)->prev_execute_data; + if (ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_HAS_SYMBOL_TABLE) { + fse->symbol_table = EG(current_execute_data)->symbol_table; + } + + if (XG_BASE(stack) && (XINI_DEV(show_local_vars) || xdebug_is_debug_connection_active())) { + /* Because include/require is treated as a stack level, we have to add used + * variables in include/required files to all the stack levels above, until + * we hit a function or the top level stack. This is so that the variables + * show up correctly where they should be. We always call + * xdebug_lib_register_compiled_variables on the current stack level, + * otherwise vars in include files do not show up in the locals list. */ + function_stack_entry *loop_fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + int i; + + for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, loop_fse--) { + xdebug_lib_register_compiled_variables(loop_fse, op_array); + if (XDEBUG_IS_NORMAL_FUNCTION(&loop_fse->function)) { + break; + } + } + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { + code_coverage_init = xdebug_coverage_execute_ex(fse, op_array, &code_coverage_filename, &code_coverage_function_name); + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + /* If we're in an eval, we need to create an ID for it. */ + if (fse->function.type == XFUNC_EVAL) { + xdebug_debugger_register_eval(fse); + } + + /* Check for entry breakpoints */ + xdebug_debugger_handle_breakpoints(fse, XDEBUG_BREAKPOINT_TYPE_CALL|XDEBUG_BREAKPOINT_TYPE_EXTERNAL, NULL); + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + xdebug_profiler_execute_ex(fse, op_array); + } + + xdebug_old_execute_ex(execute_data); + + /* Re-acquire the tail as nested calls through xdebug_old_execute_ex() + * might have reallocated the vector */ + fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + xdebug_profiler_execute_ex_end(fse); + } + + if (code_coverage_init) { + xdebug_coverage_execute_ex_end(fse, op_array, code_coverage_filename, code_coverage_function_name); + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { + xdebug_tracing_execute_ex_end(function_nr, fse, execute_data); + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + zval *return_value = NULL; + + if (execute_data->return_value && !(op_array->fn_flags & ZEND_ACC_GENERATOR)) { + return_value = execute_data->return_value; + } + + /* Check for return breakpoints */ + xdebug_debugger_handle_breakpoints(fse, XDEBUG_BREAKPOINT_TYPE_RETURN|XDEBUG_BREAKPOINT_TYPE_EXTERNAL, return_value); + } + + fse->symbol_table = NULL; + fse->execute_data = NULL; + + if (XG_BASE(stack)) { + xdebug_vector_pop(XG_BASE(stack)); + } +} + +static int check_soap_call(function_stack_entry *fse, zend_execute_data *execute_data) +{ + if ( + fse->function.object_class && + Z_OBJ(EX(This)) && + Z_TYPE(EX(This)) == IS_OBJECT && + (zend_hash_str_find_ptr(&module_registry, "soap", sizeof("soap") - 1) != NULL) + ) { + zend_class_entry *soap_server_ce, *soap_client_ce; + + soap_server_ce = zend_hash_str_find_ptr(CG(class_table), "soapserver", 10); + soap_client_ce = zend_hash_str_find_ptr(CG(class_table), "soapclient", 10); + + if (!soap_server_ce || !soap_client_ce) { + return 0; + } + + if ( + (instanceof_function(Z_OBJCE(EX(This)), soap_server_ce)) || + (instanceof_function(Z_OBJCE(EX(This)), soap_client_ce)) + ) { + return 1; + } + } + return 0; +} + +static void xdebug_execute_internal(zend_execute_data *current_execute_data, zval *return_value) +{ + zend_execute_data *edata = EG(current_execute_data); + function_stack_entry *fse; + int function_nr = 0; + int function_call_traced = 0; + int restore_error_handler_situation = 0; +#if PHP_VERSION_ID >= 80100 + void (*tmp_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message) = NULL; +#else + void (*tmp_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message) = NULL; +#endif + + /* If the stack vector hasn't been initialised yet, we should abort immediately */ + if (!XG_BASE(stack)) { + if (xdebug_old_execute_internal) { + xdebug_old_execute_internal(current_execute_data, return_value); + } else { + execute_internal(current_execute_data, return_value); + } + return; + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP) && (signed long) XDEBUG_VECTOR_COUNT(XG_BASE(stack)) >= XINI_BASE(max_nesting_level) && (XINI_BASE(max_nesting_level) != -1)) { + zend_throw_exception_ex(zend_ce_error, 0, "Xdebug has detected a possible infinite loop, and aborted your script with a stack depth of '" ZEND_LONG_FMT "' frames", XINI_BASE(max_nesting_level)); + } + + fse = xdebug_add_stack_frame(edata, &edata->func->op_array, XDEBUG_BUILT_IN); + fse->function.internal = 1; + + function_nr = XG_BASE(function_count); + + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + xdebug_monitor_handler(fse); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { + function_call_traced = xdebug_tracing_execute_internal(function_nr, fse); + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + /* Check for entry breakpoints */ + xdebug_debugger_handle_breakpoints(fse, XDEBUG_BREAKPOINT_TYPE_CALL, NULL); + } + + /* Check for SOAP */ + if (check_soap_call(fse, current_execute_data)) { + restore_error_handler_situation = 1; + tmp_error_cb = zend_error_cb; + xdebug_base_use_original_error_cb(); + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + xdebug_profiler_execute_internal(fse); + } + + if (xdebug_old_execute_internal) { + xdebug_old_execute_internal(current_execute_data, return_value); + } else { + execute_internal(current_execute_data, return_value); + } + + /* Re-acquire the tail as nested calls through + * xdebug_old_execute_internal() might have reallocated the vector */ + fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + xdebug_profiler_execute_internal_end(fse); + } + + /* Restore SOAP situation if needed */ + if (restore_error_handler_situation) { + zend_error_cb = tmp_error_cb; + } + + /* We only call the function_exit handler and return value handler if the + * function call was also traced. Otherwise we end up with return trace + * lines without a corresponding function call line. */ + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) && function_call_traced) { + xdebug_tracing_execute_internal_end(function_nr, fse, return_value); + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + /* Check for return breakpoints */ + xdebug_debugger_handle_breakpoints(fse, XDEBUG_BREAKPOINT_TYPE_RETURN, return_value); + } + + if (XG_BASE(stack)) { + xdebug_vector_pop(XG_BASE(stack)); + } +} + +static void xdebug_base_overloaded_functions_setup(void) +{ + zend_function *orig; + + /* Override set_time_limit with our own function to prevent timing out while debugging */ + orig = zend_hash_str_find_ptr(EG(function_table), "set_time_limit", sizeof("set_time_limit") - 1); + if (orig) { + XG_BASE(orig_set_time_limit_func) = orig->internal_function.handler; + orig->internal_function.handler = zif_xdebug_set_time_limit; + } else { + XG_BASE(orig_set_time_limit_func) = NULL; + } + + /* Override error_reporting with our own function, to be able to give right answer during DBGp's + * 'eval' commands */ + orig = zend_hash_str_find_ptr(EG(function_table), "error_reporting", sizeof("error_reporting") - 1); + if (orig) { + XG_BASE(orig_error_reporting_func) = orig->internal_function.handler; + orig->internal_function.handler = zif_xdebug_error_reporting; + } else { + XG_BASE(orig_error_reporting_func) = NULL; + } + + /* Override pcntl_exec with our own function to be able to write profiling summary */ + orig = zend_hash_str_find_ptr(EG(function_table), "pcntl_exec", sizeof("pcntl_exec") - 1); + if (orig) { + XG_BASE(orig_pcntl_exec_func) = orig->internal_function.handler; + orig->internal_function.handler = zif_xdebug_pcntl_exec; + } else { + XG_BASE(orig_pcntl_exec_func) = NULL; + } + + /* Override pcntl_fork with our own function to be able + * to start the debugger for the forked process */ + orig = zend_hash_str_find_ptr(EG(function_table), "pcntl_fork", sizeof("pcntl_fork") - 1); + if (orig) { + XG_BASE(orig_pcntl_fork_func) = orig->internal_function.handler; + orig->internal_function.handler = zif_xdebug_pcntl_fork; + } else { + XG_BASE(orig_pcntl_fork_func) = NULL; + } +} + +static void xdebug_base_overloaded_functions_restore(void) +{ + zend_function *orig; + + if (XG_BASE(orig_set_time_limit_func)) { + orig = zend_hash_str_find_ptr(EG(function_table), "set_time_limit", sizeof("set_time_limit") - 1); + if (orig) { + orig->internal_function.handler = XG_BASE(orig_set_time_limit_func); + } + } + + if (XG_BASE(orig_error_reporting_func)) { + orig = zend_hash_str_find_ptr(EG(function_table), "error_reporting", sizeof("error_reporting") - 1); + if (orig) { + orig->internal_function.handler = XG_BASE(orig_error_reporting_func); + } + } + + if (XG_BASE(orig_pcntl_exec_func)) { + orig = zend_hash_str_find_ptr(EG(function_table), "pcntl_exec", sizeof("pcntl_exec") - 1); + if (orig) { + orig->internal_function.handler = XG_BASE(orig_pcntl_exec_func); + } + } + + if (XG_BASE(orig_pcntl_fork_func)) { + orig = zend_hash_str_find_ptr(EG(function_table), "pcntl_fork", sizeof("pcntl_fork") - 1); + if (orig) { + orig->internal_function.handler = XG_BASE(orig_pcntl_fork_func); + } + } +} + +static int xdebug_closure_serialize_deny_wrapper(zval *object, unsigned char **buffer, size_t *buf_len, zend_serialize_data *data) +{ + zend_class_entry *ce = Z_OBJCE_P(object); + + if (!XG_BASE(in_var_serialisation)) { + zend_throw_exception_ex(NULL, 0, "Serialization of '%s' is not allowed", STR_NAME_VAL(ce->name)); + } + return FAILURE; +} + +#if PHP_VERSION_ID >= 80100 +static struct xdebug_fiber_entry* xdebug_fiber_entry_ctor(xdebug_vector *stack) +{ + struct xdebug_fiber_entry *tmp = xdmalloc(sizeof(struct xdebug_fiber_entry)); + + tmp->stack = stack; + + return tmp; +} + +static void xdebug_fiber_entry_dtor(struct xdebug_fiber_entry *entry) +{ + xdebug_vector_destroy(entry->stack); + xdfree(entry); +} + +static xdebug_str *create_key_for_fiber(zend_fiber_context *fiber) +{ + xdebug_str *tmp = xdebug_str_new(); + + xdebug_str_add_fmt(tmp, "{fiber:%0" PRIXPTR "}", ((uintptr_t) fiber)); + + return tmp; +} + +static void add_fiber_main(zend_fiber_context *fiber) +{ + xdebug_str *key = create_key_for_fiber(fiber); + function_stack_entry *tmp = (function_stack_entry*) xdebug_vector_push(XG_BASE(stack)); + + tmp->level = XDEBUG_VECTOR_COUNT(XG_BASE(stack)); + tmp->user_defined = XDEBUG_BUILT_IN; + tmp->function.type = XFUNC_FIBER; + tmp->function.object_class = NULL; + tmp->function.scope_class = NULL; + tmp->function.function = xdstrdup(key->d); + tmp->filename = zend_string_copy(zend_get_executed_filename_ex()); + tmp->lineno = zend_get_executed_lineno(); + + tmp->prev_memory = XG_BASE(prev_memory); + tmp->memory = zend_memory_usage(0); + XG_BASE(prev_memory) = tmp->memory; + + tmp->nanotime = xdebug_get_nanotime(); + + xdebug_str_free(key); +} + +static xdebug_vector* create_stack_for_fiber(zend_fiber_context *fiber) +{ + xdebug_vector *tmp_stack = xdebug_vector_alloc(sizeof(function_stack_entry), function_stack_entry_dtor); + xdebug_str *key = create_key_for_fiber(fiber); + struct xdebug_fiber_entry *entry = xdebug_fiber_entry_ctor(tmp_stack); + + xdebug_hash_add(XG_BASE(fiber_stacks), key->d, key->l, entry); + + xdebug_str_free(key); + + return tmp_stack; +} + +static void remove_stack_for_fiber(zend_fiber_context *fiber) +{ + xdebug_str *key = create_key_for_fiber(fiber); + + xdebug_hash_delete(XG_BASE(fiber_stacks), key->d, key->l); + + xdebug_str_free(key); +} + +static xdebug_vector *find_stack_for_fiber(zend_fiber_context *fiber) +{ + struct xdebug_fiber_entry *entry = NULL; + xdebug_str *key = create_key_for_fiber(fiber); + + xdebug_hash_find(XG_BASE(fiber_stacks), key->d, key->l, (void*) &entry); + + xdebug_str_free(key); + + return entry->stack; +} + +static void xdebug_fiber_switch_observer(zend_fiber_context *from, zend_fiber_context *to) +{ + xdebug_vector *current_stack; + + if (from->status == ZEND_FIBER_STATUS_DEAD) { + remove_stack_for_fiber(from); + } + if (to->status == ZEND_FIBER_STATUS_INIT) { + current_stack = create_stack_for_fiber(to); + } else { + current_stack = find_stack_for_fiber(to); + } + XG_BASE(stack) = current_stack; + + if (to->status == ZEND_FIBER_STATUS_INIT) { + add_fiber_main(to); + } +} +#endif + +#ifdef __linux__ +int read_systemd_private_tmp_directory(char **private_tmp) +{ + pid_t current_pid; + char *mountinfo_fn; + FILE *mountinfo_fd; + size_t bytes_read; + char buffer8192 = { 0 }; + xdebug_arg *lines; + int i; + int retval = 0; + + /* Open right file in /proc */ + current_pid = getpid(); + mountinfo_fn = xdebug_sprintf("/proc/%ld/mountinfo", current_pid); + mountinfo_fd = fopen(mountinfo_fn, "r"); + xdfree(mountinfo_fn); + if (!mountinfo_fd) { + return retval; + } + + /* Read contents and split in lines */ + bytes_read = fread(buffer, 1, sizeof(buffer), mountinfo_fd); + lines = xdebug_arg_ctor(); + xdebug_explode("\n", buffer, lines, -1); + + /* Check whether each line has /tmp/systemd-private, and parse accordingly. + * There is a " " in front as there is often also a /var/tmp/systemd-private + * entry that we need to ignore. */ + for (i = 0; i < lines->c; i++) { + const char *mountpoint; + const char *slash; + + mountpoint = strstr(lines->argsi, " /tmp/systemd-private"); + if (mountpoint == NULL) { + continue; + } + + mountpoint++; + + slash = strchr(mountpoint + 1, '/'); + if (!slash) { + continue; + } + + slash = strchr(slash + 1, '/'); + if (!slash) { + continue; + } + + *private_tmp = xdstrndup(mountpoint, slash - mountpoint); + + retval = 1; + break; + } + + /* Clean up and return */ + xdebug_arg_dtor(lines); + fclose(mountinfo_fd); + return retval; +} +#endif + +void xdebug_base_minit(INIT_FUNC_ARGS) +{ + /* Record Zend and Xdebug error callbacks, the actual setting is done in + * base on RINIT */ + xdebug_old_error_cb = zend_error_cb; + xdebug_new_error_cb = xdebug_error_cb; + + xdebug_old_execute_ex = zend_execute_ex; + zend_execute_ex = xdebug_execute_ex; + + xdebug_old_execute_internal = zend_execute_internal; + zend_execute_internal = xdebug_execute_internal; + + XG_BASE(error_reporting_override) = 0; + XG_BASE(error_reporting_overridden) = 0; + XG_BASE(output_is_tty) = OUTPUT_NOT_CHECKED; + +#if PHP_VERSION_ID >= 80100 + zend_observer_fiber_switch_register(xdebug_fiber_switch_observer); +#endif + + XG_BASE(private_tmp) = NULL; +#ifdef __linux__ + read_systemd_private_tmp_directory(&XG_BASE(private_tmp)); +#endif +} + +void xdebug_base_mshutdown() +{ + /* Reset compile, execute and error callbacks */ + zend_compile_file = old_compile_file; + zend_execute_ex = xdebug_old_execute_ex; + zend_execute_internal = xdebug_old_execute_internal; + zend_error_cb = xdebug_old_error_cb; + +#ifdef __linux__ + if (XG_BASE(private_tmp)) { + xdfree(XG_BASE(private_tmp)); + } +#endif +} + +void xdebug_base_post_startup() +{ + old_compile_file = zend_compile_file; + zend_compile_file = xdebug_compile_file; +} + +void xdebug_base_rinit() +{ + /* Hack: We check for a soap header here, if that's existing, we don't use + * Xdebug's error handler to keep soap fault from fucking up. */ + if ( + (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP) || XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) + && + (zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_SERVER), "HTTP_SOAPACTION", sizeof("HTTP_SOAPACTION") - 1) == NULL) + ) { + xdebug_base_use_xdebug_error_cb(); + xdebug_base_use_xdebug_throw_exception_hook(); + } + +#if PHP_VERSION_ID >= 80100 + XG_BASE(fiber_stacks) = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_fiber_entry_dtor); + XG_BASE(stack) = create_stack_for_fiber(EG(main_fiber_context)); +#else + XG_BASE(stack) = xdebug_vector_alloc(sizeof(function_stack_entry), function_stack_entry_dtor); +#endif + XG_BASE(in_debug_info) = 0; + XG_BASE(prev_memory) = 0; + XG_BASE(function_count) = -1; + XG_BASE(last_eval_statement) = NULL; + XG_BASE(last_exception_trace) = NULL; + + /* Initialize start time */ + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) || XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + XG_BASE(start_nanotime) = xdebug_get_nanotime(); + } else { + XG_BASE(start_nanotime) = 0; + } + + XG_BASE(in_var_serialisation) = 0; + zend_ce_closure->serialize = xdebug_closure_serialize_deny_wrapper; + + /* Signal that we're in a request now */ + XG_BASE(in_execution) = 1; + + /* filters */ + XG_BASE(filter_type_code_coverage) = XDEBUG_FILTER_NONE; + XG_BASE(filter_type_stack) = XDEBUG_FILTER_NONE; + XG_BASE(filter_type_tracing) = XDEBUG_FILTER_NONE; + XG_BASE(filters_code_coverage) = xdebug_llist_alloc(xdebug_llist_string_dtor); + XG_BASE(filters_stack) = xdebug_llist_alloc(xdebug_llist_string_dtor); + XG_BASE(filters_tracing) = xdebug_llist_alloc(xdebug_llist_string_dtor); + + xdebug_base_overloaded_functions_setup(); + + if (XG_BASE(private_tmp)) { + xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_INFO, "PRIVTMP", "Systemd Private Temp Directory is enabled (%s)", XG_BASE(private_tmp)); + } +} + +void xdebug_base_post_deactivate() +{ +#if PHP_VERSION_ID >= 80100 + xdebug_hash_destroy(XG_BASE(fiber_stacks)); + XG_BASE(fiber_stacks) = NULL; +#else + xdebug_vector_destroy(XG_BASE(stack)); +#endif + XG_BASE(stack) = NULL; + + XG_BASE(in_debug_info) = 0; + + if (XG_BASE(last_eval_statement)) { + zend_string_release(XG_BASE(last_eval_statement)); + XG_BASE(last_eval_statement) = NULL; + } + if (XG_BASE(last_exception_trace)) { + xdfree(XG_BASE(last_exception_trace)); + XG_BASE(last_exception_trace) = NULL; + } + + /* filters */ + xdebug_llist_destroy(XG_BASE(filters_code_coverage), NULL); + xdebug_llist_destroy(XG_BASE(filters_stack), NULL); + xdebug_llist_destroy(XG_BASE(filters_tracing), NULL); + XG_BASE(filters_tracing) = NULL; + XG_BASE(filters_code_coverage) = NULL; + + xdebug_base_overloaded_functions_restore(); +} + +void xdebug_base_rshutdown() +{ + /* Signal that we're no longer in a request */ + XG_BASE(in_execution) = 0; +} + +/* Error callback for formatting stack traces */ +#if PHP_VERSION_ID >= 80100 +static void xdebug_error_cb(int orig_type, zend_string *error_filename, const unsigned int error_lineno, zend_string *message) +{ + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + int type = orig_type & E_ALL; + char *error_type_str = xdebug_error_type(type); + + xdebug_debugger_error_cb(error_filename, error_lineno, type, error_type_str, ZSTR_VAL(message)); + + xdfree(error_type_str); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + xdebug_develop_error_cb(orig_type, error_filename, error_lineno, message); + } else { + xdebug_old_error_cb(orig_type, error_filename, error_lineno, message); + } +} +#else +static void xdebug_error_cb(int orig_type, const char *error_filename, const unsigned int error_lineno, zend_string *message) +{ + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + int type = orig_type & E_ALL; + char *error_type_str = xdebug_error_type(type); + zend_string *tmp_error_filename = zend_string_init(error_filename, strlen(error_filename), 0); + + xdebug_debugger_error_cb(tmp_error_filename, error_lineno, type, error_type_str, ZSTR_VAL(message)); + + zend_string_release(tmp_error_filename); + xdfree(error_type_str); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + xdebug_develop_error_cb(orig_type, error_filename, error_lineno, message); + } else { + xdebug_old_error_cb(orig_type, error_filename, error_lineno, message); + } +} +#endif + +void xdebug_base_use_original_error_cb(void) +{ + zend_error_cb = xdebug_old_error_cb; +} + +void xdebug_base_use_xdebug_error_cb(void) +{ + zend_error_cb = xdebug_new_error_cb; +} + +static void xdebug_throw_exception_hook(zend_object *exception) +{ + zval *code, *message, *file, *line; + zend_class_entry *exception_ce; + char *code_str = NULL; + zval dummy; + + if (!XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP) && !XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + return; + } + + if (!exception) { + return; + } + + if (zend_is_unwind_exit(exception)) { + return; + } + +#if PHP_VERSION_ID >= 80100 + if (zend_is_graceful_exit(exception)) { + return; + } +#endif + + exception_ce = exception->ce; + + code = zend_read_property(exception_ce, exception, "code", sizeof("code")-1, 0, &dummy); + message = zend_read_property(exception_ce, exception, "message", sizeof("message")-1, 0, &dummy); + file = zend_read_property(exception_ce, exception, "file", sizeof("file")-1, 0, &dummy); + line = zend_read_property(exception_ce, exception, "line", sizeof("line")-1, 0, &dummy); + + if (Z_TYPE_P(code) == IS_LONG) { + if (Z_LVAL_P(code) != 0) { + code_str = xdebug_sprintf("%lu", Z_LVAL_P(code)); + } + } else if (Z_TYPE_P(code) != IS_STRING) { + code_str = xdstrdup(""); + } + + if (Z_TYPE_P(message) != IS_STRING) { + message = NULL; + } + + convert_to_string_ex(file); + convert_to_long_ex(line); + + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + xdebug_develop_throw_exception_hook(exception, file, line, code, code_str, message); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + xdebug_debugger_throw_exception_hook(exception, file, line, code, code_str, message); + } + + /* Free code_str if necessary */ + if (code_str) { + xdfree(code_str); + } +} + +void xdebug_base_use_xdebug_throw_exception_hook(void) +{ + zend_throw_exception_hook = xdebug_throw_exception_hook; +} + +/* {{{ proto void xdebug_set_time_limit(void) + Dummy function to prevent time limit from being set within the script */ +PHP_FUNCTION(xdebug_set_time_limit) +{ + if (!xdebug_is_debug_connection_active()) { + XG_BASE(orig_set_time_limit_func)(INTERNAL_FUNCTION_PARAM_PASSTHRU); + } + + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto int xdebug_error_reporting(void) + Dummy function to return original error reporting level when 'eval' has turned it into 0 */ +PHP_FUNCTION(xdebug_error_reporting) +{ + if (ZEND_NUM_ARGS() == 0 && XG_BASE(error_reporting_overridden) && xdebug_is_debug_connection_active()) { + RETURN_LONG(XG_BASE(error_reporting_override)); + } + XG_BASE(orig_error_reporting_func)(INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + +/* {{{ proto void xdebug_pcntl_exec(void) + Dummy function to stop profiling when we run pcntl_exec */ +PHP_FUNCTION(xdebug_pcntl_exec) +{ + /* We need to stop the profiler and trace files here */ + xdebug_profiler_pcntl_exec_handler(); + + XG_BASE(orig_pcntl_exec_func)(INTERNAL_FUNCTION_PARAM_PASSTHRU); +} +/* }}} */ + +/* {{{ proto int xdebug_pcntl_fork(void) + Dummy function to set a new connection when forking a process */ +PHP_FUNCTION(xdebug_pcntl_fork) +{ + XG_BASE(orig_pcntl_fork_func)(INTERNAL_FUNCTION_PARAM_PASSTHRU); + + xdebug_debugger_restart_if_pid_changed(); +} +/* }}} */
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/base/base.h
Changed
(renamed from xdebug-3.1.5/src/base/base.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/base/base_globals.h
Added
@@ -0,0 +1,88 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __XDEBUG_BASE_GLOBALS_H__ +#define __XDEBUG_BASE_GLOBALS_H__ + +#include "lib/hash.h" +#include "lib/llist.h" +#include "lib/vector.h" + + +#if PHP_WIN32 +typedef void (WINAPI *WIN_PRECISE_TIME_FUNC)(LPFILETIME); +#endif + +typedef struct _xdebug_nanotime_context { + uint64_t start_abs; + uint64_t last_abs; +#if PHP_WIN32 | HAVE_XDEBUG_CLOCK_GETTIME | HAVE_XDEBUG_CLOCK_GETTIME_NSEC_NP + uint64_t start_rel; + uint64_t last_rel; + int use_rel_time; +#endif +#if PHP_WIN32 + WIN_PRECISE_TIME_FUNC win_precise_time_func; + uint64_t win_freq; +#endif +} xdebug_nanotime_context; + + +typedef struct _xdebug_base_globals_t { + xdebug_vector *stack; +#if PHP_VERSION_ID >= 80100 + xdebug_hash *fiber_stacks; +#endif + xdebug_nanotime_context nanotime_context; + uint64_t start_nanotime; + unsigned int prev_memory; + zif_handler orig_set_time_limit_func; + zif_handler orig_error_reporting_func; + zif_handler orig_pcntl_exec_func; + zif_handler orig_pcntl_fork_func; + int output_is_tty; + zend_bool in_debug_info; + zend_long error_reporting_override; + zend_bool error_reporting_overridden; + unsigned int function_count; + zend_string *last_eval_statement; + char *last_exception_trace; + + /* in-execution checking */ + zend_bool in_execution; + zend_bool in_var_serialisation; + + /* Systemd Private Temp */ + char *private_tmp; + + /* filters */ + zend_long filter_type_code_coverage; + zend_long filter_type_stack; + zend_long filter_type_tracing; + xdebug_llist *filters_code_coverage; + xdebug_llist *filters_stack; + xdebug_llist *filters_tracing; + + /* PHP versions */ + const char *php_version_compile_time; + const char *php_version_run_time; +} xdebug_base_globals_t; + +typedef struct _xdebug_base_settings_t { + zend_long max_nesting_level; +} xdebug_base_settings_t; + +#endif // __XDEBUG_BASE_GLOBALS_H__
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/base/base_private.h
Changed
(renamed from xdebug-3.1.5/src/base/base_private.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/base/filter.c
Changed
(renamed from xdebug-3.1.5/src/base/filter.c)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/base/filter.h
Added
@@ -0,0 +1,42 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#ifndef XDEBUG_FILTER_H +#define XDEBUG_FILTER_H + +#include "lib/php-header.h" +#include "php_xdebug.h" + +int xdebug_is_stack_frame_filtered(int filter_type, function_stack_entry *fse); +int xdebug_is_top_stack_frame_filtered(int filter_type); +void xdebug_filter_register_constants(INIT_FUNC_ARGS); +void xdebug_filter_run(function_stack_entry *fse); +void xdebug_filter_run_code_coverage(zend_op_array *op_array); +void xdebug_filter_run_internal(function_stack_entry *fse, int group, unsigned char *filtered_flag, int type, xdebug_llist *filters); + +#define XDEBUG_FILTER_NONE 0x000 +#define XDEBUG_FILTER_CODE_COVERAGE 0x100 +#define XDEBUG_FILTER_STACK 0x200 +#define XDEBUG_FILTER_TRACING 0x300 + +#define XDEBUG_PATH_INCLUDE 0x01 +#define XDEBUG_PATH_EXCLUDE 0x02 +#define XDEBUG_NAMESPACE_INCLUDE 0x11 +#define XDEBUG_NAMESPACE_EXCLUDE 0x12 + +PHP_FUNCTION(xdebug_set_filter); + +#endif +
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/coverage/branch_info.c
Added
@@ -0,0 +1,472 @@ +/* + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2020 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to the 2-Clause BSD license which is | + | available through the LICENSE file, or online at | + | http://opensource.org/licenses/bsd-license.php | + +----------------------------------------------------------------------+ + */ +#include <stdlib.h> +#include <math.h> + +#include "php_xdebug.h" +#include "code_coverage_private.h" + +#include "lib/hash.h" +#include "lib/log.h" +#include "lib/str.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +xdebug_branch_info *xdebug_branch_info_create(unsigned int size) +{ + xdebug_branch_info *tmp; + + tmp = calloc(1, sizeof(xdebug_branch_info)); + tmp->size = size; + tmp->branches = calloc(size, sizeof(xdebug_branch)); + tmp->entry_points = xdebug_set_create(size); + tmp->starts = xdebug_set_create(size); + tmp->ends = xdebug_set_create(size); + + tmp->path_info.paths_count = 0; + tmp->path_info.paths_size = 0; + tmp->path_info.paths = NULL; + + return tmp; +} + +void xdebug_branch_info_free(xdebug_branch_info *branch_info) +{ + unsigned int i; + + for (i = 0; i < branch_info->path_info.paths_count; i++) { + free(branch_info->path_info.pathsi->elements); + free(branch_info->path_info.pathsi); + } + free(branch_info->path_info.paths); + xdebug_hash_destroy(branch_info->path_info.path_hash); + free(branch_info->branches); + xdebug_set_free(branch_info->entry_points); + xdebug_set_free(branch_info->starts); + xdebug_set_free(branch_info->ends); + free(branch_info); +} + +void xdebug_branch_info_update(xdebug_branch_info *branch_info, unsigned int pos, unsigned int lineno, unsigned int outidx, unsigned int jump_pos) +{ + xdebug_set_add(branch_info->ends, pos); + if (outidx < XDEBUG_BRANCH_MAX_OUTS) { + branch_info->branchespos.outsoutidx = jump_pos; + if (outidx + 1 > branch_info->branchespos.outs_count) { + branch_info->branchespos.outs_count = outidx + 1; + } + } + branch_info->branchespos.start_lineno = lineno; +} + +static void only_leave_first_catch(zend_op_array *opa, xdebug_branch_info *branch_info, int position) +{ + unsigned int exit_jmp; +#if ZEND_USE_ABS_JMP_ADDR + zend_op *base_address = &(opa->opcodes0); +#endif + + if (opa->opcodesposition.opcode == ZEND_FETCH_CLASS) { + position++; + } + + if (opa->opcodesposition.opcode != ZEND_CATCH) { + return; + } + + xdebug_set_remove(branch_info->entry_points, position); + + if (opa->opcodesposition.extended_value & ZEND_LAST_CATCH) { + return; + } + exit_jmp = XDEBUG_ZNODE_JMP_LINE(opa->opcodesposition.op2, position, base_address); + + if (opa->opcodesexit_jmp.opcode == ZEND_FETCH_CLASS) { + exit_jmp++; + } + if (opa->opcodesexit_jmp.opcode == ZEND_CATCH) { + only_leave_first_catch(opa, branch_info, exit_jmp); + } +} + +void xdebug_branch_post_process(zend_op_array *opa, xdebug_branch_info *branch_info) +{ + unsigned int i; + int in_branch = 0, last_start = -1; +#if ZEND_USE_ABS_JMP_ADDR + zend_op *base_address = &(opa->opcodes0); +#endif + + /* Figure out which CATCHes are chained, and hence which ones should be + * considered entry points */ + for (i = 0; i < branch_info->entry_points->size; i++) { + if (xdebug_set_in(branch_info->entry_points, i) && opa->opcodesi.opcode == ZEND_CATCH) { +#if ZEND_USE_ABS_JMP_ADDR +# if PHP_VERSION_ID >= 80200 + if (opa->opcodesi.op2.jmp_addr != (void*) -1) { +# else + if (opa->opcodesi.op2.jmp_addr != NULL) { +# endif +#else + if (opa->opcodesi.op2.jmp_offset != 0) { +#endif + only_leave_first_catch(opa, branch_info, XDEBUG_ZNODE_JMP_LINE(opa->opcodesi.op2, i, base_address)); + } + } + } + + for (i = 0; i < branch_info->starts->size; i++) { + if (xdebug_set_in(branch_info->starts, i)) { + if (in_branch) { + branch_info->brancheslast_start.outs_count = 1; + branch_info->brancheslast_start.outs0 = i; + branch_info->brancheslast_start.end_op = i-1; + branch_info->brancheslast_start.end_lineno = branch_info->branchesi.start_lineno; + } + last_start = i; + in_branch = 1; + } + if (xdebug_set_in(branch_info->ends, i)) { + size_t j; + + for (j = 0; j < branch_info->branchesi.outs_count; j++) { + branch_info->brancheslast_start.outsj = branch_info->branchesi.outsj; + } + branch_info->brancheslast_start.outs_count = branch_info->branchesi.outs_count; + branch_info->brancheslast_start.end_op = i; + branch_info->brancheslast_start.end_lineno = branch_info->branchesi.start_lineno; + in_branch = 0; + } + } +} + +static void xdebug_path_add(xdebug_path *path, unsigned int nr) +{ + if (!path) { + return; + } + if (path->elements_count == path->elements_size) { + path->elements_size += 32; + path->elements = realloc(path->elements, sizeof(unsigned int) * path->elements_size); + } + path->elementspath->elements_count = nr; + path->elements_count++; +} + +static void xdebug_path_info_add_path(xdebug_path_info *path_info, xdebug_path *path) +{ + if (path_info->paths_count == path_info->paths_size) { + path_info->paths_size += 32; + path_info->paths = realloc(path_info->paths, sizeof(xdebug_path*) * path_info->paths_size); + } + path_info->pathspath_info->paths_count = path; + path_info->paths_count++; +} + +static void xdebug_path_info_make_sure_level_exists(xdebug_path_info *path_info, unsigned int level) +{ + unsigned int i = 0, orig_size; + + orig_size = path_info->paths_size; + + if (level >= path_info->paths_size) { + path_info->paths_size = level + 32; + path_info->paths = realloc(path_info->paths, sizeof(xdebug_path*) * path_info->paths_size); + + for (i = orig_size; i < XG_COV(branches).size; i++) { + XG_COV(branches).last_branch_nri = -1; + } + + for (i = orig_size; i < path_info->paths_size; i++) { + path_info->pathsi = NULL; + } + } +} + +void xdebug_path_info_add_path_for_level(xdebug_path_info *path_info, xdebug_path *path, unsigned int level) +{ + xdebug_path_info_make_sure_level_exists(path_info, level); + path_info->pathslevel = path; +} + +xdebug_path *xdebug_path_info_get_path_for_level(xdebug_path_info *path_info, unsigned int level) +{ + xdebug_path_info_make_sure_level_exists(path_info, level); + return path_info->pathslevel; +} + +xdebug_path *xdebug_path_new(xdebug_path *old_path) +{ + xdebug_path *tmp; + tmp = calloc(1, sizeof(xdebug_path)); + + if (old_path) { + unsigned i; + + for (i = 0; i < old_path->elements_count; i++) { + xdebug_path_add(tmp, old_path->elementsi); + } + } + return tmp; +} + +void xdebug_path_free(xdebug_path *path) +{ + if (path->elements) { + free(path->elements); + } + free(path); +} + +static unsigned int xdebug_branch_find_last_element(xdebug_path *path) +{ + return path->elementspath->elements_count-1; +} + +static int xdebug_path_exists(xdebug_path *path, unsigned int elem1, unsigned int elem2) +{ + unsigned int i; + + for (i = 0; i < path->elements_count - 1; i++) { + if (path->elementsi == elem1 && path->elementsi + 1 == elem2) { + return 1; + } + } + return 0; +} + +static void xdebug_branch_find_path(unsigned int nr, xdebug_branch_info *branch_info, xdebug_path *prev_path) +{ + unsigned int last; + xdebug_path *new_path; + int found = 0; + size_t i = 0; + + if (branch_info->path_info.paths_count > 4095) { + return; + } + + new_path = xdebug_path_new(prev_path); + xdebug_path_add(new_path, nr); + + last = xdebug_branch_find_last_element(new_path); + + for (i = 0; i < branch_info->branchesnr.outs_count; i++) { + int out = branch_info->branchesnr.outsi; + if (out != 0 && out != XDEBUG_JMP_EXIT && !xdebug_path_exists(new_path, last, out)) { + xdebug_branch_find_path(out, branch_info, new_path); + found = 1; + } + } + + if (found) { + xdebug_path_free(new_path); + return; + } + + xdebug_path_info_add_path(&(branch_info->path_info), new_path); +} + +xdebug_path_info *xdebug_path_info_ctor(void) +{ + xdebug_path_info *tmp; + + tmp = xdmalloc(sizeof(xdebug_path_info)); + tmp->paths_count = 0; + tmp->paths_size = 0; + tmp->paths = NULL; + tmp->path_hash = NULL; + + return tmp; +} + +void xdebug_path_info_dtor(xdebug_path_info *path_info) +{ + unsigned int i; + + for (i = 0; i < path_info->paths_count; i++) { + xdebug_path_free(path_info->pathsi); + } + xdfree(path_info->paths); + path_info->paths = NULL; + if (path_info->path_hash) { + xdebug_hash_destroy(path_info->path_hash); + path_info->path_hash = NULL; + } + + xdfree(path_info); +} + +void xdebug_create_key_for_path(xdebug_path *path, xdebug_str *str) +{ + unsigned int i; + char temp_nr16; + + for (i = 0; i < path->elements_count; i++) { + snprintf(temp_nr, 15, "%u:", path->elementsi); + xdebug_str_add(str, temp_nr, 0); + } +} + +void xdebug_branch_find_paths(xdebug_branch_info *branch_info) +{ + unsigned int i; + + for (i = 0; i < branch_info->entry_points->size; i++) { + if (xdebug_set_in(branch_info->entry_points, i)) { + xdebug_branch_find_path(i, branch_info, NULL); + } + } + + branch_info->path_info.path_hash = xdebug_hash_alloc(128, NULL); + + for (i = 0; i < branch_info->path_info.paths_count; i++) { + xdebug_str str = XDEBUG_STR_INITIALIZER; + xdebug_create_key_for_path(branch_info->path_info.pathsi, &str); + xdebug_hash_add(branch_info->path_info.path_hash, str.d, str.l, branch_info->path_info.pathsi); + xdfree(str.d); + } +} + +void xdebug_branch_info_mark_reached(zend_string *filename, char *function_name, zend_op_array *op_array, long opcode_nr) +{ + xdebug_coverage_file *file; + xdebug_coverage_function *function; + xdebug_branch_info *branch_info; + + if (XG_COV(previous_mark_filename) && zend_string_equals(XG_COV(previous_mark_filename), filename)) { + file = XG_COV(previous_mark_file); + } else { + if (!xdebug_hash_find(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &file)) { + return; + } + if (XG_COV(previous_mark_filename)) { + zend_string_release(XG_COV(previous_mark_filename)); + } + XG_COV(previous_mark_filename) = zend_string_copy(file->name); + XG_COV(previous_mark_file) = file; + } + + /* If there is no branch info, we don't have to do more */ + if (!file->has_branch_info) { + return; + } + + /* Check if the function already exists in the hash */ + if (!xdebug_hash_find(file->functions, function_name, strlen(function_name), (void *) &function)) { + return; + } + + branch_info = function->branch_info; + + if (opcode_nr != 0 && xdebug_set_in(branch_info->entry_points, opcode_nr)) { + xdebug_code_coverage_end_of_function(op_array, filename, function_name); + xdebug_code_coverage_start_of_function(op_array, function_name); + } + + if (xdebug_set_in(branch_info->starts, opcode_nr)) { + char *key; + void *dummy; + function_stack_entry *tail_fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + + /* Mark out for previous branch, if one is set */ + if (XG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)) != -1) { + size_t i = 0; + + for (i = 0; i < branch_info->branchesXG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)).outs_count; i++) { + if (branch_info->branchesXG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)).outsi == opcode_nr) { + branch_info->branchesXG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)).outs_hiti = 1; + } + } + } + + key = xdebug_sprintf("%d:%d:%d", opcode_nr, XG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)), tail_fse->function_nr); + + if (!xdebug_hash_find(XG_COV(visited_branches), key, strlen(key), (void*) &dummy)) { + xdebug_path_add(XG_COV(paths_stack)->pathsXDEBUG_VECTOR_COUNT(XG_BASE(stack)), opcode_nr); + xdebug_hash_add(XG_COV(visited_branches), key, strlen(key), NULL); + } + xdfree(key); + + branch_info->branchesopcode_nr.hit = 1; + + XG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)) = opcode_nr; + } +} + +void xdebug_branch_info_mark_end_of_function_reached(zend_string *filename, char *function_name, char *key, int key_len) +{ + xdebug_coverage_file *file; + xdebug_coverage_function *function; + xdebug_branch_info *branch_info; + xdebug_path *path; + + if (XG_COV(previous_mark_filename) && zend_string_equals(XG_COV(previous_mark_filename), filename) == 0) { + file = XG_COV(previous_mark_file); + } else { + if (!xdebug_hash_find(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &file)) { + return; + } + zend_string_release(XG_COV(previous_mark_filename)); + XG_COV(previous_mark_filename) = zend_string_copy(file->name); + XG_COV(previous_mark_file) = file; + } + + /* If there is no branch info, we don't have to do more */ + if (!file->has_branch_info) { + return; + } + + /* Check if the function already exists in the hash */ + if (!xdebug_hash_find(file->functions, function_name, strlen(function_name), (void *) &function)) { + return; + } + + branch_info = function->branch_info; + + if (!xdebug_hash_find(branch_info->path_info.path_hash, key, key_len, (void *) &path)) { + return; + } + path->hit = 1; +} + +void xdebug_branch_info_add_branches_and_paths(zend_string *filename, char *function_name, xdebug_branch_info *branch_info) +{ + xdebug_coverage_file *file; + xdebug_coverage_function *function; + + if (XG_COV(previous_filename) && zend_string_equals(XG_COV(previous_filename), filename) == 0) { + file = XG_COV(previous_file); + } else { + /* Check if the file already exists in the hash */ + if (!xdebug_hash_find(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &file)) { + /* The file does not exist, so we add it to the hash */ + file = xdebug_coverage_file_ctor(filename); + + xdebug_hash_add(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), file); + } + zend_string_release(XG_COV(previous_filename)); + XG_COV(previous_filename) = zend_string_copy(file->name); + XG_COV(previous_file) = file; + } + + /* Check if the function already exists in the hash */ + if (!xdebug_hash_find(file->functions, function_name, strlen(function_name), (void *) &function)) { + /* The file does not exist, so we add it to the hash */ + function = xdebug_coverage_function_ctor(function_name); + + xdebug_hash_add(file->functions, function_name, strlen(function_name), function); + } + + if (branch_info) { + file->has_branch_info = 1; + } + function->branch_info = branch_info; +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/coverage/branch_info.h
Changed
(renamed from xdebug-3.1.5/src/coverage/branch_info.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/coverage/code_coverage.c
Added
@@ -0,0 +1,1186 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2021 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "php_xdebug.h" +#include "zend_extensions.h" + +#include "branch_info.h" +#include "code_coverage_private.h" + +#include "base/base.h" +#include "base/filter.h" +#include "lib/compat.h" +#include "lib/set.h" +#include "lib/var.h" +#include "tracing/tracing.h" + +/* True globals */ +int zend_xdebug_filter_offset = -1; +int zend_xdebug_cc_run_offset = -1; + +extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); + +static void xdebug_coverage_line_dtor(void *data) +{ + xdebug_coverage_line *line = (xdebug_coverage_line *) data; + + xdfree(line); +} + +xdebug_coverage_file *xdebug_coverage_file_ctor(zend_string *filename) +{ + xdebug_coverage_file *file; + + file = xdmalloc(sizeof(xdebug_coverage_file)); + file->name = zend_string_copy(filename); + file->lines = xdebug_hash_alloc(128, xdebug_coverage_line_dtor); + file->functions = xdebug_hash_alloc(128, xdebug_coverage_function_dtor); + file->has_branch_info = 0; + + return file; +} + +static void xdebug_coverage_file_dtor(void *data) +{ + xdebug_coverage_file *file = (xdebug_coverage_file *) data; + + xdebug_hash_destroy(file->lines); + xdebug_hash_destroy(file->functions); + zend_string_release(file->name); + xdfree(file); +} + +xdebug_coverage_function *xdebug_coverage_function_ctor(char *function_name) +{ + xdebug_coverage_function *function; + + function = xdmalloc(sizeof(xdebug_coverage_function)); + function->name = xdstrdup(function_name); + function->branch_info = NULL; + + return function; +} + +void xdebug_coverage_function_dtor(void *data) +{ + xdebug_coverage_function *function = (xdebug_coverage_function *) data; + + if (function->branch_info) { + xdebug_branch_info_free(function->branch_info); + } + xdfree(function->name); + xdfree(function); +} + +static void xdebug_func_format(char *buffer, size_t buffer_size, xdebug_func *func) +{ + if (func->type == XFUNC_NORMAL) { + int len = strlen(func->function); + + if (len + 1 > buffer_size) { + goto error; + } + memcpy(buffer, func->function, len); + bufferlen = '\0'; + return; + } + + if (func->type == XFUNC_MEMBER) { + int func_len = strlen(func->function); + int len = ZSTR_LEN(func->object_class) + 2 + func_len; + + if (len + 1 > buffer_size) { + goto error; + } + memcpy(buffer, ZSTR_VAL(func->object_class), ZSTR_LEN(func->object_class)); + memcpy(buffer + ZSTR_LEN(func->object_class), "->", 2); + memcpy(buffer + ZSTR_LEN(func->object_class) + 2, func->function, func_len); + bufferlen = '\0'; + return; + } + +error: + memcpy(buffer, "?", 1); + buffer1 = '\0'; +} + +static void xdebug_build_fname_from_oparray(xdebug_func *tmp, zend_op_array *opa) +{ + int wrapped = 0; + + memset(tmp, 0, sizeof(xdebug_func)); + + if (opa->function_name) { + if (opa->fn_flags & ZEND_ACC_CLOSURE) { + tmp->function = xdebug_wrap_closure_location_around_function_name(opa, STR_NAME_VAL(opa->function_name)); + wrapped = 1; + } else if ( + opa->fn_flags & ZEND_ACC_TRAIT_CLONE + || (opa->scope && opa->scope->ce_flags & ZEND_ACC_TRAIT) + ) { + tmp->function = xdebug_wrap_location_around_function_name("trait-method", opa, STR_NAME_VAL(opa->function_name)); + wrapped = 1; + } else { + tmp->function = xdstrdup(STR_NAME_VAL(opa->function_name)); + } + } else { + tmp->function = xdstrdup("{main}"); + tmp->type = XFUNC_MAIN; + } + + if (opa->scope && !wrapped) { + tmp->type = XFUNC_MEMBER; + tmp->object_class = zend_string_copy(opa->scope->name); + } else { + tmp->type = XFUNC_NORMAL; + } +} + +static void xdebug_print_opcode_info(zend_execute_data *execute_data, const zend_op *cur_opcode) +{ + zend_op_array *op_array = &execute_data->func->op_array; + xdebug_func func_info; + char function_name1024; + long opnr = execute_data->opline - execute_data->func->op_array.opcodes; + + xdebug_build_fname_from_oparray(&func_info, op_array); + xdebug_func_format(function_name, sizeof(function_name), &func_info); + if (func_info.object_class) { + zend_string_release(func_info.object_class); + } + if (func_info.scope_class) { + zend_string_release(func_info.scope_class); + } + if (func_info.function) { + xdfree(func_info.function); + } + + xdebug_branch_info_mark_reached(op_array->filename, function_name, op_array, opnr); +} + +static int xdebug_check_branch_entry_handler(XDEBUG_OPCODE_HANDLER_ARGS) +{ + zend_op_array *op_array = &execute_data->func->op_array; + const zend_op *cur_opcode = execute_data->opline; + + if (!op_array->reservedXG_COV(code_coverage_filter_offset) && XG_COV(code_coverage_active)) { + xdebug_print_opcode_info(execute_data, cur_opcode); + } + + return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); +} + +static void xdebug_count_line(zend_string *filename, int lineno, int executable, int deadcode) +{ + xdebug_coverage_file *file; + xdebug_coverage_line *line; + + if (XG_COV(previous_filename) && zend_string_equals(XG_COV(previous_filename), filename)) { + file = XG_COV(previous_file); + } else { + /* Check if the file already exists in the hash */ + if (!xdebug_hash_find(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &file)) { + /* The file does not exist, so we add it to the hash */ + file = xdebug_coverage_file_ctor(filename); + + xdebug_hash_add(XG_COV(code_coverage_info), ZSTR_VAL(filename), ZSTR_LEN(filename), file); + } + if (XG_COV(previous_filename)) { + zend_string_release(XG_COV(previous_filename)); + } + XG_COV(previous_filename) = zend_string_copy(file->name); + XG_COV(previous_file) = file; + } + + /* Check if the line already exists in the hash */ + if (!xdebug_hash_index_find(file->lines, lineno, (void *) &line)) { + line = xdmalloc(sizeof(xdebug_coverage_line)); + line->lineno = lineno; + line->count = 0; + line->executable = 0; + + xdebug_hash_index_add(file->lines, lineno, line); + } + + if (executable) { + if (line->executable != 1 && deadcode) { + line->executable = 2; + } else { + line->executable = 1; + } + } else { + line->count++; + } +} + +static int xdebug_common_override_handler(XDEBUG_OPCODE_HANDLER_ARGS) +{ + zend_op_array *op_array = &execute_data->func->op_array; + const zend_op *cur_opcode = execute_data->opline; + + if (!op_array->reservedXG_COV(code_coverage_filter_offset) && XG_COV(code_coverage_active)) { + int lineno; + + lineno = cur_opcode->lineno; + + xdebug_print_opcode_info(execute_data, cur_opcode); + xdebug_count_line(op_array->filename, lineno, 0, 0); + } + + return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); +} + +static int xdebug_coverage_include_or_eval_handler(XDEBUG_OPCODE_HANDLER_ARGS) +{ + zend_op_array *op_array = &execute_data->func->op_array; + const zend_op *opline = execute_data->opline; + + xdebug_coverage_record_if_active(execute_data, op_array); + + return xdebug_call_original_opcode_handler_if_set(opline->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); +} + +static void prefill_from_opcode(zend_string *filename, zend_op opcode, int deadcode) +{ + if ( + opcode.opcode != ZEND_NOP && + opcode.opcode != ZEND_EXT_NOP && + opcode.opcode != ZEND_RECV && + opcode.opcode != ZEND_RECV_INIT + && opcode.opcode != ZEND_OP_DATA + && opcode.opcode != ZEND_TICKS + && opcode.opcode != ZEND_FAST_CALL + && opcode.opcode != ZEND_RECV_VARIADIC + ) { + xdebug_count_line(filename, opcode.lineno, 1, deadcode); + } +} + +#define XDEBUG_ZNODE_ELEM(node,var) node.var + +static int xdebug_find_jumps(zend_op_array *opa, unsigned int position, size_t *jump_count, int *jumps) +{ +#if ZEND_USE_ABS_JMP_ADDR + zend_op *base_address = &(opa->opcodes0); +#endif + + zend_op opcode = opa->opcodesposition; + if (opcode.opcode == ZEND_JMP) { + jumps0 = XDEBUG_ZNODE_JMP_LINE(opcode.op1, position, base_address); + *jump_count = 1; + return 1; + + } else if ( + opcode.opcode == ZEND_JMPZ || + opcode.opcode == ZEND_JMPNZ || + opcode.opcode == ZEND_JMPZ_EX || + opcode.opcode == ZEND_JMPNZ_EX + ) { + jumps0 = position + 1; + jumps1 = XDEBUG_ZNODE_JMP_LINE(opcode.op2, position, base_address); + *jump_count = 2; + return 1; + +#if PHP_VERSION_ID < 80200 + } else if (opcode.opcode == ZEND_JMPZNZ) { + jumps0 = XDEBUG_ZNODE_JMP_LINE(opcode.op2, position, base_address); + jumps1 = position + ((int32_t) opcode.extended_value / (int32_t) sizeof(zend_op)); + *jump_count = 2; + return 1; +#endif + + } else if (opcode.opcode == ZEND_FE_FETCH_R || opcode.opcode == ZEND_FE_FETCH_RW) { + jumps0 = position + 1; + jumps1 = position + (opcode.extended_value / sizeof(zend_op)); + *jump_count = 2; + return 1; + + } else if (opcode.opcode == ZEND_FE_RESET_R || opcode.opcode == ZEND_FE_RESET_RW) { + jumps0 = position + 1; + jumps1 = XDEBUG_ZNODE_JMP_LINE(opcode.op2, position, base_address); + *jump_count = 2; + return 1; + + } else if (opcode.opcode == ZEND_CATCH) { + *jump_count = 2; + jumps0 = position + 1; + if (!(opcode.extended_value & ZEND_LAST_CATCH)) { + jumps1 = XDEBUG_ZNODE_JMP_LINE(opcode.op2, position, base_address); + if (jumps1 == jumps0) { + jumps1 = XDEBUG_JMP_NOT_SET; + *jump_count = 1; + } + } else { + jumps1 = XDEBUG_JMP_EXIT; + } + return 1; + + } else if (opcode.opcode == ZEND_GOTO) { + jumps0 = XDEBUG_ZNODE_JMP_LINE(opcode.op1, position, base_address); + *jump_count = 1; + return 1; + + } else if (opcode.opcode == ZEND_FAST_CALL) { + jumps0 = XDEBUG_ZNODE_JMP_LINE(opcode.op1, position, base_address); + jumps1 = position + 1; + *jump_count = 2; + return 1; + + } else if (opcode.opcode == ZEND_FAST_RET) { + jumps0 = XDEBUG_JMP_EXIT; + *jump_count = 1; + return 1; + + } else if ( + opcode.opcode == ZEND_GENERATOR_RETURN || + opcode.opcode == ZEND_EXIT || + opcode.opcode == ZEND_THROW || + opcode.opcode == ZEND_MATCH_ERROR || + opcode.opcode == ZEND_RETURN + ) { + jumps0 = XDEBUG_JMP_EXIT; + *jump_count = 1; + return 1; + } else if ( + opcode.opcode == ZEND_MATCH || + opcode.opcode == ZEND_SWITCH_LONG || + opcode.opcode == ZEND_SWITCH_STRING + ) { + zval *array_value; + HashTable *myht; + zval *val; + + array_value = RT_CONSTANT(&opa->opcodesposition, opcode.op2); + myht = Z_ARRVAL_P(array_value); + + /* All 'case' statements */ + ZEND_HASH_FOREACH_VAL_IND(myht, val) { + if (*jump_count < XDEBUG_BRANCH_MAX_OUTS - 2) { + jumps*jump_count = position + (val->value.lval / sizeof(zend_op)); + (*jump_count)++; + } + } ZEND_HASH_FOREACH_END(); + + /* The 'default' case */ + jumps*jump_count = position + (opcode.extended_value / sizeof(zend_op)); + (*jump_count)++; + + if (opcode.opcode != ZEND_MATCH) { + /* The 'next' opcode */ + jumps*jump_count = position + 1; + (*jump_count)++; + } + + return 1; + } + + return 0; +} + +static void xdebug_analyse_branch(zend_op_array *opa, unsigned int position, xdebug_set *set, xdebug_branch_info *branch_info) +{ + /* fprintf(stderr, "Branch analysis from position: %d\n", position); */ + + if (branch_info) { + xdebug_set_add(branch_info->starts, position); + branch_info->branchesposition.start_lineno = opa->opcodesposition.lineno; + } + + /* First we see if the branch has been visited, if so we bail out. */ + if (xdebug_set_in(set, position)) { + return; + } + + /* fprintf(stderr, "XDEBUG Adding %d\n", position); */ + /* Loop over the opcodes until the end of the array, or until a jump point has been found */ + xdebug_set_add(set, position); + while (position < opa->last) { + size_t jump_count = 0; + int jumpsXDEBUG_BRANCH_MAX_OUTS; + size_t i; + + /* See if we have a jump instruction */ + if (xdebug_find_jumps(opa, position, &jump_count, jumps)) { + for (i = 0; i < jump_count; i++) { + if (jumpsi == XDEBUG_JMP_EXIT || jumpsi != XDEBUG_JMP_NOT_SET) { + if (branch_info) { + xdebug_branch_info_update(branch_info, position, opa->opcodesposition.lineno, i, jumpsi); + } + if (jumpsi != XDEBUG_JMP_EXIT) { + xdebug_analyse_branch(opa, jumpsi, set, branch_info); + } + } + } + break; + } + + /* See if we have a throw instruction */ + if (opa->opcodesposition.opcode == ZEND_THROW) { + /* fprintf(stderr, "Throw found at %d\n", position); */ + if (branch_info) { + xdebug_set_add(branch_info->ends, position); + branch_info->branchesposition.start_lineno = opa->opcodesposition.lineno; + } + break; + } + + /* See if we have an exit instruction */ + if (opa->opcodesposition.opcode == ZEND_EXIT) { + /* fprintf(stderr, "X* Return found\n"); */ + if (branch_info) { + xdebug_set_add(branch_info->ends, position); + branch_info->branchesposition.start_lineno = opa->opcodesposition.lineno; + } + break; + } + /* See if we have a return instruction */ + if ( + opa->opcodesposition.opcode == ZEND_RETURN + || opa->opcodesposition.opcode == ZEND_RETURN_BY_REF + ) { + /*(fprintf(stderr, "XDEBUG Return found\n");)*/ + if (branch_info) { + xdebug_set_add(branch_info->ends, position); + branch_info->branchesposition.start_lineno = opa->opcodesposition.lineno; + } + break; + } + + position++; + /*(fprintf(stderr, "XDEBUG Adding %d\n", position);)*/ + xdebug_set_add(set, position); + } +} + +static void xdebug_analyse_oparray(zend_op_array *opa, xdebug_set *set, xdebug_branch_info *branch_info) +{ + unsigned int position = 0; + + while (position < opa->last) { + if (position == 0) { + xdebug_analyse_branch(opa, position, set, branch_info); + if (branch_info) { + xdebug_set_add(branch_info->entry_points, position); + } + } else if (opa->opcodesposition.opcode == ZEND_CATCH) { + xdebug_analyse_branch(opa, position, set, branch_info); + if (branch_info) { + xdebug_set_add(branch_info->entry_points, position); + } + } + position++; + } + if (branch_info) { + xdebug_set_add(branch_info->ends, opa->last-1); + branch_info->branchesopa->last-1.start_lineno = opa->opcodesopa->last-1.lineno; + } +} + +static void prefill_from_oparray(zend_string *filename, zend_op_array *op_array) +{ + unsigned int i; + xdebug_set *set = NULL; + xdebug_branch_info *branch_info = NULL; + + op_array->reservedXG_COV(dead_code_analysis_tracker_offset) = (void*) XG_COV(dead_code_last_start_id); + + /* Check for abstract methods and simply return from this function in those + * cases. */ + if (op_array->fn_flags & ZEND_ACC_ABSTRACT) { + return; + } + + /* Check whether this function should be filtered out */ + { +/* + function_stack_entry tmp_fse; + tmp_fse.filename = STR_NAME_VAL(op_array->filename); + xdebug_build_fname_from_oparray(&tmp_fse.function, op_array); + printf(" - PREFIL FILTERED FOR %s (%s::%s): %s\n", + tmp_fse.filename, tmp_fse.function.class, tmp_fse.function.function, + op_array->reservedXG_COV(code_coverage_filter_offset) ? "YES" : "NO"); +*/ + if (op_array->reservedXG_COV(code_coverage_filter_offset)) { + return; + } + } + + /* Run dead code analysis if requested */ + if (XG_COV(code_coverage_dead_code_analysis) && (op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO)) { + set = xdebug_set_create(op_array->last); + if (XG_COV(code_coverage_branch_check)) { + branch_info = xdebug_branch_info_create(op_array->last); + } + + xdebug_analyse_oparray(op_array, set, branch_info); + } + + /* The normal loop then finally */ + for (i = 0; i < op_array->last; i++) { + zend_op opcode = op_array->opcodesi; + prefill_from_opcode(filename, opcode, set ? !xdebug_set_in(set, i) : 0); + } + + if (set) { + xdebug_set_free(set); + } + if (branch_info) { + char function_name1024; + xdebug_func func_info; + + xdebug_build_fname_from_oparray(&func_info, op_array); + xdebug_func_format(function_name, sizeof(function_name), &func_info); + + if (func_info.object_class) { + zend_string_release(func_info.object_class); + } + if (func_info.scope_class) { + zend_string_release(func_info.scope_class); + } + if (func_info.function) { + xdfree(func_info.function); + } + + xdebug_branch_post_process(op_array, branch_info); + xdebug_branch_find_paths(branch_info); + xdebug_branch_info_add_branches_and_paths(filename, (char*) function_name, branch_info); + } + +#if PHP_VERSION_ID >= 80100 + if (!op_array->num_dynamic_func_defs) { + return; + } + + for (i = 0; i < op_array->num_dynamic_func_defs; i++) { + prefill_from_oparray(filename, op_array->dynamic_func_defsi); + } +#endif +} + +static int prefill_from_function_table(zend_op_array *opa) +{ + if (opa->type == ZEND_USER_FUNCTION) { + if ((long) opa->reservedXG_COV(dead_code_analysis_tracker_offset) < XG_COV(dead_code_last_start_id)) { + prefill_from_oparray(opa->filename, opa); + } + } + + return ZEND_HASH_APPLY_KEEP; +} + +/* Set correct int format to use */ +#if SIZEOF_ZEND_LONG == 4 +# define XDEBUG_PTR_KEY_LEN 8 +# define XDEBUG_PTR_KEY_FMT "%08X" +#else +# define XDEBUG_PTR_KEY_LEN 16 +# define XDEBUG_PTR_KEY_FMT "%016lX" +#endif + +static int prefill_from_class_table(zend_class_entry *ce) +{ + if (ce->type == ZEND_USER_CLASS) { + zend_op_array *val; + + ZEND_HASH_FOREACH_PTR(&ce->function_table, val) { + prefill_from_function_table(val); + } ZEND_HASH_FOREACH_END(); + } + + return ZEND_HASH_APPLY_KEEP; +} + +static void xdebug_prefill_code_coverage(zend_op_array *op_array) +{ + zend_op_array *function_op_array; + zend_class_entry *class_entry; + + if ((long) op_array->reservedXG_COV(dead_code_analysis_tracker_offset) < XG_COV(dead_code_last_start_id)) { + prefill_from_oparray(op_array->filename, op_array); + } + + ZEND_HASH_REVERSE_FOREACH_PTR(CG(function_table), function_op_array) { + if (_idx == XG_COV(prefill_function_count)) { + break; + } + prefill_from_function_table(function_op_array); + } ZEND_HASH_FOREACH_END(); + XG_COV(prefill_function_count) = CG(function_table)->nNumUsed; + + ZEND_HASH_REVERSE_FOREACH_PTR(CG(class_table), class_entry) { + if (_idx == XG_COV(prefill_class_count)) { + break; + } + prefill_from_class_table(class_entry); + } ZEND_HASH_FOREACH_END(); + XG_COV(prefill_class_count) = CG(class_table)->nNumUsed; +} + +void xdebug_code_coverage_start_of_function(zend_op_array *op_array, char *function_name) +{ + xdebug_path *path = xdebug_path_new(NULL); + int orig_size = XG_COV(branches).size; + + xdebug_prefill_code_coverage(op_array); + xdebug_path_info_add_path_for_level(XG_COV(paths_stack), path, XDEBUG_VECTOR_COUNT(XG_BASE(stack))); + + if (orig_size == 0 || XDEBUG_VECTOR_COUNT(XG_BASE(stack)) >= orig_size) { + size_t i = 0; + + XG_COV(branches).size = XDEBUG_VECTOR_COUNT(XG_BASE(stack)) + 32; + XG_COV(branches).last_branch_nr = realloc(XG_COV(branches).last_branch_nr, sizeof(int) * XG_COV(branches.size)); + for (i = orig_size; i < XG_COV(branches).size; i++) { + XG_COV(branches).last_branch_nri = -1; + } + } + + XG_COV(branches).last_branch_nrXDEBUG_VECTOR_COUNT(XG_BASE(stack)) = -1; +} + +void xdebug_code_coverage_end_of_function(zend_op_array *op_array, zend_string *filename, char *function_name) +{ + xdebug_str str = XDEBUG_STR_INITIALIZER; + xdebug_path *path = xdebug_path_info_get_path_for_level(XG_COV(paths_stack), XDEBUG_VECTOR_COUNT(XG_BASE(stack))); + + if (!path || !path->elements) { + return; + } + + xdebug_create_key_for_path(path, &str); + + xdebug_branch_info_mark_end_of_function_reached(filename, function_name, str.d, str.l); + + xdfree(str.d); + + if (path) { + xdebug_path_free(path); + } +} + +PHP_FUNCTION(xdebug_start_code_coverage) +{ + zend_long options = 0; + + if (!XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { + php_error(E_WARNING, "Code coverage needs to be enabled in php.ini by setting 'xdebug.mode' to 'coverage'"); + RETURN_FALSE; + } + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &options) == FAILURE) { + return; + } + + XG_COV(code_coverage_unused) = (options & XDEBUG_CC_OPTION_UNUSED); + XG_COV(code_coverage_dead_code_analysis) = (options & XDEBUG_CC_OPTION_DEAD_CODE); + XG_COV(code_coverage_branch_check) = (options & XDEBUG_CC_OPTION_BRANCH_CHECK); + + XG_COV(code_coverage_active) = 1; + RETURN_TRUE; +} + +PHP_FUNCTION(xdebug_stop_code_coverage) +{ + zend_bool cleanup = 1; + + if (!XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { + RETURN_FALSE; + } + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &cleanup) == FAILURE) { + return; + } + if (!XG_COV(code_coverage_active)) { + RETURN_FALSE; + } + + if (cleanup) { + if (XG_COV(previous_filename)) { + zend_string_release(XG_COV(previous_filename)); + } + XG_COV(previous_filename) = NULL; + XG_COV(previous_file) = NULL; + if (XG_COV(previous_mark_filename)) { + zend_string_release(XG_COV(previous_mark_filename)); + } + XG_COV(previous_mark_filename) = NULL; + XG_COV(previous_mark_file) = NULL; + xdebug_hash_destroy(XG_COV(code_coverage_info)); + XG_COV(code_coverage_info) = xdebug_hash_alloc(32, xdebug_coverage_file_dtor); + XG_COV(dead_code_last_start_id)++; + xdebug_path_info_dtor(XG_COV(paths_stack)); + XG_COV(paths_stack) = xdebug_path_info_ctor(); + } + + XG_COV(code_coverage_active) = 0; + + RETURN_TRUE; +} + +static int xdebug_lineno_cmp(Bucket *f, Bucket *s) +{ + if (f->h < s->h) { + return -1; + } else if (f->h > s->h) { + return 1; + } else { + return 0; + } +} + + +static void add_line(void *ret, xdebug_hash_element *e) +{ + xdebug_coverage_line *line = (xdebug_coverage_line*) e->ptr; + zval *retval = (zval*) ret; + + if (line->executable && (line->count == 0)) { + add_index_long(retval, line->lineno, -line->executable); + } else { + add_index_long(retval, line->lineno, 1); + } +} + +static void add_branches(zval *retval, xdebug_branch_info *branch_info) +{ + zval *branches, *branch, *out, *out_hit; + unsigned int i; + + XDEBUG_MAKE_STD_ZVAL(branches); + array_init(branches); + + for (i = 0; i < branch_info->starts->size; i++) { + if (xdebug_set_in(branch_info->starts, i)) { + size_t j = 0; + + XDEBUG_MAKE_STD_ZVAL(branch); + array_init(branch); + add_assoc_long(branch, "op_start", i); + add_assoc_long(branch, "op_end", branch_info->branchesi.end_op); + add_assoc_long(branch, "line_start", branch_info->branchesi.start_lineno); + add_assoc_long(branch, "line_end", branch_info->branchesi.end_lineno); + + add_assoc_long(branch, "hit", branch_info->branchesi.hit); + + XDEBUG_MAKE_STD_ZVAL(out); + array_init(out); + for (j = 0; j < branch_info->branchesi.outs_count; j++) { + if (branch_info->branchesi.outsj) { + add_index_long(out, j, branch_info->branchesi.outsj); + } + } + add_assoc_zval(branch, "out", out); + + XDEBUG_MAKE_STD_ZVAL(out_hit); + array_init(out_hit); + for (j = 0; j < branch_info->branchesi.outs_count; j++) { + if (branch_info->branchesi.outsj) { + add_index_long(out_hit, j, branch_info->branchesi.outs_hitj); + } + } + add_assoc_zval(branch, "out_hit", out_hit); + + add_index_zval(branches, i, branch); + efree(out_hit); + efree(out); + efree(branch); + } + } + + add_assoc_zval_ex(retval, "branches", HASH_KEY_SIZEOF("branches"), branches); + + efree(branches); +} + +static void add_paths(zval *retval, xdebug_branch_info *branch_info) +{ + zval *paths, *path, *path_container; + unsigned int i, j; + + XDEBUG_MAKE_STD_ZVAL(paths); + array_init(paths); + + for (i = 0; i < branch_info->path_info.paths_count; i++) { + XDEBUG_MAKE_STD_ZVAL(path); + array_init(path); + + XDEBUG_MAKE_STD_ZVAL(path_container); + array_init(path_container); + + for (j = 0; j < branch_info->path_info.pathsi->elements_count; j++) { + add_next_index_long(path, branch_info->path_info.pathsi->elementsj); + } + + add_assoc_zval(path_container, "path", path); + add_assoc_long(path_container, "hit", branch_info->path_info.pathsi->hit); + + add_next_index_zval(paths, path_container); + + efree(path_container); + efree(path); + } + + add_assoc_zval_ex(retval, "paths", HASH_KEY_SIZEOF("paths"), paths); + + efree(paths); +} + +static void add_cc_function(void *ret, xdebug_hash_element *e) +{ + xdebug_coverage_function *function = (xdebug_coverage_function*) e->ptr; + zval *retval = (zval*) ret; + zval *function_info; + + XDEBUG_MAKE_STD_ZVAL(function_info); + array_init(function_info); + + if (function->branch_info) { + add_branches(function_info, function->branch_info); + add_paths(function_info, function->branch_info); + } + + add_assoc_zval_ex(retval, function->name, HASH_KEY_STRLEN(function->name), function_info); + + efree(function_info); +} + +static void add_file(void *ret, xdebug_hash_element *e) +{ + xdebug_coverage_file *file = (xdebug_coverage_file*) e->ptr; + zval *retval = (zval*) ret; + zval *lines, *functions, *file_info; + HashTable *target_hash; + + /* Add all the lines */ + XDEBUG_MAKE_STD_ZVAL(lines); + array_init(lines); + + xdebug_hash_apply(file->lines, (void *) lines, add_line); + + /* Sort on linenumber */ + target_hash = HASH_OF(lines); + zend_hash_sort(target_hash, xdebug_lineno_cmp, 0); + + /* Add the branch and path info */ + if (XG_COV(code_coverage_branch_check)) { + XDEBUG_MAKE_STD_ZVAL(file_info); + array_init(file_info); + + XDEBUG_MAKE_STD_ZVAL(functions); + array_init(functions); + + xdebug_hash_apply(file->functions, (void *) functions, add_cc_function); + + add_assoc_zval_ex(file_info, "lines", HASH_KEY_SIZEOF("lines"), lines); + add_assoc_zval_ex(file_info, "functions", HASH_KEY_SIZEOF("functions"), functions); + + add_assoc_zval_ex(retval, ZSTR_VAL(file->name), ZSTR_LEN(file->name), file_info); + efree(functions); + efree(file_info); + } else { + add_assoc_zval_ex(retval, ZSTR_VAL(file->name), ZSTR_LEN(file->name), lines); + } + + efree(lines); +} + +PHP_FUNCTION(xdebug_get_code_coverage) +{ + array_init(return_value); + + if (!XG_COV(code_coverage_info)) { + return; + } + + xdebug_hash_apply(XG_COV(code_coverage_info), (void *) return_value, add_file); +} + +PHP_FUNCTION(xdebug_get_function_count) +{ + RETURN_LONG(XG_BASE(function_count)); +} + +PHP_FUNCTION(xdebug_code_coverage_started) +{ + RETURN_BOOL(XG_COV(code_coverage_active)); +} + +void xdebug_init_coverage_globals(xdebug_coverage_globals_t *xg) +{ + xg->previous_filename = NULL; + xg->previous_file = NULL; + xg->previous_mark_filename = NULL; + xg->previous_mark_file = NULL; + xg->paths_stack = NULL; + xg->branches.size = 0; + xg->branches.last_branch_nr = NULL; + xg->code_coverage_active = 0; + + /* Get reserved offset */ + xg->dead_code_analysis_tracker_offset = zend_xdebug_cc_run_offset; + xg->dead_code_last_start_id = 1; + xg->code_coverage_filter_offset = zend_xdebug_filter_offset; +} + +void xdebug_coverage_count_line_if_active(zend_op_array *op_array, zend_string *file, int lineno) +{ + if (XG_COV(code_coverage_active) && !op_array->reservedXG_COV(code_coverage_filter_offset)) { + xdebug_count_line(file, lineno, 0, 0); + } +} + +void xdebug_coverage_count_line_if_branch_check_active(zend_op_array *op_array, zend_string *file, int lineno) +{ + if (XG_COV(code_coverage_active) && XG_COV(code_coverage_branch_check)) { + xdebug_coverage_count_line_if_active(op_array, file, lineno); + } +} + +void xdebug_coverage_record_if_active(zend_execute_data *execute_data, zend_op_array *op_array) +{ + if (!op_array->reservedXG_COV(code_coverage_filter_offset) && XG_COV(code_coverage_active)) { + xdebug_print_opcode_info(execute_data, execute_data->opline); + } +} + +void xdebug_coverage_compile_file(zend_op_array *op_array) +{ + if (XG_COV(code_coverage_active) && XG_COV(code_coverage_unused) && (op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO)) { + xdebug_prefill_code_coverage(op_array); + } +} + +int xdebug_coverage_execute_ex(function_stack_entry *fse, zend_op_array *op_array, zend_string **tmp_filename, char **tmp_function_name) +{ + xdebug_func func_info; + + if (!fse->filtered_code_coverage && XG_COV(code_coverage_active) && XG_COV(code_coverage_unused)) { + char buffer1024; + + *tmp_filename = zend_string_copy(op_array->filename); + xdebug_build_fname_from_oparray(&func_info, op_array); + xdebug_func_format(buffer, sizeof(buffer), &func_info); + *tmp_function_name = xdstrdup(buffer); + xdebug_code_coverage_start_of_function(op_array, *tmp_function_name); + + if (func_info.object_class) { + zend_string_release(func_info.object_class); + } + if (func_info.scope_class) { + zend_string_release(func_info.scope_class); + } + if (func_info.function) { + xdfree(func_info.function); + } + return 1; + } + + return 0; +} + +void xdebug_coverage_execute_ex_end(function_stack_entry *fse, zend_op_array *op_array, zend_string *tmp_filename, char *tmp_function_name) +{ + /* Check which path has been used */ + if (!fse->filtered_code_coverage && XG_COV(code_coverage_active) && XG_COV(code_coverage_unused)) { + xdebug_code_coverage_end_of_function(op_array, tmp_filename, tmp_function_name); + } + xdfree(tmp_function_name); + zend_string_release(tmp_filename); +} + +void xdebug_coverage_init_oparray(zend_op_array *op_array) +{ + function_stack_entry tmp_fse; + + if (XG_BASE(filter_type_code_coverage) == XDEBUG_FILTER_NONE) { + op_array->reservedXG_COV(dead_code_analysis_tracker_offset) = 0; + return; + } + + tmp_fse.filename = op_array->filename; + xdebug_build_fname_from_oparray(&tmp_fse.function, op_array); + xdebug_filter_run_internal(&tmp_fse, XDEBUG_FILTER_CODE_COVERAGE, &tmp_fse.filtered_code_coverage, XG_BASE(filter_type_code_coverage), XG_BASE(filters_code_coverage)); + xdebug_func_dtor_by_ref(&tmp_fse.function); + + op_array->reservedXG_COV(code_coverage_filter_offset) = (void*) (size_t) tmp_fse.filtered_code_coverage; +} + +static int xdebug_switch_handler(XDEBUG_OPCODE_HANDLER_ARGS) +{ + const zend_op *cur_opcode = execute_data->opline; + + if (!XG_COV(code_coverage_active)) { + return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); + } + + execute_data->opline++; + return ZEND_USER_OPCODE_CONTINUE; +} + + +void xdebug_coverage_minit(INIT_FUNC_ARGS) +{ + int i; + + /* Get reserved offsets */ + zend_xdebug_cc_run_offset = zend_get_resource_handle(XDEBUG_NAME); + zend_xdebug_filter_offset = zend_get_resource_handle(XDEBUG_NAME); + + xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN, xdebug_common_override_handler); + xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_DIM, xdebug_common_override_handler); + xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_OBJ, xdebug_common_override_handler); + xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_STATIC_PROP, xdebug_common_override_handler); + xdebug_register_with_opcode_multi_handler(ZEND_QM_ASSIGN, xdebug_common_override_handler); + xdebug_register_with_opcode_multi_handler(ZEND_INCLUDE_OR_EVAL, xdebug_coverage_include_or_eval_handler); + + /* Overload opcodes for code coverage */ + xdebug_set_opcode_handler(ZEND_JMP, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_JMPZ, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_JMPZ_EX, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_JMPNZ, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_IS_IDENTICAL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_IS_NOT_IDENTICAL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_IS_EQUAL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_IS_NOT_EQUAL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_IS_SMALLER, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_IS_SMALLER_OR_EQUAL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_BOOL_NOT, xdebug_common_override_handler); + + xdebug_set_opcode_handler(ZEND_ADD, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_SUB, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_MUL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_DIV, xdebug_common_override_handler); + + xdebug_set_opcode_handler(ZEND_ADD_ARRAY_ELEMENT, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_RETURN, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_RETURN_BY_REF, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_EXT_STMT, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_SEND_VAR, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_SEND_VAR_NO_REF, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_SEND_VAR_NO_REF_EX, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_SEND_REF, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_SEND_VAL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_SEND_VAL_EX, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_SEND_VAR_EX, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_NEW, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_EXT_FCALL_BEGIN, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_INIT_METHOD_CALL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_INIT_STATIC_METHOD_CALL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_INIT_FCALL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_INIT_NS_FCALL_BY_NAME, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_CATCH, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_BOOL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_INIT_ARRAY, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_DIM_R, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_DIM_W, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_OBJ_R, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_OBJ_W, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_OBJ_FUNC_ARG, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_DIM_FUNC_ARG, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_STATIC_PROP_FUNC_ARG, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_DIM_UNSET, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_OBJ_UNSET, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_CLASS, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_CONSTANT, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FETCH_CLASS_CONSTANT, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_CONCAT, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FAST_CONCAT, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_ISSET_ISEMPTY_DIM_OBJ, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_ISSET_ISEMPTY_PROP_OBJ, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_CASE, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_DECLARE_LAMBDA_FUNCTION, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_INSTANCEOF, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_FAST_RET, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_ROPE_ADD, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_ROPE_END, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_COALESCE, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_TYPE_CHECK, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_GENERATOR_CREATE, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_BIND_STATIC, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_BIND_LEXICAL, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_DECLARE_CLASS, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_DECLARE_CLASS_DELAYED, xdebug_common_override_handler); + xdebug_set_opcode_handler(ZEND_SWITCH_STRING, xdebug_switch_handler); + xdebug_set_opcode_handler(ZEND_SWITCH_LONG, xdebug_switch_handler); + + /* Override all the other opcodes so that we can mark when we hit a branch + * start one */ + for (i = 0; i < 256; i++) { + if (i == ZEND_HANDLE_EXCEPTION) { + continue; + } + if (!xdebug_isset_opcode_handler(i)) { + xdebug_set_opcode_handler(i, xdebug_check_branch_entry_handler); + } + } +} + +void xdebug_coverage_register_constants(INIT_FUNC_ARGS) +{ + REGISTER_LONG_CONSTANT("XDEBUG_CC_UNUSED", XDEBUG_CC_OPTION_UNUSED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XDEBUG_CC_DEAD_CODE", XDEBUG_CC_OPTION_DEAD_CODE, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XDEBUG_CC_BRANCH_CHECK", XDEBUG_CC_OPTION_BRANCH_CHECK, CONST_CS | CONST_PERSISTENT); +} + +void xdebug_coverage_rinit(void) +{ + XG_COV(code_coverage_active) = 0; + XG_COV(code_coverage_info) = xdebug_hash_alloc(32, xdebug_coverage_file_dtor); + XG_COV(dead_code_analysis_tracker_offset) = zend_xdebug_cc_run_offset; + XG_COV(dead_code_last_start_id) = 1; + XG_COV(code_coverage_filter_offset) = zend_xdebug_filter_offset; + XG_COV(previous_filename) = NULL; + XG_COV(previous_file) = NULL; + XG_COV(prefill_function_count) = 0; + XG_COV(prefill_class_count) = 0; + + /* Initialize visited classes and branches hash */ + XG_COV(visited_branches) = xdebug_hash_alloc(2048, NULL); + + XG_COV(paths_stack) = xdebug_path_info_ctor(); + XG_COV(branches).size = 0; + XG_COV(branches).last_branch_nr = NULL; +} + +void xdebug_coverage_post_deactivate(void) +{ + XG_COV(code_coverage_active) = 0; + + xdebug_hash_destroy(XG_COV(code_coverage_info)); + XG_COV(code_coverage_info) = NULL; + + xdebug_hash_destroy(XG_COV(visited_branches)); + XG_COV(visited_branches) = NULL; + + /* Clean up path coverage array */ + if (XG_COV(paths_stack)) { + xdebug_path_info_dtor(XG_COV(paths_stack)); + XG_COV(paths_stack) = NULL; + } + if (XG_COV(branches).last_branch_nr) { + free(XG_COV(branches).last_branch_nr); + XG_COV(branches).last_branch_nr = NULL; + XG_COV(branches).size = 0; + } + + if (XG_COV(previous_filename)) { + zend_string_release(XG_COV(previous_filename)); + XG_COV(previous_filename) = NULL; + } + if (XG_COV(previous_mark_filename)) { + zend_string_release(XG_COV(previous_mark_filename)); + XG_COV(previous_mark_filename) = NULL; + } +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/coverage/code_coverage.h
Changed
(renamed from xdebug-3.1.5/src/coverage/code_coverage.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/coverage/code_coverage_private.h
Added
@@ -0,0 +1,58 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __XDEBUG_CODE_COVERAGE_PRIVATE_H__ +#define __XDEBUG_CODE_COVERAGE_PRIVATE_H__ + +#include "lib/php-header.h" + +#include "branch_info.h" +#include "code_coverage.h" + +#include "lib/compat.h" +#include "lib/hash.h" +#include "lib/mm.h" + +typedef struct xdebug_coverage_line { + int lineno; + int count; + int executable; +} xdebug_coverage_line; + +typedef struct xdebug_coverage_function { + char *name; + xdebug_branch_info *branch_info; +} xdebug_coverage_function; + +#define XG_COV(v) (XG(globals.coverage.v)) +#define XINI_COV(v) (XG(settings.coverage.v)) + +xdebug_coverage_file *xdebug_coverage_file_ctor(zend_string *filename); + +xdebug_coverage_function *xdebug_coverage_function_ctor(char *function_name); +void xdebug_coverage_function_dtor(void *data); +void xdebug_code_coverage_start_of_function(zend_op_array *op_array, char *function_name); +void xdebug_code_coverage_end_of_function(zend_op_array *op_array, zend_string *file_name, char *function_name); + +PHP_FUNCTION(xdebug_start_code_coverage); +PHP_FUNCTION(xdebug_stop_code_coverage); +PHP_FUNCTION(xdebug_get_code_coverage); +PHP_FUNCTION(xdebug_code_coverage_started); + +PHP_FUNCTION(xdebug_get_function_count); + +#endif +
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/debugger/com.c
Added
@@ -0,0 +1,768 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#include "php_xdebug.h" +#include <string.h> +#include <sys/types.h> +#include <errno.h> +#include <stdio.h> +#include <fcntl.h> +#ifndef PHP_WIN32 +# if HAVE_POLL_H +# include <poll.h> +# elif HAVE_SYS_POLL_H +# include <sys/poll.h> +# endif +# include <unistd.h> +# include <sys/socket.h> +# include <sys/un.h> +# include <netinet/tcp.h> +# if HAVE_NETINET_IN_H +# include <netinet/in.h> +# endif +# include <netdb.h> +#else +# include <process.h> +# include <direct.h> +# include "win32/time.h" +# undef UNICODE +# include <winsock2.h> +# include <ws2tcpip.h> +# include <mstcpip.h> +# pragma comment (lib, "Ws2_32.lib") +# define PATH_MAX MAX_PATH +# define poll WSAPoll +#endif + +#include "com.h" + +#include "debugger_private.h" +#include "handler_dbgp.h" +#include "ip_info.h" +#include "lib/crc32.h" +#include "lib/log.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +#if !WIN32 && !WINNT +static int xdebug_create_socket_unix(const char *path) +{ + struct sockaddr_un sa; + int sockfd; + + if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == SOCK_ERR) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "UNIX", "Creating socket for 'unix://%s', socket: %s.", path, strerror(errno)); + return SOCK_ERR; + } + + sa.sun_family = AF_UNIX; + strncpy(sa.sun_path, path, sizeof(sa.sun_path) - 1); + if (connect(sockfd, (struct sockaddr*)&sa, sizeof(sa)) < 0) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "UNIX", "Creating socket for 'unix://%s', connect: %s.", path, strerror(errno)); + SCLOSE(sockfd); + return (errno == EACCES) ? SOCK_ACCESS_ERR : SOCK_ERR; + } + + /* Prevent the socket from being inherited by exec'd children */ + if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) < 0) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "UNIX", "Creating socket for 'unix://%s', fcntl(FD_CLOEXEC): %s.", path, strerror(errno)); + } + + return sockfd; +} +#endif + +#if !WIN32 && !WINNT + +/* For OSX and FreeBSD */ +# if !defined(SOL_TCP) && defined(IPPROTO_TCP) +# define SOL_TCP IPPROTO_TCP +# endif +# if !defined(TCP_KEEPIDLE) && defined(TCP_KEEPALIVE) +# define TCP_KEEPIDLE TCP_KEEPALIVE +# endif + +void set_keepalive_options(int fd) +{ + int optval = 1; + int optlen = sizeof(optval); + int ret; + + ret = setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen); + if (ret) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "KEEPALIVE", "Could not set SO_KEEPALIVE: %s.", strerror(errno)); + return; + } + +# if defined(TCP_KEEPIDLE) + optval = 600; + ret = setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &optval, optlen); + if (ret) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "KEEPALIVE", "Could not set TCP_KEEPIDLE to %d: %s.", optval, strerror(errno)); + return; + } +# endif + +# if defined(TCP_KEEPCNT) + optval = 20; + ret = setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &optval, optlen); + if (ret) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "KEEPALIVE", "Could not set TCP_KEEPCNT to %d: %s.", optval, strerror(errno)); + return; + } +# endif + +# if defined(TCP_KEEPINTVL) + optval = 60; + ret = setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &optval, optlen); + if (ret) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "KEEPALIVE", "Could not set TCP_KEEPINTVL to %d: %s.", optval, strerror(errno)); + return; + } +# endif +} +#endif // !WIN32 && !WINNT + +static char* resolve_pseudo_hosts(const char *requested_hostname) +{ +#if __linux__ + /* Does it start with 'xdebug://' ? */ + if (strncmp(requested_hostname, "xdebug://", strlen("xdebug://")) != 0) { + return NULL; + } + + /* Check for 'gateway' pseudo host */ + if (strcmp(requested_hostname, "xdebug://gateway") == 0) { +#if XDEBUG_GATEWAY_SUPPORT + char *gateway = xdebug_get_gateway_ip(); + + if (!gateway) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "GATEWAY", "Could not find network gateway to use for 'gateway' pseudo-host."); + return NULL; + } + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Found 'gateway' pseudo-host, with IP address '%s'.", gateway); + return gateway; +#else + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "PSEUDO-GW-NO-SUPPORT", "Pseudo-host: '%s' is not supported on this host.", requested_hostname + strlen("xdebug://")); + return NULL; +# endif + } + + /* Check for 'nameserver' pseudo host */ + if (strcmp(requested_hostname, "xdebug://nameserver") == 0) { +#if XDEBUG_NAMESERVER_SUPPORT + char *gateway = xdebug_get_private_nameserver(); + + if (!gateway) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "NAMESERVER", "Could not find a private network nameserver for 'nameserver' pseudo-host."); + return NULL; + } + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Found 'nameserver' pseudo-host, with IP address '%s'.", gateway); + return gateway; +# else + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "PSEUDO-NS-NO-SUPPORT", "Pseudo-host: '%s' is not supported on this host.", requested_hostname + strlen("xdebug://")); + return NULL; +# endif + } + + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "PSEUDO-UNKNOWN", "Unknown pseudo-host: '%s', only 'gateway' or 'nameserver' are supported.", requested_hostname + strlen("xdebug://")); +#endif + + return NULL; +} + +static int xdebug_create_socket(const char *hostname, int dport, int timeout) +{ + struct addrinfo hints; + struct addrinfo *remote; + struct addrinfo *ptr; + int status; + int sockfd = 0; + int sockerror; + char sport10; + int actually_connected; + struct sockaddr_in6 sa; + socklen_t size = sizeof(sa); +#if WIN32|WINNT + WSAPOLLFD ufds1 = {0}; + WORD wVersionRequested; + WSADATA wsaData; + char optval = 1; + u_long yes = 1; + u_long no = 0; + + wVersionRequested = MAKEWORD(2, 2); + WSAStartup(wVersionRequested, &wsaData); +#else + struct pollfd ufds1; + long optval = 1; +#endif + + if (!strncmp(hostname, "unix://", strlen("unix://"))) { +#if WIN32|WINNT + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "UNIX-WIN", "Creating Unix domain socket ('%s') on Windows is not supported.", hostname); + return SOCK_ERR; +#else + return xdebug_create_socket_unix(hostname + strlen("unix://")); +#endif + } + + /* Make a string of the port number that can be used with getaddrinfo */ + sprintf(sport, "%d", dport); + + /* Create hints for getaddrinfo saying that we want IPv4 and IPv6 TCP stream sockets */ + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + hints.ai_protocol = IPPROTO_TCP; + hints.ai_flags = AI_PASSIVE; + + /* Call getaddrinfo and return SOCK_ERR if the call fails for some reason */ + if ((status = getaddrinfo(hostname, sport, &hints, &remote)) != 0) { +#if WIN32|WINNT + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK1", "Creating socket for '%s:%d', getaddrinfo: %d.", hostname, dport, WSAGetLastError()); +#else + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK1", "Creating socket for '%s:%d', getaddrinfo: %s.", hostname, dport, strerror(errno)); +#endif + return SOCK_ERR; + } + + /* Go through every returned IP address */ + for (ptr = remote; ptr != NULL; ptr = ptr->ai_next) { + /* Try to create the socket. If the creation fails continue on with the + * next IP address in the list */ + if ((sockfd = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol)) == SOCK_ERR) { +#if WIN32|WINNT + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK2", "Creating socket for '%s:%d', socket: %d.", hostname, dport, WSAGetLastError()); +#else + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK2", "Creating socket for '%s:%d', socket: %s.", hostname, dport, strerror(errno)); +#endif + continue; + } + + /* Put socket in non-blocking mode so we can use poll for timeouts */ +#ifdef WIN32 + status = ioctlsocket(sockfd, FIONBIO, &yes); + if (SOCKET_ERROR == status) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK2", "Creating socket for '%s:%d', FIONBIO: %d.", hostname, dport, WSAGetLastError()); + } +#else + fcntl(sockfd, F_SETFL, O_NONBLOCK); +#endif + +#if !WIN32 && !WINNT + /* Prevent the socket from being inherited by exec'd children on *nix (not necessary on Win) */ + if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) < 0) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK2", "Creating socket for '%s:%d', fcntl(FD_CLOEXEC): %s.", hostname, dport, strerror(errno)); + } +#endif + + /* Try to connect to the newly created socket */ + /* Worth noting is that the port is set in the getaddrinfo call before */ + status = connect(sockfd, ptr->ai_addr, ptr->ai_addrlen); + + /* Determine if we got a connection. If no connection could be made + * we close the socket and continue with the next IP address in the list */ + if (status < 0) { +#ifdef WIN32 + errno = WSAGetLastError(); + if (errno != WSAEINPROGRESS && errno != WSAEWOULDBLOCK) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK3", "Creating socket for '%s:%d', connect: %d.", hostname, dport, errno); +#else + if (errno == EACCES) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK3", "Creating socket for '%s:%d', connect: %s.", hostname, dport, strerror(errno)); + SCLOSE(sockfd); + sockfd = SOCK_ACCESS_ERR; + + continue; + } + if (errno != EINPROGRESS) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK3", "Creating socket for '%s:%d', connect: %s.", hostname, dport, strerror(errno)); +#endif + SCLOSE(sockfd); + sockfd = SOCK_ERR; + + continue; + } + + ufds0.fd = sockfd; +#if WIN32|WINNT + ufds0.events = POLLIN | POLLOUT; +#else + ufds0.events = POLLIN | POLLOUT | POLLPRI; +#endif + while (1) { + sockerror = poll(ufds, 1, timeout); + +#if WIN32|WINNT + errno = WSAGetLastError(); + if (errno == WSAEINPROGRESS || errno == WSAEWOULDBLOCK) { + /* XXX introduce retry count? */ + continue; + } +#endif + /* If an error occured when doing the poll */ + if (sockerror == SOCK_ERR) { +#if WIN32|WINNT + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', WSAPoll error: %d (%d, %d).", hostname, dport, WSAGetLastError(), sockerror, errno); +#else + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', poll error: %s (%d).", hostname, dport, strerror(errno), sockerror); +#endif + sockerror = SOCK_ERR; + break; + } + + /* A timeout occured when polling the socket */ + if (sockerror == 0) { + sockerror = SOCK_TIMEOUT_ERR; + break; + } + + /* If the poll was successful but an error occured */ + if (ufds0.revents & (POLLERR | POLLHUP | POLLNVAL)) { +#if WIN32|WINNT + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', WSAPoll success, but error: %d (%d).", hostname, dport, WSAGetLastError(), ufds0.revents); +#else + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', poll success, but error: %s (%d).", hostname, dport, strerror(errno), ufds0.revents); +#endif + sockerror = SOCK_ERR; + break; + } + + /* If the poll was successful break out */ + if (ufds0.revents & (POLLIN | POLLOUT)) { + sockerror = sockfd; + break; + } else { + /* We should never get here, but added as a failsafe to break out from any loops */ +#if WIN32|WINNT + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', WSAPoll: %d.", hostname, dport, WSAGetLastError()); +#else + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK4", "Creating socket for '%s:%d', poll: %s.", hostname, dport, strerror(errno)); +#endif + sockerror = SOCK_ERR; + break; + } + } + + if (sockerror > 0) { + actually_connected = getpeername(sockfd, (struct sockaddr *)&sa, &size); + if (actually_connected == -1) { +#if WIN32|WINNT + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK5", "Creating socket for '%s:%d', getpeername: %d.", hostname, dport, WSAGetLastError()); +#else + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK5", "Creating socket for '%s:%d', getpeername: %s.", hostname, dport, strerror(errno)); +#endif + sockerror = SOCK_ERR; + } + } + + /* If there where some errors close the socket and continue with the next IP address */ + if (sockerror < 0) { + SCLOSE(sockfd); + sockfd = sockerror; + + continue; + } + } + + break; + } + + /* Free the result returned by getaddrinfo, as well as the duplicated hostname */ + freeaddrinfo(remote); + + /* If we got a socket, set the option "No delay" to true (1) */ + if (sockfd > 0) { +#ifdef WIN32 + status = ioctlsocket(sockfd, FIONBIO, &no); + if (SOCKET_ERROR == status) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SOCK6", "Creating socket for '%s:%d', FIONBIO: %d.", hostname, dport, WSAGetLastError()); + } +#else + fcntl(sockfd, F_SETFL, 0); +#endif + + setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, &optval, sizeof(optval)); +#if !WIN32 && !WINNT + set_keepalive_options(sockfd); +#endif + + /* Now we have a socket, update the last seen hostname and port */ + if (XG_DBG(context).connected_hostname) { + xdfree(XG_DBG(context).connected_hostname); + } + XG_DBG(context).connected_hostname = xdstrdup(hostname); + XG_DBG(context).connected_port = dport; + } + + return sockfd; +} + +void xdebug_close_socket(int socketfd) +{ + SCLOSE(socketfd); +} + +static zval *get_client_discovery_address(char **header) +{ + xdebug_arg *headers; + int i; + zval *remote_addr = NULL; + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Checking for client discovery headers: '%s'.", XINI_DBG(client_discovery_header)); + + headers = xdebug_arg_ctor(); + xdebug_explode(",", XINI_DBG(client_discovery_header), headers, -1); + + for (i = 0; i < headers->c; ++i) { + char *header_name = xdebug_trim(headers->argsi); + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Checking header '%s'.", header_name); + remote_addr = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_SERVER), header_name, HASH_KEY_STRLEN(header_name)); + + if (remote_addr) { + *header = header_name; + xdebug_arg_dtor(headers); + return remote_addr; + } + + xdfree(header_name); + } + + return NULL; +} + +/* Starting the debugger */ +static void xdebug_init_normal_debugger(xdebug_str *connection_attempts) +{ + zval *remote_addr = NULL; + char *cp = NULL; + int cp_found = 0; + char *header = NULL; + + if (!XINI_DBG(discover_client_host)) { + char *pseudo_hostname = resolve_pseudo_hosts(XINI_DBG(client_host)); + + if (pseudo_hostname) { + xdebug_str_add_fmt(connection_attempts, "%s:%ld (through xdebug.client_host/xdebug.client_port, from %s)", pseudo_hostname, XINI_DBG(client_port), XINI_DBG(client_host)); + xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Connecting to resolved address/port: %s:%ld.", pseudo_hostname, (long int) XINI_DBG(client_port)); + + XG_DBG(context).socket = xdebug_create_socket(pseudo_hostname, XINI_DBG(client_port), XINI_DBG(connect_timeout_ms)); + xdfree(pseudo_hostname); + return; + } + + xdebug_str_add_fmt(connection_attempts, "%s:%ld (through xdebug.client_host/xdebug.client_port)", XINI_DBG(client_host), XINI_DBG(client_port)); + xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Connecting to configured address/port: %s:%ld.", XINI_DBG(client_host), (long int) XINI_DBG(client_port)); + + XG_DBG(context).socket = xdebug_create_socket(XINI_DBG(client_host), XINI_DBG(client_port), XINI_DBG(connect_timeout_ms)); + return; + } + + /* Discover client host section */ + remote_addr = get_client_discovery_address(&header); + + if (remote_addr && strstr(Z_STRVAL_P(remote_addr), "://")) { + header = NULL; + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "INVADDR", "Invalid remote address provided containing URI spec '%s'.", Z_STRVAL_P(remote_addr)); + + remote_addr = NULL; + } + + if (!remote_addr) { + xdebug_str_add_fmt(connection_attempts, "%s:%ld (fallback through xdebug.client_host/xdebug.client_port)", XINI_DBG(client_host), XINI_DBG(client_port)); + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "HDR", "Could not discover client host through HTTP headers, connecting to configured address/port: %s:%ld.", XINI_DBG(client_host), (long int) XINI_DBG(client_port)); + + XG_DBG(context).socket = xdebug_create_socket(XINI_DBG(client_host), XINI_DBG(client_port), XINI_DBG(connect_timeout_ms)); + return; + } + + /* Use first IP according to RFC 7239 */ + cp = strchr(Z_STRVAL_P(remote_addr), ','); + if (cp) { + *cp = '\0'; + cp_found = 1; + } + + xdebug_str_add_fmt(connection_attempts, "%s:%ld (from %s HTTP header)", Z_STRVAL_P(remote_addr), XINI_DBG(client_port), header); + xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Client host discovered through HTTP header, connecting to %s:%ld.", Z_STRVAL_P(remote_addr), (long int) XINI_DBG(client_port)); + xdfree(header); + + XG_DBG(context).socket = xdebug_create_socket(Z_STRVAL_P(remote_addr), XINI_DBG(client_port), XINI_DBG(connect_timeout_ms)); + + if (XG_DBG(context).socket < 0) { + xdebug_str_add_fmt(connection_attempts, ", %s:%ld (fallback through xdebug.client_host/xdebug.client_port)", XINI_DBG(client_host), XINI_DBG(client_port)); + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "CON", "Could not connect to client host discovered through HTTP headers, connecting to configured address/port: %s:%ld.", XINI_DBG(client_host), (long int) XINI_DBG(client_port)); + + XG_DBG(context).socket = xdebug_create_socket(XINI_DBG(client_host), XINI_DBG(client_port), XINI_DBG(connect_timeout_ms)); + } + + /* Replace the ',', in case we had changed the original header due + * to multiple values */ + if (cp_found) { + *cp = ','; + } +} + +static void xdebug_init_cloud_debugger(const char *cloud_id) +{ + unsigned long crc = xdebug_crc32(cloud_id, strlen(cloud_id)); + char *host; + + host = xdebug_sprintf("%c.cloud.xdebug.com", (crc & 0x0f) + 'a'); + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Connecting to configured address/port: %s:%ld.", host, 9020L); + XG_DBG(context).socket = xdebug_create_socket(host, 9020, XINI_DBG(connect_timeout_ms)); + + xdfree(host); +} + +/** + * dXXXXXXa-cXXa-4XX7-9XX3-fXXXXXXXXXX0 + */ +static int ide_key_is_cloud_id() +{ + const char *k = XG_DBG(ide_key); + + if (strlen(k) != 36) { + return 0; + } + + if (k8 != '-' || k13 != '-' || k18 != '-' || k23 != '-') { + return 0; + } + + return 1; +} + +static void xdebug_init_debugger() +{ + xdebug_str *connection_attempts = xdebug_str_new(); + + /* Get handler from mode */ + XG_DBG(context).handler = &xdebug_handler_dbgp; + + if (strcmp(XINI_DBG(cloud_id), "") != 0) { + xdebug_init_cloud_debugger(XINI_DBG(cloud_id)); + XG_DBG(context).host_type = XDEBUG_CLOUD; + } else if (XG_DBG(ide_key) && ide_key_is_cloud_id()) { + xdebug_init_cloud_debugger(XG_DBG(ide_key)); + XG_DBG(context).host_type = XDEBUG_CLOUD_FROM_TRIGGER_VALUE; + } else { + xdebug_init_normal_debugger(connection_attempts); + XG_DBG(context).host_type = XDEBUG_NORMAL; + } + + /* Check whether we're connected, or why not */ + if (XG_DBG(context).socket >= 0) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_INFO, "Connected to debugging client: %s.", connection_attempts->d); + xdebug_mark_debug_connection_pending(); + + if (!XG_DBG(context).handler->remote_init(&(XG_DBG(context)), XDEBUG_REQ)) { + /* The request could not be started, ignore it then */ + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_ERR, "SES-INIT", "The debug session could not be started. Tried: %s.", connection_attempts->d); + } else { + /* All is well, turn off script time outs */ + zend_unset_timeout(); + EG(timeout_seconds) = 0; + zend_set_timeout(EG(timeout_seconds), 0); + } + } else if (XG_DBG(context).socket == -1) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_ERR, "NOCON", "Could not connect to debugging client. Tried: %s.", connection_attempts->d); + } else if (XG_DBG(context).socket == -2) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_ERR, "TIMEOUT", "Time-out connecting to debugging client, waited: " ZEND_LONG_FMT " ms. Tried: %s.", XINI_DBG(connect_timeout_ms), connection_attempts->d); + } else if (XG_DBG(context).socket == -3) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_ERR, "NOPERM", "No permission connecting to debugging client (%s). This could be SELinux related.", connection_attempts->d); + } + + xdebug_str_free(connection_attempts); +} + +void xdebug_abort_debugger() +{ + if (XG_DBG(remote_connection_enabled)) { + xdebug_mark_debug_connection_not_active(); + } +} + +void xdebug_restart_debugger() +{ + xdebug_abort_debugger(); + xdebug_init_debugger(); +} + +/* Remote connection activation and house keeping */ +int xdebug_is_debug_connection_active() +{ + return XG_DBG(remote_connection_enabled); +} + +void xdebug_mark_debug_connection_active() +{ + XG_DBG(remote_connection_enabled) = 1; + XG_DBG(remote_connection_pid) = xdebug_get_pid(); +} + +void xdebug_mark_debug_connection_pending() +{ + XG_DBG(remote_connection_enabled) = 0; + XG_DBG(remote_connection_pid) = 0; +} + +void xdebug_mark_debug_connection_not_active() +{ + if (XG_DBG(remote_connection_enabled)) { + xdebug_close_socket(XG_DBG(context).socket); + } + + XG_DBG(remote_connection_enabled) = 0; + XG_DBG(remote_connection_pid) = 0; +} + +void xdebug_debug_init_if_requested_on_error() +{ + RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); + + if (!xdebug_lib_start_upon_error()) { + return; + } + + if (!xdebug_is_debug_connection_active()) { + xdebug_init_debugger(); + } +} + +void xdebug_debug_init_if_requested_on_xdebug_break() +{ + RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); + + if (xdebug_is_debug_connection_active()) { + return; + } + + if (xdebug_lib_start_if_mode_is_trigger(XDEBUG_MODE_STEP_DEBUG)) { + xdebug_init_debugger(); + } +} + +static void xdebug_update_ide_key(char *new_key) +{ + if (XG_DBG(ide_key)) { + xdfree(XG_DBG(ide_key)); + } + XG_DBG(ide_key) = xdstrdup(new_key); +} + +static int xdebug_handle_start_session() +{ + int activate_session = 0; + zval *dummy; + char *dummy_env; + + /* Set session cookie if requested */ + if ( + (( + (dummy = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_ENV), "XDEBUG_SESSION_START", sizeof("XDEBUG_SESSION_START") - 1)) != NULL + ) || ( + (dummy = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_GET), "XDEBUG_SESSION_START", sizeof("XDEBUG_SESSION_START") - 1)) != NULL + ) || ( + (dummy = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_POST), "XDEBUG_SESSION_START", sizeof("XDEBUG_SESSION_START") - 1)) != NULL + )) + && !SG(headers_sent) + ) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "Found 'XDEBUG_SESSION_START' HTTP variable, with value '%s'", Z_STRVAL_P(dummy)); + + convert_to_string_ex(dummy); + xdebug_update_ide_key(Z_STRVAL_P(dummy)); + + xdebug_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION") - 1, Z_STRVAL_P(dummy), Z_STRLEN_P(dummy), 0, "/", 1, NULL, 0, 0, 1, 0); + activate_session = 1; + } else if ( + (dummy_env = getenv("XDEBUG_SESSION_START")) != NULL + ) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "Found 'XDEBUG_SESSION_START' ENV variable, with value '%s'", dummy_env); + + xdebug_update_ide_key(dummy_env); + + if (!SG(headers_sent)) { + xdebug_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION") - 1, XG_DBG(ide_key), strlen(XG_DBG(ide_key)), 0, "/", 1, NULL, 0, 0, 1, 0); + } + + activate_session = 1; + } else if (getenv("XDEBUG_CONFIG")) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "Found 'XDEBUG_CONFIG' ENV variable"); + + if (XG_DBG(ide_key) && *XG_DBG(ide_key) && !SG(headers_sent)) { + xdebug_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION") - 1, XG_DBG(ide_key), strlen(XG_DBG(ide_key)), 0, "/", 1, NULL, 0, 0, 1, 0); + activate_session = 1; + } + } + + /* Make sure that if we have a trigger value configured, we don't start the session unless it matches */ + if (activate_session && xdebug_lib_has_shared_secret()) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_INFO, "TRGSEC-LEGACY", "Not activating through legacy method because xdebug.trigger_value is set"); + activate_session = 0; + } + + return activate_session; +} + +static void xdebug_handle_stop_session() +{ + /* Remove session cookie if requested */ + if ( + (( + zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_GET), "XDEBUG_SESSION_STOP", sizeof("XDEBUG_SESSION_STOP") - 1) != NULL + ) || ( + zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_POST), "XDEBUG_SESSION_STOP", sizeof("XDEBUG_SESSION_STOP") - 1) != NULL + )) + && !SG(headers_sent) + ) { + xdebug_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION") - 1, (char*) "", 0, 0, "/", 1, NULL, 0, 0, 1, 0); + } +} + +void xdebug_debug_init_if_requested_at_startup(void) +{ + char *found_trigger_value = NULL; + + if (XG_DBG(detached)) { + return; + } + + if (xdebug_is_debug_connection_active()) { + return; + } + + if ( + xdebug_lib_start_with_request(XDEBUG_MODE_STEP_DEBUG) || + (!xdebug_lib_never_start_with_request() && xdebug_handle_start_session()) || + xdebug_lib_start_with_trigger(XDEBUG_MODE_STEP_DEBUG, &found_trigger_value) + ) { + if (found_trigger_value) { + xdebug_update_ide_key(found_trigger_value); + } + xdebug_init_debugger(); + } + + if (found_trigger_value) { + xdfree(found_trigger_value); + } + + xdebug_handle_stop_session(); +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/debugger/com.h
Added
@@ -0,0 +1,68 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2020 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __HAVE_XDEBUG_COM_H__ +#define __HAVE_XDEBUG_COM_H__ + +#include "handlers.h" + +#if WIN32|WINNT +# define SOCK_ERR INVALID_SOCKET +# define SOCK_CONN_ERR SOCKET_ERROR +# define SOCK_RECV_ERR SOCKET_ERROR +#else +# define SOCK_ERR -1 +# define SOCK_CONN_ERR -1 +# define SOCK_RECV_ERR -1 +#endif +#define SOCK_TIMEOUT_ERR -2 +#define SOCK_ACCESS_ERR -3 + +#if WIN32|WINNT +#define SCLOSE(a) closesocket(a) +#define SSENDL(a,b,c) send(a,b,c,0) +#define SSEND(a,b) send(a,b,strlen(b),0) +#define SREAD(a,b,c) recv(a,b,c,0) +#else +#define SCLOSE(a) close(a) +#define SSENDL(a,b,c) write(a,b,c) +#define SSEND(a,b) write(a,b,strlen(b)) +#define SREAD(a,b,c) read(a,b,c) +#endif + + +#define SENDMSG(socket, str) { \ + char *message_buffer; \ + \ + message_buffer = str; \ + SSEND(socket, message_buffer); \ + xdfree(message_buffer); \ +} + +void xdebug_close_socket(int socket); + +/* Remote connection activation and house keeping */ +int xdebug_is_debug_connection_active(void); +void xdebug_abort_debugger(void); +void xdebug_restart_debugger(void); +void xdebug_mark_debug_connection_active(void); +void xdebug_mark_debug_connection_not_active(void); +void xdebug_mark_debug_connection_pending(void); +void xdebug_debug_init_if_requested_at_startup(void); +void xdebug_debug_init_if_requested_on_error(void); +void xdebug_debug_init_if_requested_on_xdebug_break(void); + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/debugger/debugger.c
Added
@@ -0,0 +1,968 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "php_xdebug.h" + +#include "ext/standard/info.h" +#include "zend_exceptions.h" + +#include "debugger_private.h" +#include "lib/log.h" +#include "lib/var.h" + +extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); + +static size_t (*xdebug_orig_ub_write)(const char *string, size_t len); +static size_t xdebug_ub_write(const char *string, size_t length); + +static void xdebug_line_list_dtor(xdebug_lines_list *line_list); + +void xdebug_init_debugger_globals(xdebug_debugger_globals_t *xg) +{ + xg->breakpoint_count = 0; + xg->ide_key = NULL; + xg->stdout_mode = 0; + xg->no_exec = 0; + xg->context.program_name = NULL; + xg->context.list.last_filename = NULL; + xg->context.list.last_line = 0; + xg->context.do_break = 0; + xg->context.pending_breakpoint = NULL; + xg->context.do_step = 0; + xg->context.do_next = 0; + xg->context.do_finish = 0; + xg->context.do_connect_to_client = 0; + + xg->remote_connection_enabled = 0; + xg->remote_connection_pid = 0; + xg->breakpoints_allowed = 0; + xg->suppress_return_value_step = 0; + + /* Capturing output */ + if (sapi_module.ub_write != xdebug_ub_write) { + xdebug_orig_ub_write = sapi_module.ub_write; + sapi_module.ub_write = xdebug_ub_write; + } + + /* Statistics and diagnostics */ + xg->context.connected_hostname = NULL; + xg->context.connected_port = 0; + xg->context.detached_message = NULL; +} + +static char *xdebug_debugger_get_ide_key(void) +{ + char *ide_key; + + ide_key = XINI_DBG(ide_key_setting); + if (ide_key && *ide_key) { + return ide_key; + } + + ide_key = getenv("DBGP_IDEKEY"); + if (ide_key && *ide_key) { + return ide_key; + } + + return NULL; +} + +void xdebug_debugger_reset_ide_key(char *envval) +{ + if (XG_DBG(ide_key)) { + xdfree(XG_DBG(ide_key)); + } + XG_DBG(ide_key) = xdstrdup(envval); +} + +int xdebug_debugger_bailout_if_no_exec_requested(void) +{ + /* We need to do this first before the executable clauses are called */ + if (XG_DBG(no_exec) == 1) { + php_printf("DEBUG SESSION ENDED"); + return 1; + } + return 0; +} + +static void register_compiled_variables(void) +{ + function_stack_entry *loop_fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + int i; + + for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, loop_fse--) { + if (loop_fse->declared_vars) { + continue; + } + + if (loop_fse->user_defined == XDEBUG_BUILT_IN) { + continue; + } + + xdebug_lib_register_compiled_variables(loop_fse, loop_fse->op_array); + } +} + + +void xdebug_debugger_set_program_name(zend_string *filename) +{ + if (!XG_DBG(context).program_name) { + XG_DBG(context).program_name = zend_string_copy(filename); + } +} + +/* Remote debugger helper functions */ +static int xdebug_handle_hit_value(xdebug_brk_info *brk_info) +{ + /* If this is a temporary breakpoint, disable the breakpoint */ + if (brk_info->temporary) { + brk_info->disabled = 1; + } + + /* Increase hit counter */ + brk_info->hit_count++; + + /* If the hit_value is 0, the condition check is disabled */ + if (!brk_info->hit_value) { + return 1; + } + + switch (brk_info->hit_condition) { + case XDEBUG_HIT_GREATER_EQUAL: + if (brk_info->hit_count >= brk_info->hit_value) { + return 1; + } + break; + case XDEBUG_HIT_EQUAL: + if (brk_info->hit_count == brk_info->hit_value) { + return 1; + } + break; + case XDEBUG_HIT_MOD: + if (brk_info->hit_count % brk_info->hit_value == 0) { + return 1; + } + break; + case XDEBUG_HIT_DISABLED: + return 1; + break; + } + return 0; +} + +int xdebug_do_eval(char *eval_string, zval *ret_zval) +{ + volatile int res = 1; + zend_execute_data *original_execute_data = EG(current_execute_data); + int original_no_extensions = EG(no_extensions); + zend_object *original_exception = EG(exception); + JMP_BUF *original_bailout = EG(bailout); + + /* Remember error reporting level and track errors */ + XG_BASE(error_reporting_override) = EG(error_reporting); + XG_BASE(error_reporting_overridden) = 1; + EG(error_reporting) = 0; + + XG_DBG(context).inhibit_notifications = 1; + XG_DBG(breakpoints_allowed) = 0; + + /* Reset exception in case we're triggered while being in xdebug_throw_exception_hook */ + EG(exception) = NULL; + + /* Do evaluation */ + zend_first_try { + res = (zend_eval_string(eval_string, ret_zval, (char*) "xdebug://debug-eval") == SUCCESS); + } zend_end_try(); + + /* FIXME: Bubble up exception message to DBGp return packet */ + if (EG(exception)) { + if (!res) { + zend_clear_exception(); + } + res = 0; + } + + /* Clean up */ + EG(error_reporting) = XG_BASE(error_reporting_override); + XG_BASE(error_reporting_overridden) = 0; + XG_DBG(breakpoints_allowed) = 1; + XG_DBG(suppress_return_value_step) = 0; + XG_DBG(context).inhibit_notifications = 0; + + EG(current_execute_data) = original_execute_data; + EG(no_extensions) = original_no_extensions; + EG(exception) = original_exception; + EG(bailout) = original_bailout; + + return res; +} + +int next_condition_met(void) +{ + function_stack_entry *fse; + int level = 0; + + if (!XG_DBG(context).do_next) { + return 0; + } + + /* Get latest stack level and function number */ + if (XG_BASE(stack) && XDEBUG_VECTOR_TAIL(XG_BASE(stack))) { + fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + level = fse->level; + } + + if (XG_DBG(context).next_level >= level) { + return 1; + } + + return 0; +} + +int finish_condition_met(int break_at_return_scope) +{ + function_stack_entry *fse; + int level = 0; + int func_nr = 0; + + if (!XG_DBG(context).do_finish) { + return 0; + } + + /* Get latest stack level and function number */ + if (XG_BASE(stack) && XDEBUG_VECTOR_TAIL(XG_BASE(stack))) { + fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + level = fse->level; + func_nr = fse->function_nr; + } + + if (!break_at_return_scope && level < XG_DBG(context).finish_level) { + return 1; + } + + if (break_at_return_scope && level <= XG_DBG(context).finish_level) { + return 1; + } + + if ( + (level == XG_DBG(context).finish_level) && + (func_nr > XG_DBG(context).finish_func_nr) + ) { + return 1; + } + + return 0; +} + +void xdebug_debugger_statement_call(zend_string *filename, int lineno) +{ + xdebug_llist_element *le; + xdebug_brk_info *extra_brk_info; + + if (XG_DBG(context).do_connect_to_client) { + XG_DBG(context).do_connect_to_client = 0; + + if (!xdebug_is_debug_connection_active()) { + xdebug_debug_init_if_requested_on_xdebug_break(); + register_compiled_variables(); + } + } + + if (xdebug_is_debug_connection_active()) { + XG_DBG(suppress_return_value_step) = 0; + + if (XG_DBG(context).do_break) { + xdebug_brk_info *brk_info = XG_DBG(context).pending_breakpoint; + + XG_DBG(context).do_break = 0; + XG_DBG(context).pending_breakpoint = NULL; + + if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), filename, lineno, XDEBUG_BREAK, NULL, 0, NULL, brk_info, NULL)) { + xdebug_mark_debug_connection_not_active(); + return; + } + return; + } + + /* Check for "finish" */ + if (finish_condition_met(0)) { + XG_DBG(context).do_finish = 0; + + if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), filename, lineno, XDEBUG_STEP, NULL, 0, NULL, NULL, NULL)) { + xdebug_mark_debug_connection_not_active(); + return; + } + return; + } + + /* Check for "next" */ + if (next_condition_met()) { + XG_DBG(context).do_next = 0; + + if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), filename, lineno, XDEBUG_STEP, NULL, 0, NULL, NULL, NULL)) { + xdebug_mark_debug_connection_not_active(); + return; + } + return; + } + + /* Check for "step" */ + if (XG_DBG(context).do_step) { + XG_DBG(context).do_step = 0; + + if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), filename, lineno, XDEBUG_STEP, NULL, 0, NULL, NULL, NULL)) { + xdebug_mark_debug_connection_not_active(); + return; + } + return; + } + + if (XG_DBG(context).line_breakpoints) { + int break_ok, res; + zval retval; + + for (le = XDEBUG_LLIST_HEAD(XG_DBG(context).line_breakpoints); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { + extra_brk_info = XDEBUG_LLIST_VALP(le); + + if (XG_DBG(context).handler->break_on_line(&(XG_DBG(context)), extra_brk_info, filename, lineno)) { + break_ok = 1; /* Breaking is allowed by default */ + + /* Check if we have a condition set for it */ + if (extra_brk_info->condition) { + /* If there is a condition, we disable breaking by + * default and only enabled it when the code evaluates + * to TRUE */ + break_ok = 0; + + /* Remember error reporting level */ + res = xdebug_do_eval(extra_brk_info->condition, &retval); + if (res) { + break_ok = Z_TYPE(retval) == IS_TRUE; + zval_dtor(&retval); + } + } + if (break_ok && xdebug_handle_hit_value(extra_brk_info)) { + if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), filename, lineno, XDEBUG_BREAK, NULL, 0, NULL, extra_brk_info, NULL)) { + xdebug_mark_debug_connection_not_active(); + break; + } + return; + } + } + } + } + } +} + +void xdebug_debugger_throw_exception_hook(zend_object *exception, zval *file, zval *line, zval *code, char *code_str, zval *message) +{ + zend_class_entry *exception_ce = exception->ce; + xdebug_brk_info *extra_brk_info; + + register_compiled_variables(); + + /* Start JIT if requested and not yet enabled */ + xdebug_debug_init_if_requested_on_error(); + + if (!xdebug_is_debug_connection_active() || !XG_DBG(breakpoints_allowed)) { + return; + } + + { + int exception_breakpoint_found = 0; + + XG_DBG(suppress_return_value_step) = 1; + + /* Check if we have a wild card exception breakpoint */ + if (xdebug_hash_find(XG_DBG(context).exception_breakpoints, "*", 1, (void *) &extra_brk_info)) { + exception_breakpoint_found = 1; + } else { + /* Check if we have a breakpoint on this exception or its parent classes */ + zend_class_entry *ce_ptr = exception_ce; + + /* Check if we have a breakpoint on this exception or its parent classes */ + do { + if (xdebug_hash_find(XG_DBG(context).exception_breakpoints, (char *) STR_NAME_VAL(ce_ptr->name), STR_NAME_LEN(ce_ptr->name), (void *) &extra_brk_info)) { + exception_breakpoint_found = 1; + } + ce_ptr = ce_ptr->parent; + } while (!exception_breakpoint_found && ce_ptr); + } +#if 0 + if (XG_DBG(context).resolved_breakpoints && exception_breakpoint_found) { + XG_DBG(context).handler->resolve_breakpoints(&(XG_DBG(context)), extra_brk_info); + } +#endif + if (exception_breakpoint_found && xdebug_handle_hit_value(extra_brk_info)) { + if ( + !XG_DBG(context).handler->remote_breakpoint( + &(XG_DBG(context)), XG_BASE(stack), + zend_get_executed_filename_ex(), zend_get_executed_lineno(), + XDEBUG_BREAK, + (char*) STR_NAME_VAL(exception_ce->name), + code_str ? code_str : ((code && Z_TYPE_P(code) == IS_STRING) ? Z_STRVAL_P(code) : NULL), + message ? Z_STRVAL_P(message) : "", + extra_brk_info, + NULL + ) + ) { + xdebug_mark_debug_connection_not_active(); + } + } + } +} + +void xdebug_debugger_error_cb(zend_string *error_filename, int error_lineno, int type, char *error_type_str, char *buffer) +{ + xdebug_brk_info *extra_brk_info = NULL; + + register_compiled_variables(); + + /* Start JIT if requested and not yet enabled */ + xdebug_debug_init_if_requested_on_error(); + + if (!xdebug_is_debug_connection_active() || !XG_DBG(breakpoints_allowed)) { + return; + } + + /* Send notification with warning/notice/error information */ + if (XG_DBG(context).send_notifications && !XG_DBG(context).inhibit_notifications) { + if (!XG_DBG(context).handler->remote_notification(&(XG_DBG(context)), error_filename, error_lineno, type, error_type_str, buffer)) { + xdebug_mark_debug_connection_not_active(); + } + } + + /* Check for the pseudo exceptions to allow breakpoints on PHP error statuses */ + if ( + xdebug_hash_find(XG_DBG(context).exception_breakpoints, error_type_str, strlen(error_type_str), (void *) &extra_brk_info) || + xdebug_hash_find(XG_DBG(context).exception_breakpoints, "*", 1, (void *) &extra_brk_info) + ) { + if (xdebug_handle_hit_value(extra_brk_info)) { + char *type_str = xdebug_sprintf("%ld", type); + + if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), error_filename, error_lineno, XDEBUG_BREAK, error_type_str, type_str, buffer, extra_brk_info, NULL)) { + xdebug_mark_debug_connection_not_active(); + } + + xdfree(type_str); + } + } +} + +static int handle_breakpoints(function_stack_entry *fse, int breakpoint_type, zval *return_value) +{ + char *tmp_name = NULL; + size_t tmp_len = 0; + xdebug_brk_info *extra_brk_info = NULL; + + /* Function breakpoints */ + if (fse->function.type == XFUNC_NORMAL) { + tmp_len = 2 + strlen(fse->function.function) + 1; + tmp_name = xdmalloc(tmp_len); + /* We intentionally do not use xdebug_sprintf because it can create a bottleneck in large + * codebases due to setlocale calls. We don't care about the locale here. */ + snprintf( + tmp_name, tmp_len, + "%c/%s", + (breakpoint_type & XDEBUG_BREAKPOINT_TYPE_CALL) ? 'C' : 'R', + fse->function.function + ); + } + /* class->function breakpoints */ + else if (fse->function.type == XFUNC_MEMBER || fse->function.type == XFUNC_STATIC_MEMBER) { + /* Using strlen(ZSTR_VAL(...)) here to cut of the string at the first \0, which is needed + * for anonymous classes, in combination with the snprintf() below */ + tmp_len = 2 + strlen(ZSTR_VAL(fse->function.object_class)) + 2 + strlen(fse->function.function) + 1; + tmp_name = xdmalloc(tmp_len); + /* We intentionally do not use xdebug_sprintf because it can create a bottleneck in large + * codebases due to setlocale calls. We don't care about the locale here. */ + snprintf( + tmp_name, tmp_len, + "%c/%s::%s", + (breakpoint_type & XDEBUG_BREAKPOINT_TYPE_CALL) ? 'C' : 'R', + ZSTR_VAL(fse->function.object_class), fse->function.function + ); + } + /* Unknown */ + else { + return 1; + } + + if (xdebug_hash_find(XG_DBG(context).function_breakpoints, tmp_name, tmp_len - 1, (void *) &extra_brk_info)) { + /* Yup, breakpoint found, call handler if the breakpoint is not + * disabled AND handle_hit_value is happy */ + if (!extra_brk_info->disabled && (extra_brk_info->function_break_type == (breakpoint_type & XDEBUG_BREAKPOINT_TYPES_MASK))) { + if (xdebug_handle_hit_value(extra_brk_info)) { + if (fse->user_defined == XDEBUG_BUILT_IN || (breakpoint_type & XDEBUG_BREAKPOINT_TYPE_RETURN)) { + if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), fse->filename, fse->lineno, XDEBUG_BREAK, NULL, 0, NULL, extra_brk_info, return_value)) { + xdfree(tmp_name); + return 0; + } + } else { + XG_DBG(context).do_break = 1; + XG_DBG(context).pending_breakpoint = extra_brk_info; + } + } + } + } + xdfree(tmp_name); + + if ( + (XG_DBG(context).breakpoint_include_return_value) && + (breakpoint_type & XDEBUG_BREAKPOINT_TYPE_RETURN) && + !(XG_DBG(suppress_return_value_step)) && + return_value + ) { + if (XG_DBG(context).do_step) { + XG_DBG(context).do_step = 0; + } else if (finish_condition_met(1)) { + XG_DBG(context).do_finish = 0; + } else { + return 1; + } + + if (!XG_DBG(context).handler->remote_breakpoint(&(XG_DBG(context)), XG_BASE(stack), fse->filename, fse->lineno, XDEBUG_BREAK, NULL, 0, NULL, extra_brk_info, return_value)) { + return 0; + } + } + + return 1; +} + +void xdebug_debugger_handle_breakpoints(function_stack_entry *fse, int breakpoint_type, zval *return_value) +{ + if (xdebug_is_debug_connection_active() && XG_DBG(breakpoints_allowed)) { + if (!handle_breakpoints(fse, breakpoint_type, return_value)) { + xdebug_mark_debug_connection_not_active(); + } + } +} + +static size_t xdebug_ub_write(const char *string, size_t length) +{ + if (xdebug_is_debug_connection_active()) { + if (-1 == XG_DBG(context).handler->remote_stream_output(string, length)) { + return 0; + } + } + return xdebug_orig_ub_write(string, length); +} + +static void xdebug_hook_output_handlers() +{ + /* Override output handler for capturing output */ + if (xdebug_orig_ub_write == NULL) { + xdebug_orig_ub_write = sapi_module.ub_write; + sapi_module.ub_write = xdebug_ub_write; + } +} + +static void xdebug_unhook_output_handlers() +{ + /* Restore original output handler */ + sapi_module.ub_write = xdebug_orig_ub_write; + xdebug_orig_ub_write = NULL; +} + +void xdebug_debugger_zend_startup(void) +{ + /* Hook output handlers (header and output writer) */ + xdebug_hook_output_handlers(); +} + +void xdebug_debugger_zend_shutdown(void) +{ + /* Remove our hooks to output handlers (header and output writer) */ + xdebug_unhook_output_handlers(); +} + +void xdebug_debugger_minit(void) +{ + XG_DBG(breakpoint_count) = 0; +} + +void xdebug_debugger_minfo(void) +{ + php_info_print_table_start(); + php_info_print_table_header(2, "Debugger", "enabled"); + php_info_print_table_row(2, "IDE Key", XG_DBG(ide_key)); + php_info_print_table_end(); +} + +void xdebug_debugger_rinit(void) +{ + char *idekey; + + xdebug_disable_opcache_optimizer(); + + /* Get the ide key for this session */ + XG_DBG(ide_key) = NULL; + idekey = xdebug_debugger_get_ide_key(); + if (idekey && *idekey) { + if (XG_DBG(ide_key)) { + xdfree(XG_DBG(ide_key)); + } + XG_DBG(ide_key) = xdstrdup(idekey); + } + + XG_DBG(no_exec) = 0; + xdebug_lib_set_active_symbol_table(NULL); + + /* Check if we have this special get variable that stops a debugging + * request without executing any code */ + { + zend_string *stop_no_exec = zend_string_init(ZEND_STRL("XDEBUG_SESSION_STOP_NO_EXEC"), 0); + if ( + ( + ( + zend_hash_find(Z_ARR(PG(http_globals)TRACK_VARS_GET), stop_no_exec) != NULL + ) || ( + zend_hash_find(Z_ARR(PG(http_globals)TRACK_VARS_POST), stop_no_exec) != NULL + ) + ) + && !SG(headers_sent) + ) { + xdebug_setcookie("XDEBUG_SESSION", sizeof("XDEBUG_SESSION") - 1, (char*) "", 0, 0, "/", 1, NULL, 0, 0, 1, 0); + XG_DBG(no_exec) = 1; + } + zend_string_release(stop_no_exec); + } + + xdebug_mark_debug_connection_not_active(); + + XG_DBG(breakpoints_allowed) = 1; + XG_DBG(suppress_return_value_step) = 0; + XG_DBG(detached) = 0; + XG_DBG(breakable_lines_map) = xdebug_hash_alloc(2048, (xdebug_hash_dtor_t) xdebug_line_list_dtor); + XG_DBG(function_count) = 0; + XG_DBG(class_count) = 0; + + /* Initialize some debugger context properties */ + XG_DBG(context).program_name = NULL; + XG_DBG(context).list.last_filename = NULL; + XG_DBG(context).list.last_line = 0; + XG_DBG(context).do_break = 0; + XG_DBG(context).pending_breakpoint = NULL; + XG_DBG(context).do_step = 0; + XG_DBG(context).do_next = 0; + XG_DBG(context).do_finish = 0; + XG_DBG(context).do_connect_to_client = 0; + + /* Statistics and diagnostics */ + XG_DBG(context).connected_hostname = NULL; + XG_DBG(context).connected_port = 0; + XG_DBG(context).detached_message = NULL; +} + +void xdebug_debugger_post_deactivate(void) +{ + if (XG_DBG(remote_connection_enabled)) { + XG_DBG(context).handler->remote_deinit(&(XG_DBG(context))); + xdebug_close_socket(XG_DBG(context).socket); + } + if (XG_DBG(context).program_name) { + zend_string_release(XG_DBG(context).program_name); + } + + if (XG_DBG(ide_key)) { + xdfree(XG_DBG(ide_key)); + XG_DBG(ide_key) = NULL; + } + + if (XG_DBG(context.list.last_filename)) { + zend_string_release(XG_DBG(context).list.last_filename); + XG_DBG(context).list.last_filename = NULL; + } + + xdebug_hash_destroy(XG_DBG(breakable_lines_map)); + XG_DBG(breakable_lines_map) = NULL; + + if (XG_DBG(context).connected_hostname) { + xdfree(XG_DBG(context).connected_hostname); + XG_DBG(context).connected_hostname = NULL; + } + + if (XG_DBG(context).detached_message) { + xdfree(XG_DBG(context).detached_message); + XG_DBG(context).detached_message = NULL; + } +} + +xdebug_set *xdebug_debugger_get_breakable_lines_from_oparray(zend_op_array *opa) +{ + int i; + xdebug_set *tmp; + + tmp = xdebug_set_create(opa->line_end); + + for (i = 0; i < opa->last; i++ ) { + if (opa->opcodesi.opcode == ZEND_EXT_STMT ) { + xdebug_set_add(tmp, opa->opcodesi.lineno); + } + } + + return tmp; +} + + +/* {{{ function/lines map collection helpers */ +static void xdebug_function_lines_map_dtor(xdebug_function_lines_map_item *lines_map) +{ + xdebug_set_free(lines_map->lines_breakable); + xdfree(lines_map); +} + +static void xdebug_line_list_dtor(xdebug_lines_list *line_list) +{ + size_t i; + + for (i = 0; i < line_list->count; i++) { + xdebug_function_lines_map_dtor(line_list->functionsi); + } + xdfree(line_list->functions); + xdfree(line_list); +} + +static xdebug_lines_list *get_file_function_line_list(zend_string *filename) +{ + xdebug_lines_list *lines_list; + + if (xdebug_hash_find(XG_DBG(breakable_lines_map), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &lines_list)) { + return lines_list; + } + + lines_list = xdmalloc(sizeof(xdebug_lines_list)); + lines_list->count = 0; + lines_list->size = 0; + lines_list->functions = NULL; + + xdebug_hash_add(XG_DBG(breakable_lines_map), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) lines_list); + + return lines_list; +} + +static void add_function_to_lines_list(xdebug_lines_list *lines_list, zend_op_array *opa) +{ + xdebug_function_lines_map_item *map_item = xdmalloc(sizeof(xdebug_function_lines_map_item)); + + map_item->line_start = opa->line_start; + map_item->line_end = opa->line_end; + map_item->line_span = opa->line_end - opa->line_start; + map_item->lines_breakable = xdebug_debugger_get_breakable_lines_from_oparray(opa); + + if (lines_list->count >= lines_list->size) { + lines_list->size = lines_list->size == 0 ? 16 : lines_list->size * 2; + lines_list->functions = xdrealloc(lines_list->functions, sizeof(xdebug_function_lines_map_item *) * lines_list->size); + } + lines_list->functionslines_list->count = map_item; + lines_list->count++; + +#if PHP_VERSION_ID >= 80100 + if (opa->num_dynamic_func_defs) { + uint32_t i; + + for (i = 0; i < opa->num_dynamic_func_defs; i++) { + add_function_to_lines_list(lines_list, opa->dynamic_func_defsi); + } + } +#endif +} +/* }}} */ + +static void resolve_breakpoints_for_function(xdebug_lines_list *lines_list, zend_op_array *opa) +{ + add_function_to_lines_list(lines_list, opa); +} + +static void resolve_breakpoints_for_class(xdebug_lines_list *file_function_lines_list, zend_class_entry *ce, zend_string *filename) +{ + zend_op_array *function_op_array; + + ZEND_HASH_FOREACH_PTR(&ce->function_table, function_op_array) { + if (!ZEND_USER_CODE(function_op_array->type)) { + continue; + } + /* Only resolve if the file names are the same. This is needed in case + * of inheritance or traits where op arrays from other files might get introduced */ + if (ZSTR_LEN(filename) != ZSTR_LEN(function_op_array->filename)) { + continue; + } + if (strcmp(ZSTR_VAL(filename), ZSTR_VAL(function_op_array->filename)) != 0) { + continue; + } + resolve_breakpoints_for_function(file_function_lines_list, function_op_array); + } ZEND_HASH_FOREACH_END(); +} + +void xdebug_debugger_compile_file(zend_op_array *op_array) +{ + zend_op_array *function_op_array; + zend_class_entry *class_entry; + xdebug_lines_list *file_function_lines_list; + + RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); + + /* The breakable_lines_map can not be set if another extension compiles + * scripts during RINIT */ + if (!XG_DBG(breakable_lines_map)) { + return; + } + + file_function_lines_list = get_file_function_line_list(op_array->filename); + + ZEND_HASH_REVERSE_FOREACH_PTR(CG(function_table), function_op_array) { + if (_idx == XG_DBG(function_count)) { + break; + } + if (!ZEND_USER_CODE(function_op_array->type)) { + continue; + } + resolve_breakpoints_for_function(file_function_lines_list, function_op_array); + } ZEND_HASH_FOREACH_END(); + XG_DBG(function_count) = CG(function_table)->nNumUsed; + + ZEND_HASH_REVERSE_FOREACH_PTR(CG(class_table), class_entry) { + if (_idx == XG_DBG(class_count)) { + break; + } + if (class_entry->type == ZEND_INTERNAL_CLASS) { + continue; + } + resolve_breakpoints_for_class(file_function_lines_list, class_entry, op_array->filename); + } ZEND_HASH_FOREACH_END(); + XG_DBG(class_count) = CG(class_table)->nNumUsed; + + add_function_to_lines_list(file_function_lines_list, op_array); + + if (!xdebug_is_debug_connection_active()) { + return; + } + + XG_DBG(context).handler->resolve_breakpoints( + &(XG_DBG(context)), + op_array->filename + ); +} + +static void resolve_breakpoints_for_eval(int eval_id, zend_op_array *opa) +{ + xdebug_lines_list *lines_list; + char *eval_filename = xdebug_sprintf("dbgp://%d", eval_id); + zend_string *eval_string = zend_string_init(eval_filename, strlen(eval_filename), 0); + + lines_list = get_file_function_line_list(eval_string); + add_function_to_lines_list(lines_list, opa); + + resolve_breakpoints_for_function(lines_list, opa); + + if (!xdebug_is_debug_connection_active()) { + zend_string_release(eval_string); + xdfree(eval_filename); + return; + } + + XG_DBG(context).handler->resolve_breakpoints( + &(XG_DBG(context)), + eval_string + ); + + zend_string_release(eval_string); + xdfree(eval_filename); +} + +void xdebug_debugger_register_eval(function_stack_entry *fse) +{ + if (xdebug_is_debug_connection_active() && XG_DBG(context).handler->register_eval_id) { + int eval_id = XG_DBG(context).handler->register_eval_id(&(XG_DBG(context)), fse); + + resolve_breakpoints_for_eval(eval_id, fse->op_array); + } +} + +void xdebug_debugger_restart_if_pid_changed() +{ + zend_ulong pid; + + if (!xdebug_is_debug_connection_active()) { + return; + } + + pid = xdebug_get_pid(); + + /* Start debugger if previously a connection was established and this + * process no longer has the same PID */ + if (XG_DBG(remote_connection_pid) != pid) { + xdebug_restart_debugger(); + } +} + +PHP_FUNCTION(xdebug_break) +{ + RETURN_FALSE_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); + + xdebug_debug_init_if_requested_on_xdebug_break(); + + if (!xdebug_is_debug_connection_active()) { + RETURN_FALSE; + } + + register_compiled_variables(); + + XG_DBG(context).do_break = 1; + XG_DBG(context).pending_breakpoint = NULL; + + RETURN_TRUE; +} + +PHP_FUNCTION(xdebug_connect_to_client) +{ + RETURN_FALSE_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); + + XG_DBG(context).do_connect_to_client = 1; + + RETURN_TRUE; +} + +PHP_FUNCTION(xdebug_is_debugger_active) +{ + RETURN_BOOL(xdebug_is_debug_connection_active()); +} + +PHP_FUNCTION(xdebug_notify) +{ + function_stack_entry *fse; + zval *data; + + RETURN_FALSE_IF_MODE_IS_NOT(XDEBUG_MODE_STEP_DEBUG); + + if (!xdebug_is_debug_connection_active()) { + RETURN_FALSE; + } + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "z", &data) == FAILURE) { + return; + } + + fse = xdebug_get_stack_frame(0); + + XG_DBG(context).handler->user_notification( + &(XG_DBG(context)), + fse->filename, fse->lineno, + data + ); + + RETURN_TRUE; +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/debugger/debugger.h
Added
@@ -0,0 +1,95 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __XDEBUG_DEBUGGER_H__ +#define __XDEBUG_DEBUGGER_H__ + +#include "com.h" + +typedef struct _xdebug_debugger_globals_t { + int status; + int reason; + const char *lastcmd; + char *lasttransid; + zval *current_return_value; + + zend_bool remote_connection_enabled; + zend_ulong remote_connection_pid; + zend_bool breakpoints_allowed; + zend_bool suppress_return_value_step; + zend_bool detached; + xdebug_con context; + unsigned int breakpoint_count; + unsigned int no_exec; + char *ide_key; /* As Xdebug uses it, from environment, USER, USERNAME or empty */ + + /* breakpoint resolving */ + size_t function_count; + size_t class_count; + xdebug_hash *breakable_lines_map; + + /* output redirection */ + int stdout_mode; +} xdebug_debugger_globals_t; + +typedef struct _xdebug_debugger_settings_t { + /* Cloud */ + char *cloud_id; + char *cloud_shared_key; + + /* Step Debugger */ + zend_long client_port; /* 9000 */ + char *client_host; /* localhost */ + zend_bool discover_client_host; /* (try to) connect back to the HTTP requestor */ + char *client_discovery_header; /* User configured header to check for forwarded IP address */ + zend_long connect_timeout_ms; /* Timeout in MS for remote connections */ + + char *ide_key_setting; /* Set through php.ini and friends */ +} xdebug_debugger_settings_t; + +PHP_INI_MH(OnUpdateDebugMode); + +void xdebug_init_debugger_globals(xdebug_debugger_globals_t *xg); + +#define XDEBUG_RETURN_VALUE_VAR_NAME "__RETURN_VALUE" + +void xdebug_debugger_reset_ide_key(char *envval); +int xdebug_debugger_bailout_if_no_exec_requested(void); +void xdebug_debugger_set_program_name(zend_string *filename); +void xdebug_debugger_register_eval(function_stack_entry *fse); +void xdebug_debugger_restart_if_pid_changed(void); + +xdebug_set *xdebug_debugger_get_breakable_lines_from_oparray(zend_op_array *opa); +int xdebug_do_eval(char *eval_string, zval *ret_zval); + +void xdebug_debugger_statement_call(zend_string *filename, int lineno); +void xdebug_debugger_throw_exception_hook(zend_object *exception, zval *file, zval *line, zval *code, char *code_str, zval *message); +void xdebug_debugger_error_cb(zend_string *error_filename, int error_lineno, int type, char *error_type_str, char *buffer); +void xdebug_debugger_handle_breakpoints(function_stack_entry *fse, int breakpoint_type, zval *return_value); + +void xdebug_debugger_zend_startup(void); +void xdebug_debugger_zend_shutdown(void); +void xdebug_debugger_minit(void); +void xdebug_debugger_minfo(void); +void xdebug_debugger_rinit(void); +void xdebug_debugger_post_deactivate(void); + +void xdebug_debugger_compile_file(zend_op_array *op_array); + +PHP_FUNCTION(xdebug_break); + + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/debugger/debugger_private.h
Changed
(renamed from xdebug-3.1.5/src/debugger/debugger_private.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/debugger/handler_dbgp.c
Added
@@ -0,0 +1,3159 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include <sys/types.h> + +#ifndef PHP_WIN32 +#include <unistd.h> +#endif + +#include "lib/php-header.h" +#include "SAPI.h" + +#include "ext/standard/php_string.h" +#include "ext/standard/url.h" +#include "main/php_version.h" +#include "main/php_network.h" +#include "ext/standard/base64.h" +#include "TSRM.h" + +#include "php_globals.h" +#include "php_xdebug.h" + +#include "com.h" +#include "handler_dbgp.h" +#include "debugger_private.h" + +#include "coverage/code_coverage.h" +#include "develop/stack.h" +#include "lib/compat.h" +#include "lib/hash.h" +#include "lib/llist.h" +#include "lib/log.h" +#include "lib/mm.h" +#include "lib/var_export_xml.h" +#include "lib/vector.h" +#include "lib/xml.h" + +#ifdef PHP_WIN32 +#include "win32/time.h" +#include <process.h> +#endif +#include <fcntl.h> + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +xdebug_remote_handler xdebug_handler_dbgp = { + xdebug_dbgp_init, + xdebug_dbgp_deinit, + xdebug_dbgp_error, + xdebug_dbgp_break_on_line, + xdebug_dbgp_breakpoint, + xdebug_dbgp_resolve_breakpoints, + xdebug_dbgp_stream_output, + xdebug_dbgp_notification, + xdebug_dbgp_user_notify, + xdebug_dbgp_register_eval_id, +}; + +static char *create_eval_key_id(int id); +static void line_breakpoint_resolve_helper(xdebug_con *context, xdebug_lines_list *lines_list, xdebug_brk_info *brk_info); + +/***************************************************************************** +** Constants and strings for statii and reasons +*/ + +/* Status structure */ +#define DBGP_STATUS_STARTING 1 +#define DBGP_STATUS_STOPPING 2 +#define DBGP_STATUS_STOPPED 3 +#define DBGP_STATUS_RUNNING 4 +#define DBGP_STATUS_BREAK 5 +#define DBGP_STATUS_DETACHED 6 + +const char *xdebug_dbgp_status_strings7 = + {"", "starting", "stopping", "stopped", "running", "break", "detached"}; + +#define DBGP_REASON_OK 0 +#define DBGP_REASON_ERROR 1 +#define DBGP_REASON_ABORTED 2 +#define DBGP_REASON_EXCEPTION 3 + +const char *xdebug_dbgp_reason_strings4 = + {"ok", "error", "aborted", "exception"}; + +typedef struct { + int code; + const char *message; +} xdebug_error_entry; + +xdebug_error_entry xdebug_error_codes24 = { + { 0, "no error" }, + { 1, "parse error in command" }, + { 2, "duplicate arguments in command" }, + { 3, "invalid or missing options" }, + { 4, "unimplemented command" }, + { 5, "command is not available" }, + { 100, "can not open file" }, + { 101, "stream redirect failed" }, + { 200, "breakpoint could not be set" }, + { 201, "breakpoint type is not supported" }, + { 202, "invalid breakpoint line" }, + { 203, "no code on breakpoint line" }, + { 204, "invalid breakpoint state" }, + { 205, "no such breakpoint" }, + { 206, "error evaluating code" }, + { 207, "invalid expression" }, + { 300, "can not get property" }, + { 301, "stack depth invalid" }, + { 302, "context invalid" }, + { 800, "profiler not started" }, + { 900, "encoding not supported" }, + { 998, "an internal exception in the debugger" }, + { 999, "unknown error" }, + { -1, NULL } +}; + +#define XDEBUG_STR_SWITCH_DECL char *__switch_variable +#define XDEBUG_STR_SWITCH(s) __switch_variable = (s); +#define XDEBUG_STR_CASE(s) if (strcmp(__switch_variable, s) == 0) { +#define XDEBUG_STR_CASE_END } else +#define XDEBUG_STR_CASE_DEFAULT { +#define XDEBUG_STR_CASE_DEFAULT_END } + +#define XDEBUG_TYPES_COUNT 8 +const char *xdebug_dbgp_typemapXDEBUG_TYPES_COUNT3 = { + /* common, lang, schema */ + {"bool", "bool", "xsd:boolean"}, + {"int", "int", "xsd:decimal"}, + {"float", "float", "xsd:double"}, + {"string", "string", "xsd:string"}, + {"null", "null", NULL}, + {"hash", "array", NULL}, + {"object", "object", NULL}, + {"resource", "resource", NULL} +}; + + +typedef struct { + int value; + const char *name; +} xdebug_breakpoint_entry; + +#define XDEBUG_BREAKPOINT_TYPES_COUNT 6 +xdebug_breakpoint_entry xdebug_breakpoint_typesXDEBUG_BREAKPOINT_TYPES_COUNT = { + { XDEBUG_BREAKPOINT_TYPE_LINE, "line" }, + { XDEBUG_BREAKPOINT_TYPE_CONDITIONAL, "conditional" }, + { XDEBUG_BREAKPOINT_TYPE_CALL, "call" }, + { XDEBUG_BREAKPOINT_TYPE_RETURN, "return" }, + { XDEBUG_BREAKPOINT_TYPE_EXCEPTION, "exception" }, + { XDEBUG_BREAKPOINT_TYPE_WATCH, "watch" } +}; + +#define XDEBUG_DBGP_SCAN_RANGE 5 + +/***************************************************************************** +** Prototypes for debug command handlers +*/ + +/* DBGP_FUNC(break); */ +DBGP_FUNC(breakpoint_get); +DBGP_FUNC(breakpoint_list); +DBGP_FUNC(breakpoint_remove); +DBGP_FUNC(breakpoint_set); +DBGP_FUNC(breakpoint_update); + +DBGP_FUNC(context_get); +DBGP_FUNC(context_names); + +DBGP_FUNC(eval); +DBGP_FUNC(feature_get); +DBGP_FUNC(feature_set); + +DBGP_FUNC(typemap_get); +DBGP_FUNC(property_get); +DBGP_FUNC(property_set); +DBGP_FUNC(property_value); + +DBGP_FUNC(source); +DBGP_FUNC(stack_depth); +DBGP_FUNC(stack_get); +DBGP_FUNC(status); + +DBGP_FUNC(stderr); +DBGP_FUNC(stdout); + +DBGP_FUNC(stop); +DBGP_FUNC(run); +DBGP_FUNC(step_into); +DBGP_FUNC(step_out); +DBGP_FUNC(step_over); +DBGP_FUNC(detach); + +/* Non standard comments */ +DBGP_FUNC(xcmd_profiler_name_get); +DBGP_FUNC(xcmd_get_executable_lines); + +/***************************************************************************** +** Dispatcher tables for supported debug commands +*/ + +static xdebug_dbgp_cmd dbgp_commands = { + /* DBGP_FUNC_ENTRY(break) */ + DBGP_FUNC_ENTRY(breakpoint_get, XDEBUG_DBGP_NONE) + DBGP_FUNC_ENTRY(breakpoint_list, XDEBUG_DBGP_POST_MORTEM) + DBGP_FUNC_ENTRY(breakpoint_remove, XDEBUG_DBGP_NONE) + DBGP_FUNC_ENTRY(breakpoint_set, XDEBUG_DBGP_NONE) + DBGP_FUNC_ENTRY(breakpoint_update, XDEBUG_DBGP_NONE) + + DBGP_FUNC_ENTRY(context_get, XDEBUG_DBGP_NONE) + DBGP_FUNC_ENTRY(context_names, XDEBUG_DBGP_POST_MORTEM) + + DBGP_FUNC_ENTRY(eval, XDEBUG_DBGP_NONE) + DBGP_FUNC_ENTRY(feature_get, XDEBUG_DBGP_POST_MORTEM) + DBGP_FUNC_ENTRY(feature_set, XDEBUG_DBGP_NONE) + + DBGP_FUNC_ENTRY(typemap_get, XDEBUG_DBGP_POST_MORTEM) + DBGP_FUNC_ENTRY(property_get, XDEBUG_DBGP_NONE) + DBGP_FUNC_ENTRY(property_set, XDEBUG_DBGP_NONE) + DBGP_FUNC_ENTRY(property_value, XDEBUG_DBGP_NONE) + + DBGP_FUNC_ENTRY(source, XDEBUG_DBGP_NONE) + DBGP_FUNC_ENTRY(stack_depth, XDEBUG_DBGP_NONE) + DBGP_FUNC_ENTRY(stack_get, XDEBUG_DBGP_NONE) + DBGP_FUNC_ENTRY(status, XDEBUG_DBGP_POST_MORTEM) + + DBGP_FUNC_ENTRY(stderr, XDEBUG_DBGP_NONE) + DBGP_FUNC_ENTRY(stdout, XDEBUG_DBGP_NONE) + + DBGP_CONT_FUNC_ENTRY(run, XDEBUG_DBGP_NONE) + DBGP_CONT_FUNC_ENTRY(step_into, XDEBUG_DBGP_NONE) + DBGP_CONT_FUNC_ENTRY(step_out, XDEBUG_DBGP_NONE) + DBGP_CONT_FUNC_ENTRY(step_over, XDEBUG_DBGP_NONE) + + DBGP_STOP_FUNC_ENTRY(stop, XDEBUG_DBGP_POST_MORTEM) + DBGP_STOP_FUNC_ENTRY(detach, XDEBUG_DBGP_POST_MORTEM) + + /* Non standard functions */ + DBGP_FUNC_ENTRY(xcmd_profiler_name_get, XDEBUG_DBGP_POST_MORTEM) + DBGP_FUNC_ENTRY(xcmd_get_executable_lines, XDEBUG_DBGP_NONE) + { NULL, NULL, 0 } +}; + +/***************************************************************************** +** Utility functions +*/ + +static xdebug_dbgp_cmd* lookup_cmd(char *cmd) +{ + xdebug_dbgp_cmd *ptr = dbgp_commands; + + while (ptr->name) { + if (strcmp(ptr->name, cmd) == 0) { + return ptr; + } + ptr++; + } + return NULL; +} + +static xdebug_str *make_message(xdebug_con *context, xdebug_xml_node *message) +{ + xdebug_str xml_message = XDEBUG_STR_INITIALIZER; + xdebug_str *ret = xdebug_str_new(); + + xdebug_xml_return_node(message, &xml_message); + xdebug_log(XLOG_CHAN_DEBUG, XLOG_COM, "-> %s\n", xml_message.d); + + xdebug_str_add_fmt(ret, "%d", xml_message.l + sizeof("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n") - 1); + xdebug_str_addc(ret, '\0'); + xdebug_str_add_literal(ret, "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n"); + xdebug_str_add(ret, xml_message.d, 0); + xdebug_str_addc(ret, '\0'); + xdebug_str_destroy(&xml_message); + + return ret; +} + +static void send_message_ex(xdebug_con *context, xdebug_xml_node *message, int stage) +{ + xdebug_str *tmp; + size_t bytes_written; + + /* Sometimes we end up in 'send_message' although the debugging connection + * is already closed. In that case, we early return. */ + if (XG_DBG(status) != DBGP_STATUS_STARTING && !xdebug_is_debug_connection_active()) { + return; + } + + tmp = make_message(context, message); + + bytes_written = SSENDL(context->socket, tmp->d, tmp->l); + + /* Error */ + if (bytes_written == -1) { + int current_errno = php_socket_errno(); + char *sock_error = php_socket_strerror(current_errno, NULL, 0); + + if (current_errno == EPIPE) { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "REMCLOSE", "The debugging client closed the connection on socket %d: %s (error: %d).", context->socket, sock_error, current_errno); + xdebug_abort_debugger(); + } else { + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SENDERR", "There was a problem sending %zd bytes on socket %d: %s (error: %d).", tmp->l, context->socket, sock_error, current_errno); + } + + efree(sock_error); + + xdebug_str_free(tmp); + return; + } + + /* Not enough written, we'll allow that for now */ + if (bytes_written != tmp->l) { + char *sock_error = php_socket_strerror(php_socket_errno(), NULL, 0); + + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "SENDERR", "There was a problem sending %zd bytes on socket %d: only %zd bytes were written: %s.", tmp->l, context->socket, bytes_written, sock_error); + + efree(sock_error); + } + + xdebug_str_free(tmp); +} + +static void send_message(xdebug_con *context, xdebug_xml_node *message) +{ + send_message_ex(context, message, 0); +} + + +static xdebug_xml_node* get_symbol(xdebug_str *name, xdebug_var_export_options *options) +{ + zval retval; + xdebug_xml_node *tmp_node; + + xdebug_get_php_symbol(&retval, name); + + if (Z_TYPE(retval) == IS_UNDEF) { + return NULL; + } + + if (strcmp(name->d, "this") == 0 && Z_TYPE(retval) == IS_NULL) { + return NULL; + } + + tmp_node = xdebug_get_zval_value_xml_node(name, &retval, options); + zval_ptr_dtor_nogc(&retval); + + return tmp_node; +} + +static int get_symbol_contents(xdebug_str *name, xdebug_xml_node *node, xdebug_var_export_options *options) +{ + zval retval; + zval *retval_ptr; + + xdebug_get_php_symbol(&retval, name); + + if (Z_TYPE(retval) == IS_UNDEF) { + return 0; + } + + // TODO WTF??? + retval_ptr = &retval; + + xdebug_var_export_xml_node(&retval_ptr, name, node, options, 1); + zval_ptr_dtor_nogc(&retval); + + return 1; +} + +static xdebug_str* return_file_source(zend_string *filename, int begin, int end) +{ + php_stream *stream; + int i = begin; + char *line = NULL; + xdebug_str *source = xdebug_str_new(); + char *tmp_filename = NULL; + + if (i < 0) { + begin = 0; + i = 0; + } + xdebug_str_add_literal(source, ""); + + tmp_filename = xdebug_path_from_url(filename); + stream = php_stream_open_wrapper(tmp_filename, "rb", + USE_PATH | REPORT_ERRORS, + NULL); + xdfree(tmp_filename); + + /* Read until the "begin" line has been read */ + if (!stream) { + return NULL; + } + + /* skip to the first requested line */ + while (i > 0 && !php_stream_eof(stream)) { + if (line) { + efree(line); + line = NULL; + } + line = php_stream_gets(stream, NULL, 1024); + i--; + } + /* Read until the "end" line has been read */ + do { + if (line) { + xdebug_str_add(source, line, 0); + efree(line); + line = NULL; + if (php_stream_eof(stream)) break; + } + line = php_stream_gets(stream, NULL, 1024); + i++; + } while (i < end + 1 - begin); + + /* Print last line */ + if (line) { + efree(line); + line = NULL; + } + php_stream_close(stream); + return source; +} + +static xdebug_str* return_eval_source(char *id, int begin, int end) +{ + char *key; + xdebug_str *joined; + xdebug_eval_info *ei; + xdebug_arg *parts; + + if (begin < 0) { + begin = 0; + } + + key = create_eval_key_id(atoi(id)); + + if (!xdebug_hash_find(XG_DBG(context).eval_id_lookup, key, strlen(key), (void *) &ei)) { + return NULL; + } + + parts = xdebug_arg_ctor(); + xdebug_explode("\n", ZSTR_VAL(ei->contents), parts, end + 2); + joined = xdebug_join("\n", parts, begin, end); + xdebug_arg_dtor(parts); + + return joined; +} + +static int is_dbgp_url(zend_string *filename) +{ + return (strncmp(ZSTR_VAL(filename), "dbgp://", 7) == 0); +} + +static xdebug_str* return_source(zend_string *filename, int begin, int end) +{ + if (is_dbgp_url(filename)) { + return return_eval_source(ZSTR_VAL(filename) + 7, begin, end); + } else { + return return_file_source(filename, begin, end); + } +} + + +static int check_evaled_code(zend_string *filename_in, char **filename_out) +{ + char *end_marker; + xdebug_eval_info *ei; + + if (!filename_in) { + return 0; + } + + end_marker = ZSTR_VAL(filename_in) + ZSTR_LEN(filename_in) - strlen("eval()'d code"); + if (end_marker >= ZSTR_VAL(filename_in) && strcmp("eval()'d code", end_marker) == 0) { + if (xdebug_hash_find(XG_DBG(context).eval_id_lookup, ZSTR_VAL(filename_in), ZSTR_LEN(filename_in), (void *) &ei)) { + *filename_out = xdebug_sprintf("dbgp://%lu", ei->id); + return 1; + } + } + return 0; +} + +static xdebug_xml_node* return_stackframe(int nr) +{ + function_stack_entry *fse, *fse_prev; + char *tmp_fname; + char *tmp_filename; + xdebug_xml_node *tmp; + + fse = xdebug_get_stack_frame(nr); + fse_prev = xdebug_get_stack_frame(nr - 1); + + tmp_fname = xdebug_show_fname(fse->function, 0); + + tmp = xdebug_xml_node_init("stack"); + xdebug_xml_add_attribute_ex(tmp, "where", xdstrdup(tmp_fname), 0, 1); + xdebug_xml_add_attribute_ex(tmp, "level", xdebug_sprintf("%ld", nr), 0, 1); + if (fse_prev) { + if (check_evaled_code(fse_prev->filename, &tmp_filename)) { + xdebug_xml_add_attribute_ex(tmp, "type", xdstrdup("eval"), 0, 1); + xdebug_xml_add_attribute_ex(tmp, "filename", tmp_filename, 0, 0); + xdfree(tmp_filename); + } else { + xdebug_xml_add_attribute_ex(tmp, "type", xdstrdup("file"), 0, 1); + xdebug_xml_add_attribute_ex(tmp, "filename", xdebug_path_to_url(fse_prev->filename), 0, 1); + } + xdebug_xml_add_attribute_ex(tmp, "lineno", xdebug_sprintf("%lu", fse_prev->lineno), 0, 1); + } else { + zend_string *executed_filename = zend_get_executed_filename_ex(); + int executed_lineno = zend_get_executed_lineno(); + char *tmp_filename; + + if (check_evaled_code(executed_filename, &tmp_filename)) { + xdebug_xml_add_attribute_ex(tmp, "type", xdstrdup("eval"), 0, 1); + xdebug_xml_add_attribute_ex(tmp, "filename", tmp_filename, 0, 0); + xdfree(tmp_filename); + } else if (executed_filename) { + xdebug_xml_add_attribute_ex(tmp, "type", xdstrdup("file"), 0, 1); + xdebug_xml_add_attribute_ex(tmp, "filename", xdebug_path_to_url(executed_filename), 0, 1); + } + xdebug_xml_add_attribute_ex(tmp, "lineno", xdebug_sprintf("%lu", executed_lineno), 0, 1); + } + + xdfree(tmp_fname); + return tmp; +} + +/***************************************************************************** +** Client command handlers - Breakpoints +*/ + +/* Helper functions */ +static void xdebug_hash_admin_dtor(xdebug_brk_admin *admin) +{ + xdfree(admin->key); + xdfree(admin); +} + +static int breakpoint_admin_add(xdebug_con *context, int type, char *key) +{ + xdebug_brk_admin *admin = xdmalloc(sizeof(xdebug_brk_admin)); + char *hkey; + + XG_DBG(breakpoint_count)++; + admin->id = ((xdebug_get_pid() & 0x1ffff) * 10000) + XG_DBG(breakpoint_count); + admin->type = type; + admin->key = xdstrdup(key); + + hkey = xdebug_sprintf("%lu", admin->id); + xdebug_hash_add(context->breakpoint_list, hkey, strlen(hkey), (void*) admin); + xdfree(hkey); + + return admin->id; +} + +static int breakpoint_admin_fetch(xdebug_con *context, char *hkey, int *type, char **key) +{ + xdebug_brk_admin *admin; + + if (!xdebug_hash_find(context->breakpoint_list, hkey, strlen(hkey), (void *) &admin)) { + return FAILURE; + } + + *type = admin->type; + *key = admin->key; + + return SUCCESS; +} + +static int breakpoint_admin_remove(xdebug_con *context, char *hkey) +{ + if (!xdebug_hash_delete(context->breakpoint_list, hkey, strlen(hkey))) { + return FAILURE; + } + + return SUCCESS; +} + +static void breakpoint_brk_info_add_resolved(xdebug_xml_node *xml, xdebug_brk_info *brk_info) +{ + if (!XG_DBG(context).resolved_breakpoints) { + return; + } + + if (brk_info->resolved == XDEBUG_BRK_RESOLVED) { + xdebug_xml_add_attribute(xml, "resolved", "resolved"); + } else { + xdebug_xml_add_attribute(xml, "resolved", "unresolved"); + } +} + +static void breakpoint_brk_info_add(xdebug_xml_node *xml, xdebug_brk_info *brk_info) +{ + xdebug_xml_add_attribute_ex(xml, "type", xdstrdup(XDEBUG_BREAKPOINT_TYPE_NAME(brk_info->brk_type)), 0, 1); + breakpoint_brk_info_add_resolved(xml, brk_info); + if (brk_info->filename) { + if (is_dbgp_url(brk_info->filename)) { + xdebug_xml_add_attribute_ex(xml, "filename", ZSTR_VAL(brk_info->filename), 0, 0); + } else { + xdebug_xml_add_attribute_ex(xml, "filename", xdebug_path_to_url(brk_info->filename), 0, 1); + } + } + if (brk_info->resolved_lineno) { + xdebug_xml_add_attribute_ex(xml, "lineno", xdebug_sprintf("%lu", brk_info->resolved_lineno), 0, 1); + } + if (brk_info->functionname) { + xdebug_xml_add_attribute_ex(xml, "function", xdstrdup(brk_info->functionname), 0, 1); + } + if (brk_info->classname) { + xdebug_xml_add_attribute_ex(xml, "class", xdstrdup(brk_info->classname), 0, 1); + } + if (brk_info->exceptionname) { + xdebug_xml_add_attribute_ex(xml, "exception", xdstrdup(brk_info->exceptionname), 0, 1); + } + if (brk_info->disabled) { + xdebug_xml_add_attribute(xml, "state", "disabled"); + } else if (brk_info->temporary) { + xdebug_xml_add_attribute(xml, "state", "temporary"); + } else { + xdebug_xml_add_attribute(xml, "state", "enabled"); + } + xdebug_xml_add_attribute_ex(xml, "hit_count", xdebug_sprintf("%lu", brk_info->hit_count), 0, 1); + switch (brk_info->hit_condition) { + case XDEBUG_HIT_GREATER_EQUAL: + xdebug_xml_add_attribute(xml, "hit_condition", ">="); + break; + case XDEBUG_HIT_EQUAL: + xdebug_xml_add_attribute(xml, "hit_condition", "=="); + break; + case XDEBUG_HIT_MOD: + xdebug_xml_add_attribute(xml, "hit_condition", "%"); + break; + } + if (brk_info->condition) { + xdebug_xml_node *condition = xdebug_xml_node_init("expression"); + xdebug_xml_add_text_ex(condition, brk_info->condition, strlen(brk_info->condition), 0, 1); + xdebug_xml_add_child(xml, condition); + } + xdebug_xml_add_attribute_ex(xml, "hit_value", xdebug_sprintf("%lu", brk_info->hit_value), 0, 1); + xdebug_xml_add_attribute_ex(xml, "id", xdebug_sprintf("%lu", brk_info->id), 0, 1); +} + +static xdebug_brk_info* breakpoint_brk_info_fetch(int type, char *hkey) +{ + xdebug_llist_element *le; + xdebug_brk_info *brk_info = NULL; + + switch (type) { + case XDEBUG_BREAKPOINT_TYPE_LINE: + case XDEBUG_BREAKPOINT_TYPE_CONDITIONAL: { + xdebug_arg *parts; + + /* First we split the key into filename and linenumber */ + parts = xdebug_arg_ctor(); + xdebug_explode("$", hkey, parts, -1); + + /* Second we loop through the list of file/line breakpoints to + * look for our thingy */ + for (le = XDEBUG_LLIST_HEAD(XG_DBG(context).line_breakpoints); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { + brk_info = XDEBUG_LLIST_VALP(le); + + if (atoi(parts->args1) == brk_info->original_lineno && memcmp(ZSTR_VAL(brk_info->filename), parts->args0, ZSTR_LEN(brk_info->filename)) == 0) { + xdebug_arg_dtor(parts); + return brk_info; + } + } + + /* Cleaning up */ + xdebug_arg_dtor(parts); + + break; + } + + case XDEBUG_BREAKPOINT_TYPE_CALL: + case XDEBUG_BREAKPOINT_TYPE_RETURN: + if (xdebug_hash_find(XG_DBG(context).function_breakpoints, hkey, strlen(hkey), (void *) &brk_info)) { + return brk_info; + } + break; + + case XDEBUG_BREAKPOINT_TYPE_EXCEPTION: + if (xdebug_hash_find(XG_DBG(context).exception_breakpoints, hkey, strlen(hkey), (void *) &brk_info)) { + return brk_info; + } + break; + } + return brk_info; +} + +static int breakpoint_remove(int type, char *hkey) +{ + xdebug_llist_element *le; + xdebug_brk_info *brk_info = NULL; + int retval = FAILURE; + + switch (type) { + case XDEBUG_BREAKPOINT_TYPE_LINE: + case XDEBUG_BREAKPOINT_TYPE_CONDITIONAL: { + xdebug_arg *parts; + + /* First we split the key into filename and linenumber */ + parts = xdebug_arg_ctor(); + xdebug_explode("$", hkey, parts, -1); + + /* Second we loop through the list of file/line breakpoints to + * look for our thingy */ + for (le = XDEBUG_LLIST_HEAD(XG_DBG(context).line_breakpoints); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { + brk_info = XDEBUG_LLIST_VALP(le); + + if (atoi(parts->args1) == brk_info->original_lineno && memcmp(ZSTR_VAL(brk_info->filename), parts->args0, ZSTR_LEN(brk_info->filename)) == 0) { + xdebug_llist_remove(XG_DBG(context).line_breakpoints, le, NULL); + retval = SUCCESS; + break; + } + } + + /* Cleaning up */ + xdebug_arg_dtor(parts); + break; + } + + case XDEBUG_BREAKPOINT_TYPE_CALL: + case XDEBUG_BREAKPOINT_TYPE_RETURN: + if (xdebug_hash_delete(XG_DBG(context).function_breakpoints, hkey, strlen(hkey))) { + retval = SUCCESS; + } + break; + + case XDEBUG_BREAKPOINT_TYPE_EXCEPTION: + if (xdebug_hash_delete(XG_DBG(context).exception_breakpoints, hkey, strlen(hkey))) { + retval = SUCCESS; + } + break; + } + return retval; +} + +#define BREAKPOINT_ACTION_GET 1 +#define BREAKPOINT_ACTION_REMOVE 2 +#define BREAKPOINT_ACTION_UPDATE 3 + +#define BREAKPOINT_CHANGE_STATE() \ + XDEBUG_STR_SWITCH(CMD_OPTION_CHAR('s')) { \ + XDEBUG_STR_CASE("enabled") \ + brk_info->disabled = 0; \ + XDEBUG_STR_CASE_END \ + \ + XDEBUG_STR_CASE("disabled") \ + brk_info->disabled = 1; \ + XDEBUG_STR_CASE_END \ + \ + XDEBUG_STR_CASE_DEFAULT \ + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); \ + XDEBUG_STR_CASE_DEFAULT_END \ + } + +#define BREAKPOINT_CHANGE_OPERATOR() \ + XDEBUG_STR_SWITCH(CMD_OPTION_CHAR('o')) { \ + XDEBUG_STR_CASE(">=") \ + brk_info->hit_condition = XDEBUG_HIT_GREATER_EQUAL; \ + XDEBUG_STR_CASE_END \ + \ + XDEBUG_STR_CASE("==") \ + brk_info->hit_condition = XDEBUG_HIT_EQUAL; \ + XDEBUG_STR_CASE_END \ + \ + XDEBUG_STR_CASE("%") \ + brk_info->hit_condition = XDEBUG_HIT_MOD; \ + XDEBUG_STR_CASE_END \ + \ + XDEBUG_STR_CASE_DEFAULT \ + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); \ + XDEBUG_STR_CASE_DEFAULT_END \ + } + + + +static void breakpoint_do_action(DBGP_FUNC_PARAMETERS, int action) +{ + int type; + char *hkey; + xdebug_brk_info *brk_info; + xdebug_xml_node *breakpoint_node; + XDEBUG_STR_SWITCH_DECL; + + if (!CMD_OPTION_SET('d')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + + /* Lets check if it exists */ + if (breakpoint_admin_fetch(context, CMD_OPTION_CHAR('d'), &type, (char**) &hkey) == FAILURE) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_NO_SUCH_BREAKPOINT) + } + + /* so it exists, now we're going to find it in the correct hash/list + * and return the info we have on it */ + brk_info = breakpoint_brk_info_fetch(type, hkey); + + if (action == BREAKPOINT_ACTION_UPDATE) { + if (CMD_OPTION_SET('s')) { + BREAKPOINT_CHANGE_STATE(); + } + if (CMD_OPTION_SET('n')) { + brk_info->original_lineno = strtol(CMD_OPTION_CHAR('n'), NULL, 10); + brk_info->resolved_lineno = brk_info->original_lineno; + } + if (CMD_OPTION_SET('h')) { + brk_info->hit_value = strtol(CMD_OPTION_CHAR('h'), NULL, 10); + } + if (CMD_OPTION_SET('o')) { + BREAKPOINT_CHANGE_OPERATOR(); + } + } + + breakpoint_node = xdebug_xml_node_init("breakpoint"); + breakpoint_brk_info_add(breakpoint_node, brk_info); + xdebug_xml_add_child(*retval, breakpoint_node); + + if (action == BREAKPOINT_ACTION_REMOVE) { + /* Now we remove the crap */ + breakpoint_remove(type, hkey); + breakpoint_admin_remove(context, CMD_OPTION_CHAR('d')); + } +} + +DBGP_FUNC(breakpoint_get) +{ + breakpoint_do_action(DBGP_FUNC_PASS_PARAMETERS, BREAKPOINT_ACTION_GET); +} + +DBGP_FUNC(breakpoint_remove) +{ + breakpoint_do_action(DBGP_FUNC_PASS_PARAMETERS, BREAKPOINT_ACTION_REMOVE); +} + +DBGP_FUNC(breakpoint_update) +{ + breakpoint_do_action(DBGP_FUNC_PASS_PARAMETERS, BREAKPOINT_ACTION_UPDATE); +} + +static void breakpoint_exists_helper(void *retval, xdebug_hash_element *he, void *key_to_match) +{ + int *line_found = (int *) retval; + + xdebug_brk_admin *admin = (xdebug_brk_admin*) he->ptr; + + if (strcmp(admin->key, (const char*) key_to_match) == 0) { + *line_found = 1; + } +} + +static int line_breakpoint_exists(xdebug_con *context, const char *key) +{ + int line_found = 0; + + xdebug_hash_apply_with_argument(context->breakpoint_list, (void *) &line_found, breakpoint_exists_helper, (void*) key); + + return line_found; +} + +static void breakpoint_list_helper(void *xml, xdebug_hash_element *he, void *dummy) +{ + xdebug_xml_node *xml_node = (xdebug_xml_node*) xml; + xdebug_xml_node *child; + xdebug_brk_admin *admin = (xdebug_brk_admin*) he->ptr; + xdebug_brk_info *brk_info; + + child = xdebug_xml_node_init("breakpoint"); + brk_info = breakpoint_brk_info_fetch(admin->type, admin->key); + breakpoint_brk_info_add(child, brk_info); + xdebug_xml_add_child(xml_node, child); +} + +DBGP_FUNC(breakpoint_list) +{ + xdebug_hash_apply_with_argument(context->breakpoint_list, (void *) *retval, breakpoint_list_helper, NULL); +} + +static void warn_if_breakpoint_file_does_not_exist(xdebug_brk_info *brk_info) +{ +#ifndef WIN32 + if (brk_info && brk_info->filename && strstr(ZSTR_VAL(brk_info->filename), "://") == NULL) { + struct stat buf; + + if (stat(ZSTR_VAL(brk_info->filename), &buf) != 0) { + xdebug_log_ex( + XLOG_CHAN_DEBUG, XLOG_WARN, + "BRKFILE", + "Breakpoint file name does not exist: %s (%s).", ZSTR_VAL(brk_info->filename), strerror(errno) + ); + } + } +#endif +} + +DBGP_FUNC(breakpoint_set) +{ + xdebug_brk_info *brk_info; + XDEBUG_STR_SWITCH_DECL; + + brk_info = xdebug_brk_info_ctor(); + + if (!CMD_OPTION_SET('t')) { + xdebug_brk_info_dtor(brk_info); + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } else { + int i; + int found = 0; + + for (i = 0; i < XDEBUG_BREAKPOINT_TYPES_COUNT; i++) { + if (strcmp(xdebug_breakpoint_typesi.name, CMD_OPTION_CHAR('t')) == 0) { + brk_info->brk_type = xdebug_breakpoint_typesi.value; + found = 1; + break; + } + } + + if (!found) { + xdebug_brk_info_dtor(brk_info); + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + } + + if (CMD_OPTION_SET('s')) { + BREAKPOINT_CHANGE_STATE(); + xdebug_xml_add_attribute_ex(*retval, "state", xdstrdup(CMD_OPTION_CHAR('s')), 0, 1); + } + if (CMD_OPTION_SET('o') && CMD_OPTION_SET('h')) { + BREAKPOINT_CHANGE_OPERATOR(); + brk_info->hit_value = strtol(CMD_OPTION_CHAR('h'), NULL, 10); + } + if (CMD_OPTION_SET('r')) { + brk_info->temporary = strtol(CMD_OPTION_CHAR('r'), NULL, 10); + } + + if ((strcmp(CMD_OPTION_CHAR('t'), "line") == 0) || (strcmp(CMD_OPTION_CHAR('t'), "conditional") == 0)) { + size_t new_length = 0; + char *tmp_name; + + if (!CMD_OPTION_SET('n')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + brk_info->original_lineno = strtol(CMD_OPTION_CHAR('n'), NULL, 10); + brk_info->resolved_lineno = brk_info->original_lineno; + + /* If no filename is given, we use the current one */ + if (!CMD_OPTION_SET('f')) { + function_stack_entry *fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + + if (!fse) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); + } else { + char *tmp_path = xdebug_path_from_url(fse->filename); + brk_info->filename = zend_string_init(tmp_path, strlen(tmp_path), 0); + } + } else { + char realpath_fileMAXPATHLEN; + zend_string *tmp_f = zend_string_init(CMD_OPTION_CHAR('f'), CMD_OPTION_LEN('f'), 0); + char *tmp_path = xdebug_path_from_url(tmp_f); + + brk_info->filename = zend_string_init(tmp_path, strlen(tmp_path), 0); + + /* Now we do some real path checks to resolve symlinks. */ + if (VCWD_REALPATH(ZSTR_VAL(brk_info->filename), realpath_file)) { + zend_string_release(brk_info->filename); + brk_info->filename = zend_string_init(realpath_file, strlen(realpath_file), 0); + } + + zend_string_release(tmp_f); + xdfree(tmp_path); + } + + warn_if_breakpoint_file_does_not_exist(brk_info); + + /* Perhaps we have a break condition */ + if (CMD_OPTION_SET('-')) { + brk_info->condition = (char*) xdebug_base64_decode((unsigned char*) CMD_OPTION_CHAR('-'), CMD_OPTION_LEN('-'), &new_length); + } + + tmp_name = xdebug_sprintf("%s$%lu", ZSTR_VAL(brk_info->filename), brk_info->original_lineno); + + if (line_breakpoint_exists(context, tmp_name)) { + xdfree(tmp_name); + + xdebug_brk_info_dtor(brk_info); + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_BREAKPOINT_NOT_SET); + } + + if (strcmp(CMD_OPTION_CHAR('t'), "line") == 0) { + brk_info->id = breakpoint_admin_add(context, XDEBUG_BREAKPOINT_TYPE_LINE, tmp_name); + } else { + brk_info->id = breakpoint_admin_add(context, XDEBUG_BREAKPOINT_TYPE_CONDITIONAL, tmp_name); + } + xdfree(tmp_name); + xdebug_llist_insert_next(context->line_breakpoints, XDEBUG_LLIST_TAIL(context->line_breakpoints), (void*) brk_info); + + if (XG_DBG(context).resolved_breakpoints) { + xdebug_lines_list *lines_list; + + if (xdebug_hash_find(XG_DBG(breakable_lines_map), ZSTR_VAL(brk_info->filename), ZSTR_LEN(brk_info->filename), (void *) &lines_list)) { + line_breakpoint_resolve_helper(context, lines_list, brk_info); + } + } + } else + + if ((strcmp(CMD_OPTION_CHAR('t'), "call") == 0) || (strcmp(CMD_OPTION_CHAR('t'), "return") == 0)) { + void *dummy = NULL; + char *tmp_name; + + if (strcmp(CMD_OPTION_CHAR('t'), "call") == 0) { + brk_info->function_break_type = XDEBUG_BREAKPOINT_TYPE_CALL; + } else { + brk_info->function_break_type = XDEBUG_BREAKPOINT_TYPE_RETURN; + } + + if (!CMD_OPTION_SET('m')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + brk_info->functionname = xdstrdup(CMD_OPTION_CHAR('m')); + + if (CMD_OPTION_SET('a')) { + brk_info->classname = xdstrdup(CMD_OPTION_CHAR('a')); + tmp_name = xdebug_sprintf( + "%c/%s::%s", + (brk_info->function_break_type & XDEBUG_BREAKPOINT_TYPE_CALL) ? 'C' : 'R', + CMD_OPTION_CHAR('a'), CMD_OPTION_CHAR('m') + ); + } else { + tmp_name = xdebug_sprintf( + "%c/%s", + (brk_info->function_break_type & XDEBUG_BREAKPOINT_TYPE_CALL) ? 'C' : 'R', + CMD_OPTION_CHAR('m') + ); + } + + if (xdebug_hash_find(context->function_breakpoints, tmp_name, strlen(tmp_name), (void*) &dummy)) { + xdfree(tmp_name); + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_BREAKPOINT_NOT_SET); + } + + if (!xdebug_hash_add(context->function_breakpoints, tmp_name, strlen(tmp_name), brk_info)) { + xdfree(tmp_name); + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_BREAKPOINT_NOT_SET); + } else { + if (brk_info->function_break_type & XDEBUG_BREAKPOINT_TYPE_CALL) { + brk_info->id = breakpoint_admin_add(context, XDEBUG_BREAKPOINT_TYPE_CALL, tmp_name); + } else { + brk_info->id = breakpoint_admin_add(context, XDEBUG_BREAKPOINT_TYPE_RETURN, tmp_name); + } + } + + brk_info->resolved = XDEBUG_BRK_RESOLVED; + + xdfree(tmp_name); + } else + + if (strcmp(CMD_OPTION_CHAR('t'), "exception") == 0) { + if (!CMD_OPTION_SET('x')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + brk_info->exceptionname = xdstrdup(CMD_OPTION_CHAR('x')); + if (!xdebug_hash_add(context->exception_breakpoints, CMD_OPTION_CHAR('x'), CMD_OPTION_LEN('x'), (void*) brk_info)) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_BREAKPOINT_NOT_SET); + } else { + brk_info->id = breakpoint_admin_add(context, XDEBUG_BREAKPOINT_TYPE_EXCEPTION, CMD_OPTION_CHAR('x')); + } + + brk_info->resolved = XDEBUG_BRK_RESOLVED; + } else + + if (strcmp(CMD_OPTION_CHAR('t'), "watch") == 0) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_BREAKPOINT_TYPE_NOT_SUPPORTED); + } + + xdebug_xml_add_attribute_ex(*retval, "id", xdebug_sprintf("%lu", brk_info->id), 0, 1); + breakpoint_brk_info_add_resolved(*retval, brk_info); +} + +DBGP_FUNC(eval) +{ + char *eval_string; + xdebug_xml_node *ret_xml; + zval ret_zval; + size_t new_length = 0; + int res; + xdebug_var_export_options *options; + + if (!CMD_OPTION_SET('-')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + + options = (xdebug_var_export_options*) context->options; + + if (CMD_OPTION_SET('p')) { + options->runtime0.page = strtol(CMD_OPTION_CHAR('p'), NULL, 10); + } else { + options->runtime0.page = 0; + } + + /* base64 decode eval string */ + eval_string = (char*) xdebug_base64_decode((unsigned char*) CMD_OPTION_CHAR('-'), CMD_OPTION_LEN('-'), &new_length); + + res = xdebug_do_eval(eval_string, &ret_zval); + + xdfree(eval_string); + + /* Handle result */ + if (!res) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_EVALUATING_CODE); + } else { + ret_xml = xdebug_get_zval_value_xml_node(NULL, &ret_zval, options); + xdebug_xml_add_child(*retval, ret_xml); + zval_ptr_dtor(&ret_zval); + } +} + +/* these functions interupt PHP's output functions, so we can + redirect to our remote debugger! */ +static void xdebug_send_stream(const char *name, const char *str, unsigned int str_length) +{ + /* create an xml document to send as the stream */ + xdebug_xml_node *message; + + if (!xdebug_is_debug_connection_active()) { + return; + } + + message = xdebug_xml_node_init("stream"); + xdebug_xml_add_attribute(message, "xmlns", "urn:debugger_protocol_v1"); + xdebug_xml_add_attribute(message, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); + xdebug_xml_add_attribute_ex(message, "type", (char *)name, 0, 0); + xdebug_xml_add_text_encodel(message, xdstrndup(str, str_length), str_length); + send_message(&XG_DBG(context), message); + xdebug_xml_node_dtor(message); + + return; +} + + +DBGP_FUNC(stderr) +{ + xdebug_xml_add_attribute(*retval, "success", "0"); +} + +DBGP_FUNC(stdout) +{ + int mode = 0; + const char *success = "0"; + + if (!CMD_OPTION_SET('c')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + + mode = strtol(CMD_OPTION_CHAR('c'), NULL, 10); + XG_DBG(stdout_mode) = mode; + success = "1"; + + xdebug_xml_add_attribute_ex(*retval, "success", xdstrdup(success), 0, 1); +} + +DBGP_FUNC(stop) +{ + XG_DBG(status) = DBGP_STATUS_STOPPED; + xdebug_xml_add_attribute(*retval, "status", xdebug_dbgp_status_stringsXG_DBG(status)); + xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason)); +} + +DBGP_FUNC(run) +{ + xdebug_xml_add_attribute_ex(*retval, "filename", ZSTR_VAL(context->program_name), 0, 0); +} + +DBGP_FUNC(step_into) +{ + XG_DBG(context).do_next = 0; + XG_DBG(context).do_step = 1; + XG_DBG(context).do_finish = 0; +} + +DBGP_FUNC(step_out) +{ + function_stack_entry *fse; + + XG_DBG(context).do_next = 0; + XG_DBG(context).do_step = 0; + XG_DBG(context).do_finish = 1; + + if ((fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)))) { + XG_DBG(context).finish_level = fse->level; + XG_DBG(context).finish_func_nr = fse->function_nr; + } else { + XG_DBG(context).finish_level = -1; + XG_DBG(context).finish_func_nr = -1; + } +} + +DBGP_FUNC(step_over) +{ + function_stack_entry *fse; + + XG_DBG(context).do_next = 1; + XG_DBG(context).do_step = 0; + XG_DBG(context).do_finish = 0; + + if ((fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)))) { + XG_DBG(context).next_level = fse->level; + } else { + XG_DBG(context).next_level = 0; + } +} + +DBGP_FUNC(detach) +{ + XG_DBG(status) = DBGP_STATUS_DETACHED; + + xdebug_xml_add_attribute(*retval, "status", xdebug_dbgp_status_stringsDBGP_STATUS_STOPPED); + xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason)); + XG_DBG(context).handler->remote_deinit(&(XG_DBG(context))); + xdebug_mark_debug_connection_not_active(); + XG_DBG(stdout_mode) = 0; + XG_DBG(detached) = 1; + + if (CMD_OPTION_SET('-')) { + XG_DBG(context).detached_message = xdstrdup(CMD_OPTION_CHAR('-')); + xdebug_log_ex(XLOG_CHAN_DEBUG, XLOG_WARN, "DETACH", "Debug client detached: %s.", XG_DBG(context).detached_message); + } +} + + +DBGP_FUNC(source) +{ + xdebug_str *source; + int begin = 0, end = 999999; + zend_string *filename; + function_stack_entry *fse; + + if (!CMD_OPTION_SET('f')) { + if ((fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)))) { + filename = zend_string_copy(fse->filename); + } else { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); + } + } else { + filename = zend_string_init(CMD_OPTION_CHAR('f'), CMD_OPTION_LEN('f'), 0); + } + + if (CMD_OPTION_SET('b')) { + begin = strtol(CMD_OPTION_CHAR('b'), NULL, 10); + } + if (CMD_OPTION_SET('e')) { + end = strtol(CMD_OPTION_CHAR('e'), NULL, 10); + } + + /* return_source allocates memory for source */ + XG_DBG(breakpoints_allowed) = 0; + source = return_source(filename, begin, end); + XG_DBG(breakpoints_allowed) = 1; + + zend_string_release(filename); + + if (!source) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_CANT_OPEN_FILE); + } else { + xdebug_xml_add_text_ex(*retval, xdstrdup(source->d), source->l, 1, 1); + xdebug_str_free(source); + } +} + +DBGP_FUNC(feature_get) +{ + xdebug_var_export_options *options; + XDEBUG_STR_SWITCH_DECL; + + options = (xdebug_var_export_options*) context->options; + + if (!CMD_OPTION_SET('n')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + xdebug_xml_add_attribute_ex(*retval, "feature_name", xdstrdup(CMD_OPTION_CHAR('n')), 0, 1); + + XDEBUG_STR_SWITCH(CMD_OPTION_CHAR('n')) { + XDEBUG_STR_CASE("breakpoint_languages") + xdebug_xml_add_attribute(*retval, "supported", "0"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("breakpoint_types") + xdebug_xml_add_text(*retval, xdstrdup("line conditional call return exception")); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("data_encoding") + xdebug_xml_add_attribute(*retval, "supported", "0"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("encoding") + xdebug_xml_add_text(*retval, xdstrdup("iso-8859-1")); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("language_name") + xdebug_xml_add_text(*retval, xdstrdup("PHP")); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("language_supports_threads") + xdebug_xml_add_text(*retval, xdstrdup("0")); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("language_version") + xdebug_xml_add_text(*retval, xdstrdup(XG_BASE(php_version_run_time))); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("max_children") + xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", options->max_children)); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("max_data") + xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", options->max_data)); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("max_depth") + xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", options->max_depth)); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("protocol_version") + xdebug_xml_add_text(*retval, xdstrdup(DBGP_VERSION)); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("supported_encodings") + xdebug_xml_add_text(*retval, xdstrdup("iso-8859-1")); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("supports_async") + xdebug_xml_add_text(*retval, xdstrdup("0")); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("supports_postmortem") + xdebug_xml_add_text(*retval, xdstrdup("1")); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("show_hidden") + xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", options->show_hidden)); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("extended_properties") + xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", options->extended_properties)); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("notify_ok") + xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", XG_DBG(context).send_notifications)); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("resolved_breakpoints") + xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", XG_DBG(context).resolved_breakpoints)); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("breakpoint_details") + xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", XG_DBG(context).breakpoint_details)); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("breakpoint_include_return_value") + xdebug_xml_add_text(*retval, xdebug_sprintf("%ld", XG_DBG(context).breakpoint_include_return_value)); + xdebug_xml_add_attribute(*retval, "supported", "1"); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE_DEFAULT + xdebug_xml_add_text(*retval, xdstrdup(lookup_cmd(CMD_OPTION_CHAR('n')) ? "1" : "0")); + xdebug_xml_add_attribute(*retval, "supported", lookup_cmd(CMD_OPTION_CHAR('n')) ? "1" : "0"); + XDEBUG_STR_CASE_DEFAULT_END + } +} + +DBGP_FUNC(feature_set) +{ + xdebug_var_export_options *options; + XDEBUG_STR_SWITCH_DECL; + + options = (xdebug_var_export_options*) context->options; + + if (!CMD_OPTION_SET('n') || !CMD_OPTION_SET('v')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + + XDEBUG_STR_SWITCH(CMD_OPTION_CHAR('n')) { + + XDEBUG_STR_CASE("encoding") + if (strcmp(CMD_OPTION_CHAR('v'), "iso-8859-1") != 0) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_ENCODING_NOT_SUPPORTED); + } + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("max_children") + options->max_children = strtol(CMD_OPTION_CHAR('v'), NULL, 10); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("max_data") + options->max_data = strtol(CMD_OPTION_CHAR('v'), NULL, 10); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("max_depth") + int i; + options->max_depth = strtol(CMD_OPTION_CHAR('v'), NULL, 10); + + /* Reallocating page structure */ + xdfree(options->runtime); + options->runtime = (xdebug_var_runtime_page*) xdmalloc(options->max_depth * sizeof(xdebug_var_runtime_page)); + for (i = 0; i < options->max_depth; i++) { + options->runtimei.page = 0; + options->runtimei.current_element_nr = 0; + } + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("show_hidden") + options->show_hidden = strtol(CMD_OPTION_CHAR('v'), NULL, 10); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("multiple_sessions") + /* FIXME: Add new boolean option check / struct field for this */ + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("extended_properties") + options->extended_properties = strtol(CMD_OPTION_CHAR('v'), NULL, 10); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("notify_ok") + XG_DBG(context).send_notifications = strtol(CMD_OPTION_CHAR('v'), NULL, 10); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("resolved_breakpoints") + XG_DBG(context).resolved_breakpoints = strtol(CMD_OPTION_CHAR('v'), NULL, 10); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("breakpoint_details") + XG_DBG(context).breakpoint_details = strtol(CMD_OPTION_CHAR('v'), NULL, 10); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("breakpoint_include_return_value") + XG_DBG(context).breakpoint_include_return_value = strtol(CMD_OPTION_CHAR('v'), NULL, 10); + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE_DEFAULT + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + XDEBUG_STR_CASE_DEFAULT_END + } + xdebug_xml_add_attribute_ex(*retval, "feature", xdstrdup(CMD_OPTION_CHAR('n')), 0, 1); + xdebug_xml_add_attribute_ex(*retval, "success", "1", 0, 0); +} + +DBGP_FUNC(typemap_get) +{ + int i; + xdebug_xml_node *type; + + xdebug_xml_add_attribute(*retval, "xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); + xdebug_xml_add_attribute(*retval, "xmlns:xsd", "http://www.w3.org/2001/XMLSchema"); + + /* Add our basic types */ + for (i = 0; i < XDEBUG_TYPES_COUNT; i++) { + type = xdebug_xml_node_init("map"); + xdebug_xml_add_attribute(type, "name", xdebug_dbgp_typemapi1); + xdebug_xml_add_attribute(type, "type", xdebug_dbgp_typemapi0); + if (xdebug_dbgp_typemapi2) { + xdebug_xml_add_attribute(type, "xsi:type", xdebug_dbgp_typemapi2); + } + xdebug_xml_add_child(*retval, type); + } +} + +static int add_constant_node(xdebug_xml_node *node, xdebug_str *name, zval *const_val, xdebug_var_export_options *options) +{ + xdebug_xml_node *contents; + + contents = xdebug_get_zval_value_xml_node_ex(name, const_val, XDEBUG_VAR_TYPE_CONSTANT, options); + if (!contents) { + return FAILURE; + } + + xdebug_xml_expand_attribute_value(contents, "facet", "constant"); + xdebug_xml_add_child(node, contents); + + return SUCCESS; +} + +static int add_variable_node(xdebug_xml_node *node, xdebug_str *name, int var_only, int non_null, int no_eval, xdebug_var_export_options *options) +{ + xdebug_xml_node *contents; + + contents = get_symbol(name, options); + if (!contents) { + return FAILURE; + } + + xdebug_xml_add_child(node, contents); + + return SUCCESS; +} + +static int xdebug_get_constant(xdebug_str *val, zval *const_val) +{ + zval *tmp_const = NULL; + tmp_const = zend_get_constant_str(val->d, val->l); + + if (!tmp_const) { + return 0; + } + + *const_val = *tmp_const; + + return 1; +} + +DBGP_FUNC(property_get) +{ + int depth = 0; + int context_nr = 0; + function_stack_entry *fse; + int old_max_data; + xdebug_var_export_options *options = (xdebug_var_export_options*) context->options; + + if (!CMD_OPTION_SET('n')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + + if (CMD_OPTION_SET('d')) { + depth = strtol(CMD_OPTION_CHAR('d'), NULL, 10); + } + + if (CMD_OPTION_SET('c')) { + context_nr = strtol(CMD_OPTION_CHAR('c'), NULL, 10); + } + + /* Set the symbol table corresponding with the requested stack depth */ + if (context_nr == 0) { /* locals */ + if ((fse = xdebug_get_stack_frame(depth))) { + function_stack_entry *old_fse; + + if (!fse->user_defined) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTENT); + } + + old_fse = xdebug_get_stack_frame(depth - 1); + + if (depth > 0) { + xdebug_lib_set_active_data(old_fse->execute_data); + } else { + xdebug_lib_set_active_data(EG(current_execute_data)); + } + xdebug_lib_set_active_stack_entry(fse); + xdebug_lib_set_active_symbol_table(fse->symbol_table); + } else { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); + } + } else if (context_nr == 1) { /* superglobals */ + xdebug_lib_set_active_symbol_table(&EG(symbol_table)); + } else if (context_nr == 2) { /* constants */ + /* Do nothing */ + } else { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + + if (CMD_OPTION_SET('p')) { + options->runtime0.page = strtol(CMD_OPTION_CHAR('p'), NULL, 10); + } else { + options->runtime0.page = 0; + } + + /* Override max data size if necessary */ + old_max_data = options->max_data; + if (CMD_OPTION_SET('m')) { + options->max_data= strtol(CMD_OPTION_CHAR('m'), NULL, 10); + } + + if (context_nr == 2) { /* constants */ + zval const_val; + + if (!xdebug_get_constant(CMD_OPTION_XDEBUG_STR('n'), &const_val)) { + options->max_data = old_max_data; + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTENT); + } + if (add_constant_node(*retval, CMD_OPTION_XDEBUG_STR('n'), &const_val, options) == FAILURE) { + options->max_data = old_max_data; + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTENT); + } + } else { + int add_var_retval; + + XG_DBG(context).inhibit_notifications = 1; + add_var_retval = add_variable_node(*retval, CMD_OPTION_XDEBUG_STR('n'), 1, 0, 0, options); + XG_DBG(context).inhibit_notifications = 0; + + if (add_var_retval == FAILURE) { + options->max_data = old_max_data; + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTENT); + } + } + options->max_data = old_max_data; +} + +DBGP_FUNC(property_set) +{ + unsigned char *new_value; + size_t new_length = 0; + int depth = 0; + int context_nr = 0; + int res; + char *eval_string; + const char *cast_as; + zval ret_zval; + function_stack_entry *fse; + xdebug_var_export_options *options = (xdebug_var_export_options*) context->options; + zend_execute_data *original_execute_data; + XDEBUG_STR_SWITCH_DECL; + + if (!CMD_OPTION_SET('n')) { /* name */ + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + + if (!CMD_OPTION_SET('-')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + + if (CMD_OPTION_SET('d')) { /* depth */ + depth = strtol(CMD_OPTION_CHAR('d'), NULL, 10); + } + + if (CMD_OPTION_SET('c')) { /* context_id */ + context_nr = strtol(CMD_OPTION_CHAR('c'), NULL, 10); + } + + /* Set the symbol table corresponding with the requested stack depth */ + if (context_nr == 0) { /* locals */ + if ((fse = xdebug_get_stack_frame(depth))) { + function_stack_entry *old_fse = xdebug_get_stack_frame(depth - 1); + + if (depth > 0) { + xdebug_lib_set_active_data(old_fse->execute_data); + } else { + xdebug_lib_set_active_data(EG(current_execute_data)); + } + xdebug_lib_set_active_stack_entry(fse); + xdebug_lib_set_active_symbol_table(fse->symbol_table); + } else { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); + } + } else { /* superglobals */ + xdebug_lib_set_active_symbol_table(&EG(symbol_table)); + } + + if (CMD_OPTION_SET('p')) { + options->runtime0.page = strtol(CMD_OPTION_CHAR('p'), NULL, 10); + } else { + options->runtime0.page = 0; + } + + new_value = xdebug_base64_decode((unsigned char*) CMD_OPTION_CHAR('-'), CMD_OPTION_LEN('-'), &new_length); + + /* Set a cast, if requested through the 't' option */ + cast_as = ""; + + if (CMD_OPTION_SET('t')) { + XDEBUG_STR_SWITCH(CMD_OPTION_CHAR('t')) { + XDEBUG_STR_CASE("bool") + cast_as = "(bool) "; + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("int") + cast_as = "(int) "; + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("float") + cast_as = "(float) "; + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE("string") + cast_as = "(string) "; + XDEBUG_STR_CASE_END + + XDEBUG_STR_CASE_DEFAULT + xdebug_xml_add_attribute(*retval, "success", "0"); + XDEBUG_STR_CASE_DEFAULT_END + } + } + + /* backup executor state */ + if (depth > 0) { + original_execute_data = EG(current_execute_data); + + EG(current_execute_data) = xdebug_lib_get_active_data(); + } + + /* Do the eval */ + eval_string = xdebug_sprintf("%s = %s %s", CMD_OPTION_CHAR('n'), cast_as, new_value); + res = xdebug_do_eval(eval_string, &ret_zval); + + /* restore executor state */ + if (depth > 0) { + EG(current_execute_data) = original_execute_data; + } + + /* Free data */ + xdfree(eval_string); + xdfree(new_value); + + /* Handle result */ + if (!res) { + /* don't send an error, send success = zero */ + xdebug_xml_add_attribute(*retval, "success", "0"); + } else { + zval_dtor(&ret_zval); + xdebug_xml_add_attribute(*retval, "success", "1"); + } +} + +static int add_variable_contents_node(xdebug_xml_node *node, xdebug_str *name, int var_only, int non_null, int no_eval, xdebug_var_export_options *options) +{ + int contents_found; + + contents_found = get_symbol_contents(name, node, options); + + if (!contents_found) { + return FAILURE; + } + + return SUCCESS; +} + +DBGP_FUNC(property_value) +{ + int depth = 0; + int context_nr = 0; + function_stack_entry *fse; + int old_max_data; + xdebug_var_export_options *options = (xdebug_var_export_options*) context->options; + + if (!CMD_OPTION_SET('n')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + + if (CMD_OPTION_SET('d')) { + depth = strtol(CMD_OPTION_CHAR('d'), NULL, 10); + } + + if (CMD_OPTION_SET('c')) { + context_nr = strtol(CMD_OPTION_CHAR('c'), NULL, 10); + } + + /* Set the symbol table corresponding with the requested stack depth */ + if (context_nr == 0) { /* locals */ + if ((fse = xdebug_get_stack_frame(depth))) { + function_stack_entry *old_fse = xdebug_get_stack_frame(depth - 1); + + if (depth > 0) { + xdebug_lib_set_active_data(old_fse->execute_data); + } else { + xdebug_lib_set_active_data(EG(current_execute_data)); + } + xdebug_lib_set_active_stack_entry(fse); + xdebug_lib_set_active_symbol_table(fse->symbol_table); + } else { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); + } + } else { /* superglobals */ + xdebug_lib_set_active_symbol_table(&EG(symbol_table)); + } + + if (CMD_OPTION_SET('p')) { + options->runtime0.page = strtol(CMD_OPTION_CHAR('p'), NULL, 10); + } else { + options->runtime0.page = 0; + } + + /* Override max data size if necessary */ + old_max_data = options->max_data; + if (CMD_OPTION_SET('m')) { + options->max_data = strtol(CMD_OPTION_CHAR('m'), NULL, 10); + } + if (options->max_data < 0) { + options->max_data = old_max_data; + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + if (add_variable_contents_node(*retval, CMD_OPTION_XDEBUG_STR('n'), 1, 0, 0, options) == FAILURE) { + options->max_data = old_max_data; + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTENT); + } + options->max_data = old_max_data; +} + +static void attach_declared_var_with_contents(void *xml, xdebug_hash_element* he, void *options) +{ + xdebug_str *name = (xdebug_str*) he->ptr; + xdebug_xml_node *node = (xdebug_xml_node *) xml; + xdebug_xml_node *contents; + + contents = get_symbol(name, options); + if (!contents) { + xdebug_var_xml_attach_uninitialized_var(options, node, name); + return; + } + + xdebug_xml_add_child(node, contents); +} + +static int xdebug_add_filtered_symboltable_var(zval *symbol, int num_args, va_list args, zend_hash_key *hash_key) +{ + xdebug_hash *tmp_hash; + + tmp_hash = va_arg(args, xdebug_hash *); + + /* We really ought to deal properly with non-associate keys for symbol + * tables, but for now, we'll just ignore them. */ + if (!hash_key->key) { return 0; } + + if (hash_key->key->val0 == '\0') { return 0; } + + if (strcmp("argc", hash_key->key->val) == 0) { return 0; } + if (strcmp("argv", hash_key->key->val) == 0) { return 0; } + if (hash_key->key->val0 == '_') { + if (strcmp("_COOKIE", hash_key->key->val) == 0) { return 0; } + if (strcmp("_ENV", hash_key->key->val) == 0) { return 0; } + if (strcmp("_FILES", hash_key->key->val) == 0) { return 0; } + if (strcmp("_GET", hash_key->key->val) == 0) { return 0; } + if (strcmp("_POST", hash_key->key->val) == 0) { return 0; } + if (strcmp("_REQUEST", hash_key->key->val) == 0) { return 0; } + if (strcmp("_SERVER", hash_key->key->val) == 0) { return 0; } + if (strcmp("_SESSION", hash_key->key->val) == 0) { return 0; } + } + if (hash_key->key->val0 == 'H') { + if (strcmp("HTTP_COOKIE_VARS", hash_key->key->val) == 0) { return 0; } + if (strcmp("HTTP_ENV_VARS", hash_key->key->val) == 0) { return 0; } + if (strcmp("HTTP_GET_VARS", hash_key->key->val) == 0) { return 0; } + if (strcmp("HTTP_POST_VARS", hash_key->key->val) == 0) { return 0; } + if (strcmp("HTTP_POST_FILES", hash_key->key->val) == 0) { return 0; } + if (strcmp("HTTP_RAW_POST_DATA", hash_key->key->val) == 0) { return 0; } + if (strcmp("HTTP_SERVER_VARS", hash_key->key->val) == 0) { return 0; } + if (strcmp("HTTP_SESSION_VARS", hash_key->key->val) == 0) { return 0; } + } + if (strcmp("GLOBALS", hash_key->key->val) == 0) { return 0; } + + xdebug_hash_add(tmp_hash, (char*) hash_key->key->val, hash_key->key->len, xdebug_str_create(hash_key->key->val, hash_key->key->len)); + + return 0; +} + +static int attach_context_vars(xdebug_xml_node *node, xdebug_var_export_options *options, long context_id, long depth, void (*func)(void *, xdebug_hash_element*, void*)) +{ + function_stack_entry *fse; + char *var_name; + + /* right now, we only have zero, one, or two with one being globals, which + * is always the head of the stack */ + if (context_id == 1) { + zend_ulong num; + zend_string *key; + zval *val; + + /* add super globals */ + xdebug_lib_set_active_symbol_table(&EG(symbol_table)); + xdebug_lib_set_active_data(NULL); + + ZEND_HASH_FOREACH_KEY_VAL_IND(&EG(symbol_table), num, key, val) { + if (!HASH_KEY_IS_NUMERIC(key)) { + add_variable_node(node, XDEBUG_STR_WRAP_CHAR(HASH_APPLY_KEY_VAL(key)), 1, 1, 0, options); + } + } ZEND_HASH_FOREACH_END(); + + xdebug_lib_set_active_symbol_table(NULL); + return 0; + } + + /* add user defined constants */ + if (context_id == 2) { + zend_constant *val; + + ZEND_HASH_FOREACH_PTR(EG(zend_constants), val) { + xdebug_str *tmp_name; + + if (!val->name) { + /* skip special constants */ + continue; + } + + if (ZEND_CONSTANT_MODULE_NUMBER(val) != PHP_USER_CONSTANT) { + /* we're only interested in user defined constants */ + continue; + } + + tmp_name = xdebug_str_create(val->name->val, val->name->len); + add_constant_node(node, tmp_name, &(val->value), options); + xdebug_str_free(tmp_name); + } ZEND_HASH_FOREACH_END(); + + return 0; + } + + /* Add return value special one if set and depth = 0 */ + if (XG_DBG(context).breakpoint_include_return_value && XG_DBG(current_return_value) && depth == 0) { + xdebug_xml_node *tmp_node; + xdebug_str *name = xdebug_str_create_from_const_char("$"XDEBUG_RETURN_VALUE_VAR_NAME); + + tmp_node = xdebug_get_zval_value_xml_node(name, XG_DBG(current_return_value), options); + xdebug_xml_expand_attribute_value(tmp_node, "facet", "readonly return_value virtual"); + + xdebug_xml_add_child(node, tmp_node); + xdebug_str_free(name); + + return 0; + } + + /* Here the context_id is 0 */ + if ((fse = xdebug_get_stack_frame(depth))) { + function_stack_entry *old_fse = xdebug_get_stack_frame(depth - 1); + + if (depth > 0) { + xdebug_lib_set_active_data(old_fse->execute_data); + } else { + xdebug_lib_set_active_data(EG(current_execute_data)); + } + xdebug_lib_set_active_symbol_table(fse->symbol_table); + + /* Only show vars when they are scanned */ + if (fse->declared_vars) { + xdebug_hash *tmp_hash; + + /* Get a hash from all the used vars (which can have duplicates) */ + tmp_hash = xdebug_declared_var_hash_from_llist(fse->declared_vars); + + /* Check for dynamically defined variables, but make sure we don't already + * have them. Also exclude superglobals and argv/argc */ + if (xdebug_lib_has_active_symbol_table()) { + zend_hash_apply_with_arguments(xdebug_lib_get_active_symbol_table(), (apply_func_args_t) xdebug_add_filtered_symboltable_var, 1, tmp_hash); + } + + /* Add all the found variables to the node */ + xdebug_hash_apply_with_argument(tmp_hash, (void *) node, func, (void *) options); + + /* Zend engine 2 does not give us $this, eval so we can get it */ + if (!xdebug_hash_find(tmp_hash, "this", 4, (void *) &var_name)) { + add_variable_node(node, XDEBUG_STR_WRAP_CHAR("this"), 1, 1, 0, options); + } + + xdebug_hash_destroy(tmp_hash); + } + + /* Check for static variables and constants, but only if it's a static + * method call as we attach constants and static properties to "this" + * too normally. */ + if (fse->function.type == XFUNC_STATIC_MEMBER) { + zend_class_entry *ce = zend_fetch_class(fse->function.object_class, ZEND_FETCH_CLASS_DEFAULT); + + if (ce->type == ZEND_INTERNAL_CLASS || (ce->ce_flags & ZEND_ACC_IMMUTABLE)) { + zend_class_init_statics(ce); + } + + xdebug_var_xml_attach_static_vars(node, options, ce); + } + + xdebug_lib_set_active_data(NULL); + xdebug_lib_set_active_symbol_table(NULL); + return 0; + } + + return 1; +} + +DBGP_FUNC(stack_depth) +{ + xdebug_xml_add_attribute_ex(*retval, "depth", xdebug_sprintf("%lu", XDEBUG_VECTOR_COUNT(XG_BASE(stack))), 0, 1); +} + +DBGP_FUNC(stack_get) +{ + xdebug_xml_node *stackframe; + long depth; + + if (CMD_OPTION_SET('d')) { + depth = strtol(CMD_OPTION_CHAR('d'), NULL, 10); + if (depth >= 0 && depth < (long) XDEBUG_VECTOR_COUNT(XG_BASE(stack))) { + stackframe = return_stackframe(depth); + xdebug_xml_add_child(*retval, stackframe); + } else { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); + } + } else { + function_stack_entry *fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + int i = 0; + + for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, fse--) { + stackframe = return_stackframe(i); + xdebug_xml_add_child(*retval, stackframe); + } + } +} + +DBGP_FUNC(status) +{ + xdebug_xml_add_attribute(*retval, "status", xdebug_dbgp_status_stringsXG_DBG(status)); + xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason)); +} + + +DBGP_FUNC(context_names) +{ + xdebug_xml_node *child; + + child = xdebug_xml_node_init("context"); + xdebug_xml_add_attribute(child, "name", "Locals"); + xdebug_xml_add_attribute(child, "id", "0"); + xdebug_xml_add_child(*retval, child); + + child = xdebug_xml_node_init("context"); + xdebug_xml_add_attribute(child, "name", "Superglobals"); + xdebug_xml_add_attribute(child, "id", "1"); + xdebug_xml_add_child(*retval, child); + + child = xdebug_xml_node_init("context"); + xdebug_xml_add_attribute(child, "name", "User defined constants"); + xdebug_xml_add_attribute(child, "id", "2"); + xdebug_xml_add_child(*retval, child); +} + +DBGP_FUNC(context_get) +{ + int res; + int context_id = 0; + int depth = 0; + xdebug_var_export_options *options = (xdebug_var_export_options*) context->options; + + if (CMD_OPTION_SET('c')) { + context_id = atol(CMD_OPTION_CHAR('c')); + } + if (CMD_OPTION_SET('d')) { + depth = atol(CMD_OPTION_CHAR('d')); + } + /* Always reset to page = 0, as it might have been modified by property_get or property_value */ + options->runtime0.page = 0; + + res = attach_context_vars(*retval, options, context_id, depth, attach_declared_var_with_contents); + switch (res) { + case 1: + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); + break; + } + + xdebug_xml_add_attribute_ex(*retval, "context", xdebug_sprintf("%d", context_id), 0, 1); +} + +DBGP_FUNC(xcmd_profiler_name_get) +{ + char *filename = xdebug_get_profiler_filename(); + + if (!filename) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_PROFILING_NOT_STARTED); + } + + xdebug_xml_add_text(*retval, xdstrdup(filename)); +} + +DBGP_FUNC(xcmd_get_executable_lines) +{ + function_stack_entry *fse; + unsigned int i; + long depth; + xdebug_xml_node *lines, *line; + + if (!CMD_OPTION_SET('d')) { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_INVALID_ARGS); + } + + depth = strtol(CMD_OPTION_CHAR('d'), NULL, 10); + if (depth >= 0 && depth < (long) XDEBUG_VECTOR_COUNT(XG_BASE(stack))) { + fse = xdebug_get_stack_frame(depth); + } else { + RETURN_RESULT(XG_DBG(status), XG_DBG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID); + } + + lines = xdebug_xml_node_init("xdebug:lines"); + for (i = 0; i < fse->op_array->last; i++ ) { + if (fse->op_array->opcodesi.opcode == ZEND_EXT_STMT ) { + line = xdebug_xml_node_init("xdebug:line"); + xdebug_xml_add_attribute_ex(line, "lineno", xdebug_sprintf("%lu", fse->op_array->opcodesi.lineno), 0, 1); + xdebug_xml_add_child(lines, line); + } + } + xdebug_xml_add_child(*retval, lines); +} + + +/***************************************************************************** +** Parsing functions +*/ + +/* {{{ Constants for state machine */ +#define STATE_NORMAL 0 +#define STATE_QUOTED 1 +#define STATE_OPT_FOLLOWS 2 +#define STATE_SEP_FOLLOWS 3 +#define STATE_VALUE_FOLLOWS_FIRST_CHAR 4 +#define STATE_VALUE_FOLLOWS 5 +#define STATE_SKIP_CHAR 6 +#define STATE_ESCAPED_CHAR_FOLLOWS 7 +/* }}} */ + +static void xdebug_dbgp_arg_dtor(xdebug_dbgp_arg *arg) +{ + int i; + + for (i = 0; i < 27; i++) { + if (arg->valuei) { + xdebug_str_free(arg->valuei); + } + } + xdfree(arg); +} + +static int xdebug_dbgp_parse_cmd(char *line, char **cmd, xdebug_dbgp_arg **ret_args) +{ + xdebug_dbgp_arg *args = NULL; + char *ptr; + int state; + int charescaped = 0; + char opt = ' ', *value_begin = NULL; + + args = xdmalloc(sizeof (xdebug_dbgp_arg)); + memset(args->value, 0, sizeof(args->value)); + *cmd = NULL; + + /* Find the end of the command, this is always on the first space */ + ptr = strchr(line, ' '); + if (!ptr) { + /* No space found. If the line is not empty, return the line + * and assume it only consists of the command name. If the line + * is 0 chars long, we return a failure. */ + if (strlen(line)) { + *cmd = strdup(line); + *ret_args = args; + return XDEBUG_ERROR_OK; + } else { + goto parse_error; + } + } else { + /* A space was found, so we copy everything before it + * into the cmd parameter. */ + *cmd = xdcalloc(1, ptr - line + 1); + memcpy(*cmd, line, ptr - line); + } + /* Now we loop until we find the end of the string, which is the \0 + * character */ + state = STATE_NORMAL; + do { + ptr++; + switch (state) { + case STATE_NORMAL: + if (*ptr != '-') { + goto parse_error; + } else { + state = STATE_OPT_FOLLOWS; + } + break; + case STATE_OPT_FOLLOWS: + opt = *ptr; + state = STATE_SEP_FOLLOWS; + break; + case STATE_SEP_FOLLOWS: + if (*ptr != ' ') { + goto parse_error; + } else { + state = STATE_VALUE_FOLLOWS_FIRST_CHAR; + value_begin = ptr + 1; + } + break; + case STATE_VALUE_FOLLOWS_FIRST_CHAR: + if (*ptr == '"' && opt != '-') { + value_begin = ptr + 1; + state = STATE_QUOTED; + } else { + state = STATE_VALUE_FOLLOWS; + } + break; + case STATE_VALUE_FOLLOWS: + if ((*ptr == ' ' && opt != '-') || *ptr == '\0') { + int opt_index = opt - 'a'; + + if (opt == '-') { + opt_index = 26; + } + + if (!args->valueopt_index) { + args->valueopt_index = xdebug_str_create(value_begin, ptr - value_begin); + state = STATE_NORMAL; + } else { + goto duplicate_opts; + } + } + break; + case STATE_QUOTED: + if (*ptr == '\\') { + state = STATE_ESCAPED_CHAR_FOLLOWS; + } else + if (*ptr == '"') { + int opt_index = opt - 'a'; + + if (charescaped) { + charescaped = 0; + break; + } + if (opt == '-') { + opt_index = 26; + } + + if (!args->valueopt_index) { + int len = ptr - value_begin; + + args->valueopt_index = xdebug_str_create(value_begin, len); + xdebug_stripcslashes(args->valueopt_index->d, &len); + args->valueopt_index->l = len; + + state = STATE_SKIP_CHAR; + } else { + goto duplicate_opts; + } + } + break; + case STATE_SKIP_CHAR: + state = STATE_NORMAL; + break; + case STATE_ESCAPED_CHAR_FOLLOWS: + state = STATE_QUOTED; + break; + + } + } while (*ptr); + *ret_args = args; + return XDEBUG_ERROR_OK; + +parse_error: + *ret_args = args; + return XDEBUG_ERROR_PARSE; + +duplicate_opts: + *ret_args = args; + return XDEBUG_ERROR_DUP_ARG; +} + +static int xdebug_dbgp_parse_option(xdebug_con *context, char* line, int flags, xdebug_xml_node *retval) +{ + char *cmd = NULL; + int res, ret = 0; + xdebug_dbgp_arg *args; + xdebug_dbgp_cmd *command; + xdebug_xml_node *error; + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_COM, "<- %s", line); + res = xdebug_dbgp_parse_cmd(line, (char**) &cmd, (xdebug_dbgp_arg**) &args); + + /* Add command name to return packet */ + if (cmd) { + /* if no cmd res will be XDEBUG_ERROR_PARSE */ + xdebug_xml_add_attribute_ex(retval, "command", xdstrdup(cmd), 0, 1); + } + + /* Handle missing transaction ID, and if it exist add it to the result */ + if (!CMD_OPTION_SET('i')) { + /* we need the transaction_id even for errors in parse_cmd, but if + we error out here, just force the error to happen below */ + res = XDEBUG_ERROR_INVALID_ARGS; + } else { + xdebug_xml_add_attribute_ex(retval, "transaction_id", xdstrdup(CMD_OPTION_CHAR('i')), 0, 1); + } + + /* Handle parse errors */ + /* FIXME: use RETURN_RESULT here too */ + if (res != XDEBUG_ERROR_OK) { + error = xdebug_xml_node_init("error"); + xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", res), 0, 1); + xdebug_xml_add_child(retval, error); + ADD_REASON_MESSAGE(res); + } else { + + /* Execute commands and stuff */ + command = lookup_cmd(cmd); + + if (command) { + if (command->cont) { + XG_DBG(status) = DBGP_STATUS_RUNNING; + XG_DBG(reason) = DBGP_REASON_OK; + } + XG_DBG(lastcmd) = command->name; + if (XG_DBG(lasttransid)) { + xdfree(XG_DBG(lasttransid)); + } + XG_DBG(lasttransid) = xdstrdup(CMD_OPTION_CHAR('i')); + if ( + XG_DBG(status) != DBGP_STATUS_STOPPING + || + (XG_DBG(status) == DBGP_STATUS_STOPPING && command->flags & XDEBUG_DBGP_POST_MORTEM)) + { + command->handler((xdebug_xml_node**) &retval, context, args); + ret = command->cont; + } else { + error = xdebug_xml_node_init("error"); + xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", XDEBUG_ERROR_COMMAND_UNAVAILABLE), 0, 1); + ADD_REASON_MESSAGE(XDEBUG_ERROR_COMMAND_UNAVAILABLE); + xdebug_xml_add_child(retval, error); + + ret = -1; + } + } else { + error = xdebug_xml_node_init("error"); + xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", XDEBUG_ERROR_UNIMPLEMENTED), 0, 1); + ADD_REASON_MESSAGE(XDEBUG_ERROR_UNIMPLEMENTED); + xdebug_xml_add_child(retval, error); + + ret = -1; + } + } + + xdfree(cmd); + xdebug_dbgp_arg_dtor(args); + return ret; +} + +/***************************************************************************** +** Handlers for debug functions +*/ +#define READ_BUFFER_SIZE 128 + +#define FD_RL_FILE 0 +#define FD_RL_SOCKET 1 + + +static char* xdebug_fd_read_line_delim(int socketfd, fd_buf *context, int type, unsigned char delim, int *length) +{ + int size = 0, newl = 0, nbufsize = 0; + char *tmp; + char *tmp_buf = NULL; + char *ptr; + char bufferREAD_BUFFER_SIZE + 1; + + if (!context->buffer) { + context->buffer = calloc(1,1); + context->buffer_size = 0; + } + + while (context->buffer_size < 1 || context->buffercontext->buffer_size - 1 != delim) { + ptr = context->buffer + context->buffer_size; + if (type == FD_RL_FILE) { + newl = read(socketfd, buffer, READ_BUFFER_SIZE); + } else { + newl = recv(socketfd, buffer, READ_BUFFER_SIZE, 0); + } + if (newl > 0) { + context->buffer = realloc(context->buffer, context->buffer_size + newl + 1); + memcpy(context->buffer + context->buffer_size, buffer, newl); + context->buffer_size += newl; + context->buffercontext->buffer_size = '\0'; + } else if (newl == -1 && errno == EINTR) { + continue; + } else { + free(context->buffer); + context->buffer = NULL; + context->buffer_size = 0; + return NULL; + } + } + + ptr = memchr(context->buffer, delim, context->buffer_size); + size = ptr - context->buffer; + /* Copy that line into tmp */ + tmp = malloc(size + 1); + tmpsize = '\0'; + memcpy(tmp, context->buffer, size); + /* Rewrite existing buffer */ + if ((nbufsize = context->buffer_size - size - 1) > 0) { + tmp_buf = malloc(nbufsize + 1); + memcpy(tmp_buf, ptr + 1, nbufsize); + tmp_bufnbufsize = 0; + } + free(context->buffer); + context->buffer = tmp_buf; + context->buffer_size = context->buffer_size - (size + 1); + + /* Return normal line */ + if (length) { + *length = size; + } + return tmp; +} + +static int xdebug_dbgp_cmdloop(xdebug_con *context, int bail) +{ + char *option; + int length; + int ret; + xdebug_xml_node *response; + + do { + length = 0; + + option = xdebug_fd_read_line_delim(context->socket, context->buffer, FD_RL_SOCKET, '\0', &length); + if (!option) { + return 0; + } + + response = xdebug_xml_node_init("response"); + xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); + xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); + ret = xdebug_dbgp_parse_option(context, option, 0, response); + if (ret != 1) { + send_message(context, response); + } + xdebug_xml_node_dtor(response); + + free(option); + } while (0 == ret); + + if (bail && XG_DBG(status) == DBGP_STATUS_STOPPED) { + _zend_bailout((char*)__FILE__, __LINE__); + } + return ret; + +} + +static int xdebug_compare_brk_info(const void *le1, const void *le2) +{ + xdebug_brk_info *a = (xdebug_brk_info *) XDEBUG_LLIST_VALP(*(xdebug_llist_element **) le1); + xdebug_brk_info *b = (xdebug_brk_info *) XDEBUG_LLIST_VALP(*(xdebug_llist_element **) le2); + + return (a->id > b->id); +} + +int xdebug_dbgp_init(xdebug_con *context, int mode) +{ + xdebug_var_export_options *options; + xdebug_xml_node *response, *child; + int i; + + /* initialize our status information */ + if (mode == XDEBUG_REQ) { + XG_DBG(status) = DBGP_STATUS_STARTING; + XG_DBG(reason) = DBGP_REASON_OK; + } else if (mode == XDEBUG_JIT) { + XG_DBG(status) = DBGP_STATUS_BREAK; + XG_DBG(reason) = DBGP_REASON_ERROR; + } + XG_DBG(lastcmd) = NULL; + XG_DBG(lasttransid) = NULL; + + response = xdebug_xml_node_init("init"); + xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); + xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); + +/* {{{ XML Init Stuff*/ + child = xdebug_xml_node_init("engine"); + xdebug_xml_add_attribute(child, "version", XDEBUG_VERSION); + xdebug_xml_add_text(child, xdstrdup(XDEBUG_NAME)); + xdebug_xml_add_child(response, child); + + child = xdebug_xml_node_init("author"); + xdebug_xml_add_text(child, xdstrdup(XDEBUG_AUTHOR)); + xdebug_xml_add_child(response, child); + + child = xdebug_xml_node_init("url"); + xdebug_xml_add_text(child, xdstrdup(XDEBUG_URL)); + xdebug_xml_add_child(response, child); + + child = xdebug_xml_node_init("copyright"); + xdebug_xml_add_text(child, xdstrdup(XDEBUG_COPYRIGHT)); + xdebug_xml_add_child(response, child); + + if (zend_string_equals_literal(context->program_name, "-") || zend_string_equals_literal(context->program_name, "Command line code")) { + xdebug_xml_add_attribute_ex(response, "fileuri", xdstrdup("dbgp://stdin"), 0, 1); + } else { + xdebug_xml_add_attribute_ex(response, "fileuri", xdebug_path_to_url(context->program_name), 0, 1); + } + xdebug_xml_add_attribute_ex(response, "language", "PHP", 0, 0); + xdebug_xml_add_attribute_ex(response, "xdebug:language_version", XG_BASE(php_version_run_time), 0, 0); + xdebug_xml_add_attribute_ex(response, "protocol_version", DBGP_VERSION, 0, 0); + xdebug_xml_add_attribute_ex(response, "appid", xdebug_sprintf(ZEND_ULONG_FMT, xdebug_get_pid()), 0, 1); + + if (getenv("DBGP_COOKIE")) { + xdebug_xml_add_attribute_ex(response, "session", xdstrdup(getenv("DBGP_COOKIE")), 0, 1); + } + + if (XG_DBG(context).host_type == XDEBUG_CLOUD && XINI_DBG(cloud_id) && *XINI_DBG(cloud_id)) { + xdebug_xml_add_attribute_ex(response, "xdebug:userid", xdstrdup(XINI_DBG(cloud_id)), 0, 1); + } + if (XG_DBG(context).host_type == XDEBUG_CLOUD_FROM_TRIGGER_VALUE && XG_DBG(ide_key) && *XG_DBG(ide_key)) { + xdebug_xml_add_attribute_ex(response, "xdebug:userid", xdstrdup(XG_DBG(ide_key)), 0, 1); + } + if (XG_DBG(context).host_type == XDEBUG_NORMAL && XG_DBG(ide_key) && *XG_DBG(ide_key)) { + xdebug_xml_add_attribute_ex(response, "idekey", xdstrdup(XG_DBG(ide_key)), 0, 1); + } + + context->buffer = xdmalloc(sizeof(fd_buf)); + context->buffer->buffer = NULL; + context->buffer->buffer_size = 0; + + send_message_ex(context, response, DBGP_STATUS_STARTING); + xdebug_xml_node_dtor(response); +/* }}} */ + + context->options = xdmalloc(sizeof(xdebug_var_export_options)); + options = (xdebug_var_export_options*) context->options; + options->max_children = 32; + options->max_data = 1024; + options->max_depth = 1; + options->show_hidden = 0; + options->extended_properties = 0; + options->encode_as_extended_property = 0; + options->runtime = (xdebug_var_runtime_page*) xdmalloc((options->max_depth + 1) * sizeof(xdebug_var_runtime_page)); + for (i = 0; i < options->max_depth; i++) { + options->runtimei.page = 0; + options->runtimei.current_element_nr = 0; + } + + context->breakpoint_list = xdebug_hash_alloc_with_sort(64, (xdebug_hash_dtor_t) xdebug_hash_admin_dtor, xdebug_compare_brk_info); + context->function_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_brk_dtor); + context->exception_breakpoints = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_brk_dtor); + context->line_breakpoints = xdebug_llist_alloc((xdebug_llist_dtor) xdebug_llist_brk_dtor); + context->eval_id_lookup = xdebug_hash_alloc(64, (xdebug_hash_dtor_t) xdebug_hash_eval_info_dtor); + context->eval_id_sequence = 0; + context->send_notifications = 0; + context->inhibit_notifications = 0; + context->resolved_breakpoints = 0; + context->breakpoint_details = 0; + context->breakpoint_include_return_value = 0; + + xdebug_mark_debug_connection_active(); + xdebug_dbgp_cmdloop(context, XDEBUG_CMDLOOP_BAIL); + + return 1; +} + +int xdebug_dbgp_deinit(xdebug_con *context) +{ + xdebug_xml_node *response; + xdebug_var_export_options *options; + int detaching = (XG_DBG(status) == DBGP_STATUS_DETACHED); + + if (xdebug_is_debug_connection_active()) { + XG_DBG(status) = DBGP_STATUS_STOPPING; + XG_DBG(reason) = DBGP_REASON_OK; + response = xdebug_xml_node_init("response"); + xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); + xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); + /* lastcmd and lasttransid are not always set (for example when the + * connection is severed before the first command is send) */ + if (XG_DBG(lastcmd) && XG_DBG(lasttransid)) { + xdebug_xml_add_attribute_ex(response, "command", XG_DBG(lastcmd), 0, 0); + xdebug_xml_add_attribute_ex(response, "transaction_id", XG_DBG(lasttransid), 0, 0); + } + xdebug_xml_add_attribute_ex(response, "status", xdebug_dbgp_status_stringsXG_DBG(status), 0, 0); + xdebug_xml_add_attribute_ex(response, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason), 0, 0); + + send_message(context, response); + xdebug_xml_node_dtor(response); + + if (!detaching) { + xdebug_dbgp_cmdloop(context, XDEBUG_CMDLOOP_NONBAIL); + } + } + + if (xdebug_is_debug_connection_active()) { + options = (xdebug_var_export_options*) context->options; + xdfree(options->runtime); + xdfree(context->options); + xdebug_hash_destroy(context->function_breakpoints); + xdebug_hash_destroy(context->exception_breakpoints); + xdebug_hash_destroy(context->eval_id_lookup); + xdebug_llist_destroy(context->line_breakpoints, NULL); + xdebug_hash_destroy(context->breakpoint_list); + xdfree(context->buffer); + context->buffer = NULL; + } + + if (XG_DBG(lasttransid)) { + xdfree(XG_DBG(lasttransid)); + XG_DBG(lasttransid) = NULL; + } + xdebug_mark_debug_connection_not_active(); + return 1; +} + +int xdebug_dbgp_error(xdebug_con *context, int type, char *exception_type, char *message, const char *location, const unsigned int line, xdebug_vector *stack) +{ + char *errortype; + xdebug_xml_node *response, *error; + + if (exception_type) { + errortype = exception_type; + } else { + errortype = xdebug_error_type(type); + } + + if (exception_type) { + XG_DBG(status) = DBGP_STATUS_BREAK; + XG_DBG(reason) = DBGP_REASON_EXCEPTION; + } else { + switch (type) { + case E_CORE_ERROR: + /* no break - intentionally */ + case E_ERROR: + /*case E_PARSE: the parser would return 1 (failure), we can bail out nicely */ + case E_COMPILE_ERROR: + case E_USER_ERROR: + XG_DBG(status) = DBGP_STATUS_STOPPING; + XG_DBG(reason) = DBGP_REASON_ABORTED; + break; + default: + XG_DBG(status) = DBGP_STATUS_BREAK; + XG_DBG(reason) = DBGP_REASON_ERROR; + } + } +/* + runtime_allowed = ( + (type != E_ERROR) && + (type != E_CORE_ERROR) && + (type != E_COMPILE_ERROR) && + (type != E_USER_ERROR) + ) ? XDEBUG_BREAKPOINT | XDEBUG_RUNTIME : 0; +*/ + + response = xdebug_xml_node_init("response"); + xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); + xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); + /* lastcmd and lasttransid are not always set (for example when the + * connection is severed before the first command is send) */ + if (XG_DBG(lastcmd) && XG_DBG(lasttransid)) { + xdebug_xml_add_attribute_ex(response, "command", XG_DBG(lastcmd), 0, 0); + xdebug_xml_add_attribute_ex(response, "transaction_id", XG_DBG(lasttransid), 0, 0); + } + xdebug_xml_add_attribute(response, "status", xdebug_dbgp_status_stringsXG_DBG(status)); + xdebug_xml_add_attribute(response, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason)); + + error = xdebug_xml_node_init("error"); + xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", type), 0, 1); + xdebug_xml_add_attribute_ex(error, "exception", xdstrdup(errortype), 0, 1); + xdebug_xml_add_text(error, xdstrdup(message)); + xdebug_xml_add_child(response, error); + + send_message(context, response); + xdebug_xml_node_dtor(response); + if (!exception_type) { + xdfree(errortype); + } + + xdebug_dbgp_cmdloop(context, XDEBUG_CMDLOOP_BAIL); + + return 1; +} + +int xdebug_dbgp_break_on_line(xdebug_con *context, xdebug_brk_info *brk, zend_string *filename, int lineno) +{ + char *tmp_file = ZSTR_VAL(filename); + int tmp_file_len = ZSTR_LEN(filename); + int free_tmp_file = 0; + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "Checking whether to break on %s:%d.", ZSTR_VAL(brk->filename), brk->resolved_lineno); + + if (brk->disabled) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: Breakpoint is disabled."); + return 0; + } + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Current location: %s:%d.", tmp_file, lineno); + + if (is_dbgp_url(brk->filename) && check_evaled_code(filename, &tmp_file)) { + free_tmp_file = 1; + tmp_file_len = strlen(tmp_file); + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Found eval code for '%s': %s.", ZSTR_VAL(filename), tmp_file); + } + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Matching breakpoint '%s:%d' against location '%s:%d'.", ZSTR_VAL(brk->filename), brk->resolved_lineno, tmp_file, lineno); + + if (ZSTR_LEN(brk->filename) != tmp_file_len) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: File name length (%d) doesn't match with breakpoint (%zd).", tmp_file_len, ZSTR_LEN(brk->filename)); + + if (free_tmp_file) { + xdfree(tmp_file); + } + return 0; + } + + if (brk->resolved_lineno != lineno) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: Line number (%d) doesn't match with breakpoint (%d).", lineno, brk->resolved_lineno); + + if (free_tmp_file) { + xdfree(tmp_file); + } + return 0; + } + + if (strncasecmp(ZSTR_VAL(brk->filename), tmp_file, ZSTR_LEN(brk->filename)) == 0) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "F: File names match (%s).", ZSTR_VAL(brk->filename)); + + if (free_tmp_file) { + xdfree(tmp_file); + } + return 1; + } + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: File names (%s) doesn't match with breakpoint (%s).", tmp_file, ZSTR_VAL(brk->filename)); + + if (free_tmp_file) { + xdfree(tmp_file); + } + return 0; +} + +int xdebug_dbgp_breakpoint(xdebug_con *context, xdebug_vector *stack, zend_string *filename, long lineno, int type, char *exception, char *code, const char *message, xdebug_brk_info *brk_info, zval *return_value) +{ + xdebug_xml_node *response, *error_container; + + XG_DBG(status) = DBGP_STATUS_BREAK; + XG_DBG(reason) = DBGP_REASON_OK; + + response = xdebug_xml_node_init("response"); + xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); + xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); + /* lastcmd and lasttransid are not always set (for example when the + * connection is severed before the first command is send) */ + if (XG_DBG(lastcmd) && XG_DBG(lasttransid)) { + xdebug_xml_add_attribute_ex(response, "command", XG_DBG(lastcmd), 0, 0); + xdebug_xml_add_attribute_ex(response, "transaction_id", XG_DBG(lasttransid), 0, 0); + } + xdebug_xml_add_attribute(response, "status", xdebug_dbgp_status_stringsXG_DBG(status)); + xdebug_xml_add_attribute(response, "reason", xdebug_dbgp_reason_stringsXG_DBG(reason)); + + error_container = xdebug_xml_node_init("xdebug:message"); + if (filename) { + char *tmp_filename = NULL; + + if (check_evaled_code(filename, &tmp_filename)) { + xdebug_xml_add_attribute_ex(error_container, "filename", tmp_filename, 0, 0); + xdfree(tmp_filename); + } else { + xdebug_xml_add_attribute_ex(error_container, "filename", xdebug_path_to_url(filename), 0, 1); + } + } + if (lineno) { + xdebug_xml_add_attribute_ex(error_container, "lineno", xdebug_sprintf("%lu", lineno), 0, 1); + } + if (exception) { + xdebug_xml_add_attribute_ex(error_container, "exception", xdstrdup(exception), 0, 1); + } + if (code) { + xdebug_xml_add_attribute_ex(error_container, "code", xdstrdup(code), 0, 1); + } + if (message) { + xdebug_xml_add_text(error_container, xdstrdup(message)); + } + xdebug_xml_add_child(response, error_container); + + if (XG_DBG(context).breakpoint_include_return_value && return_value) { + xdebug_xml_node *return_value_container, *tmp_node; + xdebug_var_export_options *options = (xdebug_var_export_options*) context->options; + + return_value_container = xdebug_xml_node_init("xdebug:return_value"); + tmp_node = xdebug_get_zval_value_xml_node(NULL, return_value, options); + + xdebug_xml_add_child(return_value_container, tmp_node); + + xdebug_xml_add_child(response, return_value_container); + } + + if (XG_DBG(context).breakpoint_details && brk_info) { + xdebug_xml_node *breakpoint_node = xdebug_xml_node_init("breakpoint"); + breakpoint_brk_info_add(breakpoint_node, brk_info); + xdebug_xml_add_child(response, breakpoint_node); + } + + send_message(context, response); + xdebug_xml_node_dtor(response); + + XG_DBG(lastcmd) = NULL; + if (XG_DBG(lasttransid)) { + xdfree(XG_DBG(lasttransid)); + XG_DBG(lasttransid) = NULL; + } + + XG_DBG(current_return_value) = return_value; + if (XG_DBG(current_return_value)) { + Z_TRY_ADDREF_P(XG_DBG(current_return_value)); + } + + xdebug_dbgp_cmdloop(context, XDEBUG_CMDLOOP_BAIL); + + if (XG_DBG(current_return_value)) { + Z_TRY_DELREF_P(XG_DBG(current_return_value)); + } + XG_DBG(current_return_value) = NULL; + + return xdebug_is_debug_connection_active(); +} + +static int xdebug_dbgp_resolved_breakpoint_notification(xdebug_con *context, xdebug_brk_info *brk_info) +{ + xdebug_xml_node *response, *child; + + if (!context->send_notifications) { + return 0; + } + + response = xdebug_xml_node_init("notify"); + xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); + xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); + xdebug_xml_add_attribute(response, "name", "breakpoint_resolved"); + + child = xdebug_xml_node_init("breakpoint"); + breakpoint_brk_info_add(child, brk_info); + xdebug_xml_add_child(response, child); + + send_message(context, response); + xdebug_xml_node_dtor(response); + + return 1; +} + +/* +static void function_breakpoint_resolve_helper(void *rctxt, xdebug_brk_info *brk_info, xdebug_hash_element *he) +{ + xdebug_dbgp_resolve_context *ctxt = (xdebug_dbgp_resolve_context*) rctxt; + + if (brk_info->resolved == XDEBUG_BRK_RESOLVED) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: %s breakpoint for '%s' has already been resolved.", + XDEBUG_BREAKPOINT_TYPE_NAME(brk_info->brk_type), ctxt->fse->function.function); + return; + } + + if (ctxt->fse->function.type == XFUNC_NORMAL) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: '%s' is a normal function (%02x).", ctxt->fse->function.function, ctxt->fse->function.type); + + if (strcmp(ctxt->fse->function.function, brk_info->functionname) == 0) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "F: Breakpoint function (%s) matches current function (%s).", brk_info->functionname, ctxt->fse->function.function); + brk_info->resolved = XDEBUG_BRK_RESOLVED; + xdebug_dbgp_resolved_breakpoint_notification(ctxt->context, brk_info); + return; + } + } else if (ctxt->fse->function.type == XFUNC_MEMBER || ctxt->fse->function.type == XFUNC_STATIC_MEMBER) { + char *tmp_name = NULL; + size_t tmp_len = 0; + + tmp_len = strlen(ctxt->fse->function.class) + strlen(ctxt->fse->function.function) + 3; + tmp_name = xdmalloc(tmp_len); + snprintf(tmp_name, tmp_len, "%s::%s", ctxt->fse->function.class, ctxt->fse->function.function); + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: '%s::%s' is a normal method (%02x).", ctxt->fse->function.class, ctxt->fse->function.function, ctxt->fse->function.type); + + if (strcmp(tmp_name, brk_info->functionname) == 0) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "F: Breakpoint method (%s) matches current method (%s).", brk_info->functionname, tmp_name); + brk_info->resolved = XDEBUG_BRK_RESOLVED; + xdebug_dbgp_resolved_breakpoint_notification(ctxt->context, brk_info); + xdfree(tmp_name); + return; + } + + xdfree(tmp_name); + } else { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: We don't handle this function type (%02x) yet.", ctxt->fse->function.type); + return; + } +} +*/ + +static void line_breakpoint_resolve_helper(xdebug_con *context, xdebug_lines_list *lines_list, xdebug_brk_info *brk_info) +{ +// xdebug_func func; + int i; + xdebug_function_lines_map_item *found_item = NULL; + int found_item_span = XDEBUG_RESOLVED_SPAN_MAX; + + /* Loop over all definitions in lines_list for file */ + for (i = 0; i < lines_list->count; i++) { + xdebug_function_lines_map_item *item = lines_list->functionsi; + + /* Loop over all the file/line list entries to find the best fitting one for 'brk_info->original_lineno' */ + if (brk_info->original_lineno < item->line_start || brk_info->original_lineno > item->line_end) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: Line number (%d) out of range (%zd-%zd).", brk_info->original_lineno, item->line_start, item->line_end); + continue; + } + + if (item->line_span < found_item_span) { + found_item = item; + found_item_span = item->line_span; + } + } + + if (!found_item) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: Could not find any file/line entry in lines list."); + return; + } + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: Line number (%d) in smallest range of range (%zd-%zd).", brk_info->original_lineno, found_item->line_start, found_item->line_end); + + /* If the breakpoint's line number is in the set, mark as resolved */ + if (xdebug_set_in(found_item->lines_breakable, brk_info->original_lineno)) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "F: Breakpoint line (%d) found in set of executable lines.", brk_info->original_lineno); + brk_info->resolved_lineno = brk_info->original_lineno; + brk_info->resolved = XDEBUG_BRK_RESOLVED; + xdebug_dbgp_resolved_breakpoint_notification(context, brk_info); + return; + } else { + int tmp_lineno; + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "I: Breakpoint line (%d) NOT found in set of executable lines.", brk_info->original_lineno); + + /* Check for a following line in the function */ + tmp_lineno = brk_info->original_lineno; + do { + tmp_lineno++; + + if (xdebug_set_in(found_item->lines_breakable, tmp_lineno)) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, " F: Line (%d) in set.", tmp_lineno); + + brk_info->resolved_lineno = tmp_lineno; + brk_info->resolved = XDEBUG_BRK_RESOLVED; + xdebug_dbgp_resolved_breakpoint_notification(context, brk_info); + return; + } else { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, " I: Line (%d) not in set.", tmp_lineno); + } + } while (tmp_lineno < found_item->line_end && (tmp_lineno < brk_info->original_lineno + XDEBUG_DBGP_SCAN_RANGE)); + + /* Check for a previous line in the function */ + tmp_lineno = brk_info->original_lineno; + do { + tmp_lineno--; + + if (xdebug_set_in(found_item->lines_breakable, tmp_lineno)) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, " F: Line (%d) in set.", tmp_lineno); + + brk_info->resolved_lineno = tmp_lineno; + brk_info->resolved = XDEBUG_BRK_RESOLVED; + xdebug_dbgp_resolved_breakpoint_notification(context, brk_info); + return; + } else { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, " I: Line (%d) not in set.", tmp_lineno); + } + } while (tmp_lineno > found_item->line_start && (tmp_lineno > brk_info->original_lineno - XDEBUG_DBGP_SCAN_RANGE)); + } +} + +static void breakpoint_resolve_helper(void *rctxt, xdebug_hash_element *he, void *dummy) +{ + xdebug_dbgp_resolve_context *ctxt = (xdebug_dbgp_resolve_context*) rctxt; + xdebug_brk_admin *admin = (xdebug_brk_admin*) he->ptr; + xdebug_brk_info *brk_info; + + brk_info = breakpoint_brk_info_fetch(admin->type, admin->key); + + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "Breakpoint %d (type: %s).", admin->id, XDEBUG_BREAKPOINT_TYPE_NAME(brk_info->brk_type)); + + /* Bail early if it's already resolved */ + if (brk_info->resolved == XDEBUG_BRK_RESOLVED) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "D: Breakpoint %d (type: %s) is already resolved.", admin->id, XDEBUG_BREAKPOINT_TYPE_NAME(brk_info->brk_type)); + return; + } + + switch (brk_info->brk_type) { + case XDEBUG_BREAKPOINT_TYPE_LINE: + case XDEBUG_BREAKPOINT_TYPE_CONDITIONAL: + if (!zend_string_equals(brk_info->filename, ctxt->filename)) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: File name (%s) does not match breakpoint to resolve (%s).", ZSTR_VAL(ctxt->filename), ZSTR_VAL(brk_info->filename)); + return; + } + + line_breakpoint_resolve_helper(ctxt->context, ctxt->lines_list, brk_info); + return; +/* + case XDEBUG_BREAKPOINT_TYPE_CALL: + case XDEBUG_BREAKPOINT_TYPE_RETURN: + function_breakpoint_resolve_helper(rctxt, brk_info, he); + return; +*/ + default: + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "R: The breakpoint type '%s' can not be resolved.", XDEBUG_BREAKPOINT_TYPE_NAME(brk_info->brk_type)); + return; + } +} + +/* Fetches the lines list for 'filename', and loops over all breakpoints to try + * to resolve them at run-time */ +int xdebug_dbgp_resolve_breakpoints(xdebug_con *context, zend_string *filename) +{ + xdebug_dbgp_resolve_context resolv_ctxt; + xdebug_lines_list *lines_list; + + /* Get the lines list for the current file */ + if (!XG_DBG(breakable_lines_map) || !xdebug_hash_find(XG_DBG(breakable_lines_map), ZSTR_VAL(filename), ZSTR_LEN(filename), (void *) &lines_list)) { + xdebug_log(XLOG_CHAN_DEBUG, XLOG_DEBUG, "E: Lines list for '%s' does not exist.", ZSTR_VAL(filename)); + return 0; + } + + resolv_ctxt.context = context; + resolv_ctxt.filename = filename; + resolv_ctxt.lines_list = lines_list; + xdebug_hash_apply_with_argument(context->breakpoint_list, (void *) &resolv_ctxt, breakpoint_resolve_helper, NULL); + + return 1; +} + +int xdebug_dbgp_stream_output(const char *string, unsigned int length) +{ + if ((XG_DBG(stdout_mode) == 1 || XG_DBG(stdout_mode) == 2) && length) { + xdebug_send_stream("stdout", string, length); + } + + if (XG_DBG(stdout_mode) == 0 || XG_DBG(stdout_mode) == 1) { + return 0; + } + return -1; +} + +int xdebug_dbgp_notification(xdebug_con *context, zend_string *filename, long lineno, int type, char *type_string, char *message) +{ + xdebug_xml_node *response, *error_container; + + response = xdebug_xml_node_init("notify"); + xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); + xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); + xdebug_xml_add_attribute(response, "name", "error"); + + error_container = xdebug_xml_node_init("xdebug:message"); + if (filename) { + char *tmp_filename = NULL; + + if (check_evaled_code(filename, &tmp_filename)) { + xdebug_xml_add_attribute_ex(error_container, "filename", tmp_filename, 0, 0); + xdfree(tmp_filename); + } else { + xdebug_xml_add_attribute_ex(error_container, "filename", xdebug_path_to_url(filename), 0, 1); + } + } + if (lineno) { + xdebug_xml_add_attribute_ex(error_container, "lineno", xdebug_sprintf("%lu", lineno), 0, 1); + } + if (type_string) { + xdebug_xml_add_attribute_ex(error_container, "type", xdstrdup(type_string), 0, 1); + } + if (message) { + char *tmp_buf; + + if (type == E_ERROR && ((tmp_buf = xdebug_strip_php_stack_trace(message)) != NULL)) { + xdebug_xml_add_text(error_container, tmp_buf); + } else { + xdebug_xml_add_text(error_container, xdstrdup(message)); + } + } + xdebug_xml_add_child(response, error_container); + + send_message(context, response); + xdebug_xml_node_dtor(response); + + return 1; +} + +int xdebug_dbgp_user_notify(xdebug_con *context, zend_string *filename, long lineno, zval *data) +{ + xdebug_xml_node *response, *data_node, *location_node; + xdebug_var_export_options *options; + + if (!context->send_notifications) { + return 0; + } + + response = xdebug_xml_node_init("notify"); + xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); + xdebug_xml_add_attribute(response, "xmlns:xdebug", "https://xdebug.org/dbgp/xdebug"); + xdebug_xml_add_attribute(response, "name", "user"); + + options = (xdebug_var_export_options*) context->options; + options->encode_as_extended_property = 0; + + location_node = xdebug_xml_node_init("xdebug:location"); + if (filename) { + char *tmp_filename = NULL; + + if (check_evaled_code(filename, &tmp_filename)) { + xdebug_xml_add_attribute_ex(location_node, "filename", tmp_filename, 0, 0); + xdfree(tmp_filename); + } else { + xdebug_xml_add_attribute_ex(location_node, "filename", xdebug_path_to_url(filename), 0, 1); + } + } + if (lineno) { + xdebug_xml_add_attribute_ex(location_node, "lineno", xdebug_sprintf("%lu", lineno), 0, 1); + } + xdebug_xml_add_child(response, location_node); + + data_node = xdebug_xml_node_init("property"); + xdebug_var_export_xml_node(&data, NULL, data_node, options, 0); + xdebug_xml_add_child(response, data_node); + + send_message(context, response); + xdebug_xml_node_dtor(response); + + return 1; +} + +static char *create_eval_key_file(zend_string *filename, int lineno) +{ + return xdebug_sprintf("%s(%d) : eval()'d code", ZSTR_VAL(filename), lineno); +} + +static char *create_eval_key_id(int id) +{ + return xdebug_sprintf("%04x", id); +} + +int xdebug_dbgp_register_eval_id(xdebug_con *context, function_stack_entry *fse) +{ + char *key; + xdebug_eval_info *ei; + + context->eval_id_sequence++; + + ei = xdcalloc(sizeof(xdebug_eval_info), 1); + ei->id = context->eval_id_sequence; + ei->contents = zend_string_copy(fse->include_filename); + ei->refcount = 2; + + key = create_eval_key_file(fse->filename, fse->lineno); + xdebug_hash_add(context->eval_id_lookup, key, strlen(key), (void*) ei); + xdfree(key); + + key = create_eval_key_id(ei->id); + xdebug_hash_add(context->eval_id_lookup, key, strlen(key), (void*) ei); + xdfree(key); + + return ei->id; +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/debugger/handler_dbgp.h
Added
@@ -0,0 +1,112 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __HAVE_XDEBUG_HANDLER_DBGP_H__ +#define __HAVE_XDEBUG_HANDLER_DBGP_H__ + +#include <string.h> +#include "handlers.h" +#include "lib/xml.h" + +#define DBGP_VERSION "1.0" + +typedef struct xdebug_dbgp_result { + int status; + int reason; + int code; +} xdebug_dbgp_result; + +#define ADD_REASON_MESSAGE(c) { \ + xdebug_xml_node *message = xdebug_xml_node_init("message"); \ + xdebug_error_entry *error_entry = &xdebug_error_codes0; \ + \ + while (error_entry->message) { \ + if ((c) == error_entry->code) { \ + xdebug_xml_add_text(message, xdstrdup(error_entry->message)); \ + xdebug_xml_add_child(error, message); \ + } \ + error_entry++; \ + } \ +} + +#define RETURN_RESULT(s, r, c) { \ + xdebug_xml_node *error = xdebug_xml_node_init("error"); \ + xdebug_xml_node *message = xdebug_xml_node_init("message"); \ + xdebug_error_entry *error_entry = &xdebug_error_codes0; \ + \ + xdebug_xml_add_attribute(*retval, "status", xdebug_dbgp_status_strings(s)); \ + xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_strings(r)); \ + xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%u", (c)), 0, 1); \ + \ + while (error_entry->message) { \ + if ((c) == error_entry->code) { \ + xdebug_xml_add_text(message, xdstrdup(error_entry->message)); \ + xdebug_xml_add_child(error, message); \ + } \ + error_entry++; \ + } \ + xdebug_xml_add_child(*retval, error); \ + return; \ +} + +/* Argument structure */ +typedef struct xdebug_dbgp_arg { + xdebug_str *value27; /* one extra for - */ +} xdebug_dbgp_arg; + +#define DBGP_FUNC_PARAMETERS xdebug_xml_node **retval, xdebug_con *context, xdebug_dbgp_arg *args +#define DBGP_FUNC_PASS_PARAMETERS retval, context, args +#define DBGP_FUNC(name) static void xdebug_dbgp_handle_##name(DBGP_FUNC_PARAMETERS) +#define DBGP_FUNC_ENTRY(name,flags) { #name, xdebug_dbgp_handle_##name, 0, flags }, +#define DBGP_CONT_FUNC_ENTRY(name,flags) { #name, xdebug_dbgp_handle_##name, 1, flags }, +#define DBGP_STOP_FUNC_ENTRY(name,flags) { #name, xdebug_dbgp_handle_##name, 2, flags }, + +#define XDEBUG_DBGP_NONE 1 << 0 +#define XDEBUG_DBGP_POST_MORTEM 1 << 1 /* command is valid in 'stopping' (post mortem) state */ + +typedef struct xdebug_dbgp_cmd { + const char *name; + void (*handler)(DBGP_FUNC_PARAMETERS); + int cont; + int flags; +} xdebug_dbgp_cmd; + +typedef struct xdebug_dbgp_resolve_context { + xdebug_con *context; + zend_string *filename; + xdebug_lines_list *lines_list; +} xdebug_dbgp_resolve_context; + +#define CMD_OPTION_SET(opt) (!!(opt == '-' ? args->value26 : args->value(opt) - 'a')) +#define CMD_OPTION_CHAR(opt) (opt == '-' ? args->value26->d : args->value(opt) - 'a'->d) +#define CMD_OPTION_LEN(opt) (opt == '-' ? args->value26->l : args->value(opt) - 'a'->l) +#define CMD_OPTION_XDEBUG_STR(opt) (opt == '-' ? args->value26 : args->value(opt) - 'a') + +int xdebug_dbgp_init(xdebug_con *context, int mode); +int xdebug_dbgp_deinit(xdebug_con *context); +int xdebug_dbgp_error(xdebug_con *context, int type, char *exception_type, char *message, const char *location, const unsigned int line, xdebug_vector *stack); +int xdebug_dbgp_break_on_line(xdebug_con *context, xdebug_brk_info *brk, zend_string *filename, int lineno); +int xdebug_dbgp_breakpoint(xdebug_con *context, xdebug_vector *stack, zend_string *filename, long lineno, int type, char *exception, char *code, const char *message, xdebug_brk_info *brk_info, zval *return_value); +int xdebug_dbgp_resolve_breakpoints(xdebug_con *context, zend_string *filename); +int xdebug_dbgp_stream_output(const char *string, unsigned int length); +int xdebug_dbgp_notification(xdebug_con *context, zend_string *filename, long lineno, int type, char *type_string, char *message); +int xdebug_dbgp_user_notify(xdebug_con *context, zend_string *filename, long lineno, zval *data); +void XDEBUG_ATTRIBUTE_FORMAT(printf, 2, 3) xdebug_dbgp_log(int log_level, const char *fmt, ...); +int xdebug_dbgp_register_eval_id(xdebug_con *context, function_stack_entry *fse); + +extern xdebug_remote_handler xdebug_handler_dbgp; + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/debugger/handlers.c
Changed
(renamed from xdebug-3.1.5/src/debugger/handlers.c)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/debugger/handlers.h
Added
@@ -0,0 +1,168 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __HAVE_XDEBUG_HANDLERS_H__ +#define __HAVE_XDEBUG_HANDLERS_H__ + +#include "php_xdebug.h" +#include "lib/compat.h" +#include "lib/llist.h" +#include "lib/hash.h" +#include "lib/lib.h" +#include "lib/usefulstuff.h" +#include "lib/vector.h" +#include "debugger_private.h" + +typedef struct _xdebug_brk_admin xdebug_brk_admin; +typedef struct _xdebug_brk_info xdebug_brk_info; +typedef struct _xdebug_brk_span xdebug_brk_span; +typedef struct _xdebug_eval_info xdebug_eval_info; +typedef struct _xdebug_con xdebug_con; +typedef struct _xdebug_debug_list xdebug_debug_list; +typedef struct _xdebug_remote_handler xdebug_remote_handler; +typedef struct _xdebug_remote_handler_info xdebug_remote_handler_info; + +struct _xdebug_debug_list { + zend_string *last_filename; + int last_line; +}; + +#define XDEBUG_BREAKPOINT_TYPE_LINE 0x01 +#define XDEBUG_BREAKPOINT_TYPE_CONDITIONAL 0x02 +#define XDEBUG_BREAKPOINT_TYPE_CALL 0x04 +#define XDEBUG_BREAKPOINT_TYPE_RETURN 0x08 +#define XDEBUG_BREAKPOINT_TYPE_EXCEPTION 0x10 +#define XDEBUG_BREAKPOINT_TYPE_WATCH 0x20 +#define XDEBUG_BREAKPOINT_TYPES_MASK 0x3F + +#define XDEBUG_BREAKPOINT_TYPE_EXTERNAL 0x40 // user-defined PHP function + +#define XDEBUG_BREAKPOINT_TYPE_NAME(v) (xdebug_breakpoint_types(int)(log2(v))).name + +struct _xdebug_brk_admin { + int id; + int type; + char *key; +}; + +#define XDEBUG_NORMAL 0x01 +#define XDEBUG_CLOUD 0x02 +#define XDEBUG_CLOUD_FROM_TRIGGER_VALUE 0x03 + +struct _xdebug_con { + int socket; + int host_type; /* XDEBUG_NORMAL, XDEBUG_CLOUD, XDEBUG_CLOUD_FROM_TRIGGER_VALUE */ + void *options; + xdebug_remote_handler *handler; + fd_buf *buffer; + zend_string *program_name; + xdebug_hash *breakpoint_list; + xdebug_hash *function_breakpoints; + xdebug_hash *eval_id_lookup; + int eval_id_sequence; + xdebug_llist *line_breakpoints; + xdebug_hash *exception_breakpoints; + xdebug_debug_list list; + int do_break; + xdebug_brk_info *pending_breakpoint; + + int do_step; + int do_next; + int next_level; + int do_finish; + int do_connect_to_client; + int finish_level; + int finish_func_nr; + + int send_notifications; + int inhibit_notifications; + + int resolved_breakpoints; + int breakpoint_details; + int breakpoint_include_return_value; + + /* Statistics and diagnostics */ + char *connected_hostname; + int connected_port; + char *detached_message; +}; + +#define XDEBUG_BRK_UNRESOLVED 0 +#define XDEBUG_BRK_RESOLVED 1 + +#define XDEBUG_HIT_DISABLED 0 +#define XDEBUG_HIT_GREATER_EQUAL 1 +#define XDEBUG_HIT_EQUAL 2 +#define XDEBUG_HIT_MOD 3 + +#define XDEBUG_RESOLVED_SPAN_MAX 2147483647 + +struct _xdebug_brk_info { + int id; + int brk_type; + int resolved; + char *classname; + char *functionname; + char *exceptionname; + int function_break_type; /* XDEBUG_BRK_FUNC_* */ + zend_string *filename; + int original_lineno; /* line number that was set through breakpoint_set */ + int resolved_lineno; /* line number after resolving, initialised with 'original_lineno' */ + char *condition; + int disabled; + int temporary; + int hit_count; + int hit_value; + int hit_condition; +}; + +struct _xdebug_eval_info { + int id; + int refcount; + zend_string *contents; +}; + +struct _xdebug_remote_handler { + /* Init / deinit */ + int (*remote_init)(xdebug_con *h, int mode); + int (*remote_deinit)(xdebug_con *h); + + /* Stack messages */ + int (*remote_error)(xdebug_con *h, int type, char *exception_type, char *message, const char *location, const unsigned int line, xdebug_vector *stack); + + /* Breakpoints */ + int (*break_on_line)(xdebug_con *h, xdebug_brk_info *brk, zend_string *filename, int lineno); + int (*remote_breakpoint)(xdebug_con *h, xdebug_vector *stack, zend_string *filename, long lineno, int type, char *exception, char *code, const char *message, xdebug_brk_info *brk_info, zval *return_value); + int (*resolve_breakpoints)(xdebug_con *h, zend_string *opa); + + /* Output redirection */ + int (*remote_stream_output)(const char *string, unsigned int length); + + /* Notifications & Logging */ + int (*remote_notification)(xdebug_con *h, zend_string *file, long lineno, int type, char *type_string, char *message); + int (*user_notification)(xdebug_con *h, zend_string *filename, long lineno, zval *data); + + /* Eval ID registration and removal */ + int (*register_eval_id)(xdebug_con *h, function_stack_entry *fse); +}; + +xdebug_brk_info *xdebug_brk_info_ctor(void); +void xdebug_brk_info_dtor(xdebug_brk_info *brk); +void xdebug_llist_brk_dtor(void *dummy, xdebug_brk_info *brk); +void xdebug_hash_brk_dtor(xdebug_brk_info *brk); +void xdebug_hash_eval_info_dtor(xdebug_eval_info *ei); + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/debugger/ip_info.c
Added
@@ -0,0 +1,289 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#ifdef __linux__ + +#include "php_xdebug.h" + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <errno.h> +#include <linux/rtnetlink.h> +#include <arpa/inet.h> +#include <net/if.h> +#include <netinet/in.h> +#include <arpa/nameser.h> +#include <resolv.h> + +#include "ip_info.h" + +#if XDEBUG_GATEWAY_SUPPORT + +#define BUFFER_SIZE 4096 + +static char *convert_to_quad(int domain, void *buf) +{ + char *ip = xdcalloc(1, INET6_ADDRSTRLEN + 1); + + inet_ntop(domain, buf, ip, INET6_ADDRSTRLEN); + + return ip; +} + +static int get_ip(int fd, struct sockaddr_nl *sa, int domain) +{ + char bufBUFFER_SIZE; + struct nlmsghdr *nl; + struct ifaddrmsg *ifa; + struct iovec iov = { 0 }; + struct msghdr msg = { 0 }; + int r; + + memset(buf, 0, BUFFER_SIZE); + + /* Assemble the message according to the netlink protocol */ + nl = (struct nlmsghdr*)buf; + nl->nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)); + nl->nlmsg_type = RTM_GETADDR; + nl->nlmsg_flags = NLM_F_REQUEST | NLM_F_ROOT; + + ifa = (struct ifaddrmsg*)NLMSG_DATA(nl); + ifa->ifa_family = domain; // We only get IPv4 address here + + /* Prepare struct msghdr for sending */ + iov.iov_base = nl; + iov.iov_len = nl->nlmsg_len; + msg.msg_name = sa; + msg.msg_namelen = sizeof(*sa); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + msg.msg_control = NULL; + msg.msg_controllen = 0; + msg.msg_flags = 0; + + /* Send netlink message to kernel */ + r = sendmsg(fd, &msg, 0); + return (r < 0) ? -1 : 0; +} + +static int get_msg(int fd, struct sockaddr_nl *sa, void *buf, size_t len) +{ + struct iovec iov; + struct msghdr msg; + + iov.iov_base = buf; + iov.iov_len = len; + + memset(&msg, 0, sizeof(msg)); + msg.msg_name = sa; + msg.msg_namelen = sizeof(*sa); + msg.msg_iov = &iov; + msg.msg_iovlen = 1; + + return recvmsg(fd, &msg, 0); +} + +static char *parse_ifa_msg(struct ifaddrmsg *ifa, void *buf, size_t len, const char *wanted_iface) +{ + char ifnameIF_NAMESIZE; + struct rtattr *rta = NULL; + int fa = ifa->ifa_family; + + if_indextoname(ifa->ifa_index, ifname); + + if (strcmp(ifname, wanted_iface) != 0) { + return NULL; + } + + for (rta = (struct rtattr*)buf; RTA_OK(rta, len); rta = RTA_NEXT(rta, len)) { + if (rta->rta_type == IFA_ADDRESS) { + return convert_to_quad(fa, RTA_DATA(rta)); + } + } + + return NULL; +} + +static uint32_t parse_nl_msg(void *buf, size_t len, const char *iface, char **if_address) +{ + struct nlmsghdr *nl = NULL; + uint32_t nlmsg_type = NLMSG_ERROR; + + for ( + nl = (struct nlmsghdr*)buf; + NLMSG_OK(nl, (uint32_t)len) && nl->nlmsg_type != NLMSG_DONE; + nl = NLMSG_NEXT(nl, len) + ) { + nlmsg_type = nl->nlmsg_type; + + if (nl->nlmsg_type == NLMSG_ERROR) { + return -1; + } + + if (nl->nlmsg_type == RTM_NEWADDR) { + struct ifaddrmsg *ifa; + ifa = (struct ifaddrmsg*)NLMSG_DATA(nl); + + if (*if_address == NULL) { + *if_address = parse_ifa_msg(ifa, IFA_RTA(ifa), IFA_PAYLOAD(nl), iface); + if (*if_address) { + return NLMSG_DONE; + } + } + continue; + } + } + return nlmsg_type; +} + +char *xdebug_get_ip_for_interface(const char *iface) +{ + char bufBUFFER_SIZE; + int fd = 0, len = 0; + char *if_address = NULL; + uint32_t nl_msg_type = NLMSG_DONE; + struct sockaddr_nl sa; + + /* Create a socket with the AF_NETLINK domain */ + fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); + if (fd < 0) { + return NULL; + } + + memset(&sa, 0, sizeof(sa)); + sa.nl_family = AF_NETLINK; + + len = get_ip(fd, &sa, AF_INET); // For IPv6: use AF_INET6 instead + if (len < 0) { + return NULL; + } + + do { + len = get_msg(fd, &sa, buf, BUFFER_SIZE); + if (len < 0) { + return NULL; + } + + nl_msg_type = parse_nl_msg(buf, len, iface, &if_address); + } while (nl_msg_type != NLMSG_DONE && nl_msg_type != NLMSG_ERROR); + + return if_address; +} + +/***/ + +static int get_gateway_and_iface(in_addr_t *addr, char *interface) +{ + long destination, gateway; + char ifaceIF_NAMESIZE; + char bufBUFFER_SIZE; + FILE *file; + + memset(iface, 0, sizeof(iface)); + memset(buf, 0, sizeof(buf)); + + file = fopen("/proc/net/route", "r"); + if (!file) { + return 0; + } + + while (fgets(buf, sizeof(buf), file)) { + if (sscanf(buf, "%s %lx %lx", iface, &destination, &gateway) == 3) { + if (destination == 0) { /* default */ + *addr = gateway; + strcpy(interface, iface); + fclose(file); + return 1; + } + } + } + + /* default route not found */ + if (file) { + fclose(file); + } + return 0; +} + +char *xdebug_get_gateway_ip(void) +{ + in_addr_t addr = 0; + char ifaceIF_NAMESIZE; + + memset(iface, 0, sizeof(iface)); + + if (get_gateway_and_iface(&addr, iface)) { + return xdstrdup(inet_ntoa(*(struct in_addr *) &addr)); + } + + return NULL; +} +#endif /* XDEBUG_GATEWAY_SUPPORT */ + +/***/ + +#if XDEBUG_NAMESERVER_SUPPORT +char *xdebug_get_private_nameserver(void) +{ + res_state res = malloc(sizeof(struct __res_state)); + in_addr_t ns_addr = 0; + char nameserver_buf20; + char *nameserver = NULL; + + res_ninit(res); + if (res->nscount > 0 && res->nsaddr_list0.sin_family == AF_INET) { + ns_addr = res->nsaddr_list0.sin_addr.s_addr; + /* Only allow private networks */ + if ( + ((ns_addr & 0x000000ff) == 0x0000000a) || // 10.x.x.x/24 + ((ns_addr & 0x0000f0ff) == 0x000010ac) || // 172.16.x.x/20 + ((ns_addr & 0x0000ffff) == 0x0000a8c0) || // 192.168.x.x/16 + ((ns_addr & 0x000000ff) == 0x0000007f) // 127.x.x.x/8 + ) + { + snprintf( + nameserver_buf, 16, "%d.%d.%d.%d", + (ns_addr & 0xff), + (ns_addr & 0xff00) >> 8, + (ns_addr & 0xff0000) >> 16, + (ns_addr & 0xff000000) >> 24 + ); + nameserver = xdstrdup(nameserver_buf); + } + } + res_nclose(res); + free(res); + + return nameserver; +} +#endif /* XDEBUG_NAMESERVER_SUPPORT */ + + +# if 0 +int main(int argc, char *argv) +{ + char *gateway_address = xdebug_get_gateway_ip(); + char *ip_address = xdebug_get_ip_for_interface(argv1); + + printf("Gateway: %s\n", gateway_address); + printf("IP: %s\n", ip_address); + + free(ip_address); + free(gateway_address); +} +# endif // int main + +#endif // __linux__
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/debugger/ip_info.h
Added
@@ -0,0 +1,37 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifdef __linux__ + +#include "php_xdebug.h" + +char *xdebug_get_ip_for_interface(const char *iface); + +#if HAVE_LINUX_RTNETLINK_H +# define XDEBUG_GATEWAY_SUPPORT 1 +char *xdebug_get_gateway_ip(void); +#else +# define XDEBUG_GATEWAY_SUPPORT 0 +#endif + +#if HAVE_RES_NINIT && HAVE_RES_NCLOSE +# define XDEBUG_NAMESERVER_SUPPORT 1 +char *xdebug_get_private_nameserver(void); +#else +# define XDEBUG_NAMESERVER_SUPPORT 0 +#endif + +#endif /* __linux__ */
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/develop/develop.c
Added
@@ -0,0 +1,137 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#include "lib/php-header.h" +#include "zend_exceptions.h" + +#include "php_xdebug.h" +#include "monitor.h" +#include "stack.h" +#include "superglobals.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +static int xdebug_silence_handler(XDEBUG_OPCODE_HANDLER_ARGS); + +static void xdebug_develop_overloaded_functions_setup(void) +{ + zend_function *orig; + + /* Override var_dump with our own function */ + orig = zend_hash_str_find_ptr(EG(function_table), "var_dump", sizeof("var_dump") - 1); + XG_DEV(orig_var_dump_func) = orig->internal_function.handler; + orig->internal_function.handler = zif_xdebug_var_dump; +} + +static void xdebug_develop_overloaded_functions_restore(void) +{ + zend_function *orig; + + orig = zend_hash_str_find_ptr(EG(function_table), "var_dump", sizeof("var_dump") - 1); + orig->internal_function.handler = XG_DEV(orig_var_dump_func); +} + + +void xdebug_init_develop_globals(xdebug_develop_globals_t *xg) +{ + xg->do_monitor_functions = 0; + + xg->in_at = 0; /* scream */ + + xdebug_llist_init(&xg->server, xdebug_superglobals_dump_dtor); + xdebug_llist_init(&xg->get, xdebug_superglobals_dump_dtor); + xdebug_llist_init(&xg->post, xdebug_superglobals_dump_dtor); + xdebug_llist_init(&xg->cookie, xdebug_superglobals_dump_dtor); + xdebug_llist_init(&xg->files, xdebug_superglobals_dump_dtor); + xdebug_llist_init(&xg->env, xdebug_superglobals_dump_dtor); + xdebug_llist_init(&xg->request, xdebug_superglobals_dump_dtor); + xdebug_llist_init(&xg->session, xdebug_superglobals_dump_dtor); +} + +void xdebug_deinit_develop_globals(xdebug_develop_globals_t *xg) +{ + xdebug_llist_empty(&xg->server, NULL); + xdebug_llist_empty(&xg->get, NULL); + xdebug_llist_empty(&xg->post, NULL); + xdebug_llist_empty(&xg->cookie, NULL); + xdebug_llist_empty(&xg->files, NULL); + xdebug_llist_empty(&xg->env, NULL); + xdebug_llist_empty(&xg->request, NULL); + xdebug_llist_empty(&xg->session, NULL); +} + +void xdebug_develop_minit(INIT_FUNC_ARGS) +{ + /* Overload opcodes for 'scream' */ + xdebug_set_opcode_handler(ZEND_BEGIN_SILENCE, xdebug_silence_handler); + xdebug_set_opcode_handler(ZEND_END_SILENCE, xdebug_silence_handler); + + REGISTER_LONG_CONSTANT("XDEBUG_STACK_NO_DESC", XDEBUG_STACK_NO_DESC, CONST_CS | CONST_PERSISTENT); +} + +void xdebug_develop_mshutdown() +{ +} + +void xdebug_develop_rinit() +{ + XG_DEV(collected_errors) = xdebug_llist_alloc(xdebug_llist_string_dtor); + + /* Function monitoring */ + XG_DEV(do_monitor_functions) = 0; + XG_DEV(functions_to_monitor) = NULL; + XG_DEV(monitored_functions_found) = xdebug_llist_alloc(xdebug_monitored_function_dtor); + + xdebug_develop_overloaded_functions_setup(); +} + +void xdebug_develop_post_deactivate() +{ + xdebug_llist_destroy(XG_DEV(collected_errors), NULL); + XG_DEV(collected_errors) = NULL; + + xdebug_llist_destroy(XG_DEV(monitored_functions_found), NULL); + XG_DEV(monitored_functions_found) = NULL; + + if (XG_DEV(functions_to_monitor)) { + xdebug_hash_destroy(XG_DEV(functions_to_monitor)); + XG_DEV(functions_to_monitor) = NULL; + } + + xdebug_develop_overloaded_functions_restore(); +} + + +static int xdebug_silence_handler(XDEBUG_OPCODE_HANDLER_ARGS) +{ + zend_op_array *op_array = &execute_data->func->op_array; + const zend_op *cur_opcode = execute_data->opline; + + if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { + xdebug_coverage_record_if_active(execute_data, op_array); + } + + if (XINI_DEV(do_scream)) { + execute_data->opline++; + if (cur_opcode->opcode == ZEND_BEGIN_SILENCE) { + XG_DEV(in_at) = 1; + } else { + XG_DEV(in_at) = 0; + } + return ZEND_USER_OPCODE_CONTINUE; + } + + return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/develop/develop.h
Added
@@ -0,0 +1,78 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2020 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __XDEBUG_DEVELOP_H__ +#define __XDEBUG_DEVELOP_H__ + +typedef struct _xdebug_develop_globals_t { + /* used for function monitoring */ + zend_bool do_monitor_functions; + xdebug_hash *functions_to_monitor; + xdebug_llist *monitored_functions_found; /* List of functions found */ + + /* superglobals */ + xdebug_llist server; + xdebug_llist get; + xdebug_llist post; + xdebug_llist cookie; + xdebug_llist files; + xdebug_llist env; + xdebug_llist request; + xdebug_llist session; + + /* used for collection errors */ + xdebug_llist *collected_errors; + + /* scream */ + zend_bool in_at; + + /* overloaded var_dump */ + zif_handler orig_var_dump_func; +} xdebug_develop_globals_t; + +typedef struct _xdebug_develop_settings_t { + + zend_long max_stack_frames; + zend_bool show_ex_trace; + zend_bool show_error_trace; + zend_bool show_local_vars; + zend_bool force_display_errors; + zend_long force_error_reporting; + zend_long halt_level; + + zend_long cli_color; + + /* superglobals */ + zend_bool dump_globals; + zend_bool dump_once; + zend_bool dump_undefined; + + /* scream */ + zend_bool do_scream; +} xdebug_develop_settings_t; + +void xdebug_init_develop_globals(xdebug_develop_globals_t *xg); +void xdebug_deinit_develop_globals(xdebug_develop_globals_t *xg); + +void xdebug_develop_minit(); +void xdebug_develop_mshutdown(); +void xdebug_develop_rinit(); +void xdebug_develop_post_deactivate(); + +void xdebug_develop_throw_exception_hook(zend_object *exception, zval *file, zval *line, zval *code, char *code_str, zval *message); +void xdebug_monitor_handler(function_stack_entry *fse); + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/develop/develop_private.h
Changed
(renamed from xdebug-3.1.5/src/develop/develop_private.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/develop/monitor.c
Added
@@ -0,0 +1,173 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "lib/php-header.h" +#include "php_xdebug.h" + +#include "develop_private.h" +#include "monitor.h" + +#include "lib/compat.h" +#include "lib/hash.h" +#include "lib/var.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +static void init_function_monitor_hash(xdebug_hash *internal, HashTable *functions_to_monitor) +{ + zval *val; + + ZEND_HASH_FOREACH_VAL(functions_to_monitor, val) { + if (Z_TYPE_P(val) == IS_STRING) { + xdebug_hash_add(internal, Z_STRVAL_P(val), Z_STRLEN_P(val), xdstrdup(Z_STRVAL_P(val))); + } + } ZEND_HASH_FOREACH_END(); +} + +static void xdebug_hash_function_monitor_dtor(char *function) +{ + xdfree(function); +} + +static xdebug_monitored_function_entry *xdebug_monitored_function_init(char *func_name, zend_string *filename, int lineno) +{ + xdebug_monitored_function_entry *tmp = xdmalloc(sizeof(xdebug_monitored_function_entry)); + + tmp->func_name = xdstrdup(func_name); + tmp->filename = zend_string_copy(filename); + tmp->lineno = lineno; + + return tmp; +} + +void xdebug_monitored_function_dtor(void *dummy, void *elem) +{ + xdebug_monitored_function_entry *mfe = (xdebug_monitored_function_entry*) elem; + + xdfree(mfe->func_name); + zend_string_release(mfe->filename); + xdfree(mfe); +} + +void xdebug_function_monitor_record(char *func_name, zend_string *filename, int lineno) +{ + xdebug_monitored_function_entry *record; + + record = xdebug_monitored_function_init(func_name, filename, lineno); + xdebug_llist_insert_next(XG_DEV(monitored_functions_found), XDEBUG_LLIST_TAIL(XG_DEV(monitored_functions_found)), record); +} + +void xdebug_monitor_handler(function_stack_entry *fse) +{ + char *func_name = NULL; + int func_name_len = 0; + void *dummy = NULL; + + if (!XG_DEV(do_monitor_functions)) { + return; + } + + func_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); + func_name_len = strlen(func_name); + + if (xdebug_hash_find(XG_DEV(functions_to_monitor), func_name, func_name_len, (void *) &dummy)) { + xdebug_function_monitor_record(func_name, fse->filename, fse->lineno); + } + + xdfree(func_name); +} + +PHP_FUNCTION(xdebug_start_function_monitor) +{ + HashTable *functions_to_monitor; + + if (!XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + php_error(E_WARNING, "Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop'"); + return; + } + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "H", &functions_to_monitor) == FAILURE) { + return; + } + + if (XG_DEV(do_monitor_functions) == 1) { + php_error(E_NOTICE, "Function monitoring was already started"); + } + + /* Clean and store list of functions to monitor */ + if (XG_DEV(functions_to_monitor)) { + xdebug_hash_destroy(XG_DEV(functions_to_monitor)); + } + + /* We add "1" here so that we don't alloc a 0-slot hash table */ + XG_DEV(functions_to_monitor) = xdebug_hash_alloc(zend_hash_num_elements(functions_to_monitor) + 1, (xdebug_hash_dtor_t) xdebug_hash_function_monitor_dtor); + init_function_monitor_hash(XG_DEV(functions_to_monitor), functions_to_monitor); + + XG_DEV(do_monitor_functions) = 1; +} + +PHP_FUNCTION(xdebug_stop_function_monitor) +{ + if (!XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + php_error(E_WARNING, "Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop'"); + return; + } + + if (XG_DEV(do_monitor_functions) == 0) { + php_error(E_NOTICE, "Function monitoring was not started"); + } + XG_DEV(do_monitor_functions) = 0; +} + +PHP_FUNCTION(xdebug_get_monitored_functions) +{ + xdebug_llist_element *le; + zend_bool clear = 0; + xdebug_monitored_function_entry *mfe; + + if (!XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + php_error(E_WARNING, "Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop'"); + array_init(return_value); + return; + } + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &clear) == FAILURE) { + return; + } + + array_init(return_value); + for (le = XDEBUG_LLIST_HEAD(XG_DEV(monitored_functions_found)); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { + zval *entry; + + mfe = XDEBUG_LLIST_VALP(le); + + XDEBUG_MAKE_STD_ZVAL(entry); + array_init(entry); + + add_assoc_string_ex(entry, "function", HASH_KEY_SIZEOF("function"), mfe->func_name); + add_assoc_string_ex(entry, "filename", HASH_KEY_SIZEOF("filename"), ZSTR_VAL(mfe->filename)); + add_assoc_long(entry, "lineno", mfe->lineno); + + add_next_index_zval(return_value, entry); + efree(entry); + } + + if (clear) { + xdebug_llist_destroy(XG_DEV(monitored_functions_found), NULL); + XG_DEV(monitored_functions_found) = xdebug_llist_alloc(xdebug_monitored_function_dtor); + } +} +/* }}} */
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/develop/monitor.h
Changed
(renamed from xdebug-3.1.5/src/develop/monitor.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/develop/php_functions.c
Added
@@ -0,0 +1,383 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "lib/php-header.h" +#include "php_xdebug.h" + +#include "develop_private.h" +#include "stack.h" + +#include "lib/lib_private.h" +#include "lib/var_export_html.h" +#include "lib/var_export_line.h" +#include "lib/var_export_text.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +#define MODE_MUST_BE(m,n) \ + if (!XDEBUG_MODE_IS((m))) { \ + php_error(E_WARNING, "Function must be enabled in php.ini by setting 'xdebug.mode' to '%s'", (n)); \ + return; \ + } + +/* {{{ proto void xdebug_var_dump(mixed var , ... ) + Outputs a fancy string representation of a variable */ +PHP_FUNCTION(xdebug_var_dump) +{ + zval *args; + int argc; + int i; + xdebug_str *val; + + argc = ZEND_NUM_ARGS(); + + args = safe_emalloc(argc, sizeof(zval), 0); + if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) { + efree(args); + WRONG_PARAM_COUNT; + } + + for (i = 0; i < argc; i++) { + if (PG(html_errors)) { + val = xdebug_get_zval_value_html(NULL, (zval*) &argsi, 0, NULL); + PHPWRITE(val->d, val->l); + xdebug_str_free(val); + } + else if ((XINI_DEV(cli_color) == 1 && xdebug_is_output_tty()) || (XINI_DEV(cli_color) == 2)) { + val = xdebug_get_zval_value_ansi((zval*) &argsi, 0, NULL); + PHPWRITE(val->d, val->l); + xdebug_str_free(val); + } + else { + val = xdebug_get_zval_value_text((zval*) &argsi, 0, NULL); + PHPWRITE(val->d, val->l); + xdebug_str_free(val); + } + } + + efree(args); +} +/* }}} */ + +/* {{{ proto void xdebug_debug_zval(mixed var , ... ) + Outputs a fancy string representation of a variable */ +PHP_FUNCTION(xdebug_debug_zval) +{ + zval *args; + int argc; + int i; + xdebug_str *val; + + argc = ZEND_NUM_ARGS(); + + args = safe_emalloc(argc, sizeof(zval), 0); + if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) { + efree(args); + WRONG_PARAM_COUNT; + } + + if (!(ZEND_CALL_INFO(EG(current_execute_data)->prev_execute_data) & ZEND_CALL_HAS_SYMBOL_TABLE)) { + zend_rebuild_symbol_table(); + } + + for (i = 0; i < argc; i++) { + if (Z_TYPE(argsi) == IS_STRING) { + zval debugzval; + xdebug_str *tmp_name; + + xdebug_lib_set_active_symbol_table(EG(current_execute_data)->prev_execute_data->symbol_table); + xdebug_lib_set_active_data(EG(current_execute_data)->prev_execute_data); + + tmp_name = xdebug_str_create(Z_STRVAL(argsi), Z_STRLEN(argsi)); + xdebug_get_php_symbol(&debugzval, tmp_name); + xdebug_str_free(tmp_name); + + /* Reduce refcount for dumping */ + Z_TRY_DELREF(debugzval); + + php_printf("%s: ", Z_STRVAL(argsi)); + if (Z_TYPE(debugzval) != IS_UNDEF) { + if (PG(html_errors)) { + val = xdebug_get_zval_value_html(NULL, &debugzval, 1, NULL); + PHPWRITE(val->d, val->l); + } + else if ((XINI_DEV(cli_color) == 1 && xdebug_is_output_tty()) || (XINI_DEV(cli_color) == 2)) { + val = xdebug_get_zval_value_ansi(&debugzval, 1, NULL); + PHPWRITE(val->d, val->l); + } + else { + val = xdebug_get_zval_value_line(&debugzval, 1, NULL); + PHPWRITE(val->d, val->l); + } + xdebug_str_free(val); + PHPWRITE("\n", 1); + } else { + PHPWRITE("no such symbol\n", 15); + } + + /* Restore original refcount */ + Z_TRY_ADDREF(debugzval); + zval_ptr_dtor_nogc(&debugzval); + } + } + + efree(args); +} +/* }}} */ + +/* {{{ proto void xdebug_debug_zval_stdout(mixed var , ... ) + Outputs a fancy string representation of a variable */ +PHP_FUNCTION(xdebug_debug_zval_stdout) +{ + zval *args; + int argc; + int i; + + argc = ZEND_NUM_ARGS(); + + args = safe_emalloc(argc, sizeof(zval), 0); + if (ZEND_NUM_ARGS() == 0 || zend_get_parameters_array_ex(argc, args) == FAILURE) { + efree(args); + WRONG_PARAM_COUNT; + } + + if (!(ZEND_CALL_INFO(EG(current_execute_data)->prev_execute_data) & ZEND_CALL_HAS_SYMBOL_TABLE)) { + zend_rebuild_symbol_table(); + } + + for (i = 0; i < argc; i++) { + if (Z_TYPE(argsi) == IS_STRING) { + zval debugzval; + xdebug_str *tmp_name; + xdebug_str *val; + + xdebug_lib_set_active_symbol_table(EG(current_execute_data)->prev_execute_data->symbol_table); + xdebug_lib_set_active_data(EG(current_execute_data)->prev_execute_data); + + tmp_name = xdebug_str_create(Z_STRVAL(argsi), Z_STRLEN(argsi)); + xdebug_get_php_symbol(&debugzval, tmp_name); + xdebug_str_free(tmp_name); + + /* Reduce refcount for dumping */ + Z_TRY_DELREF(debugzval); + + printf("%s: ", Z_STRVAL(argsi)); + if (Z_TYPE(debugzval) != IS_UNDEF) { + val = xdebug_get_zval_value_line(&debugzval, 1, NULL); + printf("%s(%zd)", val->d, val->l); + xdebug_str_free(val); + printf("\n"); + } else { + printf("no such symbol\n\n"); + } + + /* Restore original refcount */ + Z_TRY_ADDREF(debugzval); + zval_ptr_dtor_nogc(&debugzval); + } + } + + efree(args); +} +/* }}} */ + +PHP_FUNCTION(xdebug_start_error_collection) +{ + MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); + + if (XG_LIB(do_collect_errors) == 1) { + php_error(E_NOTICE, "Error collection was already started"); + } + + XG_LIB(do_collect_errors) = 1; +} + +PHP_FUNCTION(xdebug_stop_error_collection) +{ + MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); + + if (XG_LIB(do_collect_errors) == 0) { + php_error(E_NOTICE, "Error collection was not started"); + } + + XG_LIB(do_collect_errors) = 0; +} + +PHP_FUNCTION(xdebug_memory_usage) +{ + RETURN_LONG(zend_memory_usage(0)); +} + +PHP_FUNCTION(xdebug_peak_memory_usage) +{ + RETURN_LONG(zend_memory_peak_usage(0)); +} + +PHP_FUNCTION(xdebug_time_index) +{ + MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); + + RETURN_DOUBLE(XDEBUG_SECONDS_SINCE_START(xdebug_get_nanotime())); +} + +/* {{{ proto void xdebug_print_function_stack(string message , int options) + Displays a stack trace */ +PHP_FUNCTION(xdebug_print_function_stack) +{ + char *message = NULL; + size_t message_len; + function_stack_entry *fse; + char *tmp; + zend_long options = 0; + + MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sl", &message, &message_len, &options) == FAILURE) { + return; + } + + fse = xdebug_get_stack_frame(0); + if (message) { + tmp = xdebug_get_printable_stack(PG(html_errors), 0, message, ZSTR_VAL(fse->filename), fse->lineno, !(options & XDEBUG_STACK_NO_DESC)); + } else { + tmp = xdebug_get_printable_stack(PG(html_errors), 0, "user triggered", ZSTR_VAL(fse->filename), fse->lineno, !(options & XDEBUG_STACK_NO_DESC)); + } + php_printf("%s", tmp); + xdfree(tmp); +} +/* }}} */ + +/* {{{ proto string xdebug_call_class() + Returns the name of the calling class */ +PHP_FUNCTION(xdebug_call_class) +{ + function_stack_entry *fse; + zend_long depth = 2; + + MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &depth) == FAILURE) { + return; + } + + fse = xdebug_get_stack_frame(depth); + if (!fse) { + return; + } + + if (!fse->function.object_class) { + RETURN_FALSE; + } + + RETURN_STR_COPY(fse->function.object_class); +} +/* }}} */ + +/* {{{ proto string xdebug_call_function() + Returns the function name from which the current function was called from. */ +PHP_FUNCTION(xdebug_call_function) +{ + function_stack_entry *fse; + zend_long depth = 2; + + MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &depth) == FAILURE) { + return; + } + + fse = xdebug_get_stack_frame(depth); + if (!fse) { + return; + } + + if (!fse->function.function) { + RETURN_FALSE; + } + + RETURN_STRING(fse->function.function); +} +/* }}} */ + +/* {{{ proto int xdebug_call_line() + Returns the line number where the current function was called from. */ +PHP_FUNCTION(xdebug_call_line) +{ + function_stack_entry *fse; + zend_long depth = 2; + + MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &depth) == FAILURE) { + return; + } + + fse = xdebug_get_stack_frame(depth); + if (!fse) { + return; + } + + RETURN_LONG(fse->lineno); +} +/* }}} */ + +/* {{{ proto string xdebug_call_file() + Returns the filename where the current function was called from. */ +PHP_FUNCTION(xdebug_call_file) +{ + function_stack_entry *fse; + zend_long depth = 2; + + MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l", &depth) == FAILURE) { + return; + } + + fse = xdebug_get_stack_frame(depth); + if (!fse) { + return; + } + + RETURN_STR_COPY(fse->filename); +} +/* }}} */ + +PHP_FUNCTION(xdebug_get_collected_errors) +{ + xdebug_llist_element *le; + char *string; + zend_bool clear = 0; + + MODE_MUST_BE(XDEBUG_MODE_DEVELOP, "develop"); + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|b", &clear) == FAILURE) { + return; + } + + array_init(return_value); + for (le = XDEBUG_LLIST_HEAD(XG_DEV(collected_errors)); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { + string = XDEBUG_LLIST_VALP(le); + add_next_index_string(return_value, string); + } + + if (!clear) { + return; + } + + xdebug_llist_destroy(XG_DEV(collected_errors), NULL); + XG_DEV(collected_errors) = xdebug_llist_alloc(xdebug_llist_string_dtor); +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/develop/stack.c
Added
@@ -0,0 +1,1005 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2021 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#include "php_xdebug.h" + +#include "main/php_ini.h" + +#include "ext/standard/html.h" +#include "ext/standard/php_smart_string.h" +#include "zend_exceptions.h" +#include "zend_generators.h" + +#include "monitor.h" +#include "stack.h" +#include "superglobals.h" + +#include "base/filter.h" +#include "coverage/code_coverage.h" +#include "lib/compat.h" +#include "lib/lib_private.h" +#include "lib/str.h" +#include "lib/var_export_html.h" +#include "lib/var_export_line.h" +#include "profiler/profiler.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +static const char* text_formats11 = { + "\n", + "%s: %s in %s on line %d\n", + "\nCall Stack:\n", + "%10.4F %10ld %3d. %s(", + "'%s'", + ") %s:%d\n", + "\n\nVariables in local scope (#%d):\n", + "\n", + " $%s = %s\n", + " $%s = *uninitialized*\n", + "SCREAM: Error suppression ignored for\n" +}; + +static const char* ansi_formats11 = { + "\n", + "1m31m%s0m: %s22m in 31m%s0m on line 32m%d0m22m\n", + "\n1mCall Stack:22m\n", + "%10.4F %10ld %3d. %s(", + "'%s'", + ") %s:%d\n", + "\n\nVariables in local scope (#%d):\n", + "\n", + " $%s = %s\n", + " $%s = *uninitialized*\n", + "1m31mSCREAM0m: Error suppression ignored for\n" +}; + +static const char* html_formats13 = { + "<br />\n<font size='1'><table class='xdebug-error xe-%s%s' dir='ltr' border='1' cellspacing='0' cellpadding='1'>\n", + "<tr><th align='left' bgcolor='#f57900' colspan=\"5\"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> %s: %s in %s on line <i>%d</i></th></tr>\n", + "<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>\n<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>\n", + "<tr><td bgcolor='#eeeeec' align='center'>%d</td><td bgcolor='#eeeeec' align='center'>%.4F</td><td bgcolor='#eeeeec' align='right'>%ld</td><td bgcolor='#eeeeec'>%s( ", + "<font color='#00bb00'>'%s'</font>", + " )</td><td title='%s' bgcolor='#eeeeec'>%s<b>:</b>%d</td></tr>\n", + "<tr><th align='left' colspan='5' bgcolor='#e9b96e'>Variables in local scope (#%d)</th></tr>\n", + "</table></font>\n", + "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s =</pre></td><td colspan='3' bgcolor='#eeeeec'>%s</td></tr>\n", + "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s =</pre></td><td colspan='3' bgcolor='#eeeeec' valign='top'><i>Undefined</i></td></tr>\n", + " )</td><td title='%s' bgcolor='#eeeeec'><a style='color: black' href='%s'>%s<b>:</b>%d</a></td></tr>\n", + "<tr><th align='left' bgcolor='#f57900' colspan=\"5\"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> %s: %s in <a style='color: black' href='%s'>%s</a> on line <i>%d</i></th></tr>\n", + "<tr><th align='left' bgcolor='#f57900' colspan=\"5\"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> SCREAM: Error suppression ignored for</th></tr>\n" +}; + +static const char** select_formats(int html) +{ + if (html) { + return html_formats; + } else if ((XINI_DEV(cli_color) == 1 && xdebug_is_output_tty()) || (XINI_DEV(cli_color) == 2)) { + return ansi_formats; + } else { + return text_formats; + } +} + +void xdebug_log_stack(const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno) +{ + char *tmp_log_message; + int i; + function_stack_entry *fse; + + tmp_log_message = xdebug_sprintf( "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); + php_log_err(tmp_log_message); + xdfree(tmp_log_message); + + if (!XG_BASE(stack) || XDEBUG_VECTOR_COUNT(XG_BASE(stack)) < 1) { + return; + } + + fse = XDEBUG_VECTOR_HEAD(XG_BASE(stack)); + + php_log_err((char*) "PHP Stack trace:"); + + for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, fse++) + { + int c = 0; /* Comma flag */ + unsigned int j = 0; /* Counter */ + char *tmp_name; + xdebug_str log_buffer = XDEBUG_STR_INITIALIZER; + int variadic_opened = 0; + int sent_variables = fse->varc; + + if (sent_variables > 0 && fse->varsent_variables-1.is_variadic && Z_ISUNDEF(fse->varsent_variables-1.data)) { + sent_variables--; + } + + tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); + xdebug_str_add_fmt(&log_buffer, "PHP %3d. %s(", fse->level, tmp_name); + xdfree(tmp_name); + + /* Printing vars */ + for (j = 0; j < sent_variables; j++) { + xdebug_str *tmp_value; + + if (c) { + xdebug_str_add_literal(&log_buffer, ", "); + } else { + c = 1; + } + + if (fse->varj.is_variadic) { + xdebug_str_add_literal(&log_buffer, "..."); + variadic_opened = 1; + } + + if (fse->varj.name) { + xdebug_str_add_fmt(&log_buffer, "$%s = ", ZSTR_VAL(fse->varj.name)); + } + + if (fse->varj.is_variadic) { + xdebug_str_add_literal(&log_buffer, "variadic("); + c = 0; + continue; + } + + if (!Z_ISUNDEF(fse->varj.data)) { + tmp_value = xdebug_get_zval_value_line(&fse->varj.data, 0, NULL); + xdebug_str_add_str(&log_buffer, tmp_value); + xdebug_str_free(tmp_value); + } else { + xdebug_str_add_literal(&log_buffer, "*uninitialized*"); + } + } + + if (variadic_opened) { + xdebug_str_add_literal(&log_buffer, ")"); + } + + xdebug_str_add_fmt(&log_buffer, ") %s:%d", ZSTR_VAL(fse->filename), fse->lineno); + php_log_err(log_buffer.d); + xdebug_str_destroy(&log_buffer); + } +} + +void xdebug_append_error_head(xdebug_str *str, int html, const char *error_type_str) +{ + const char **formats = select_formats(html); + + if (html) { + xdebug_str_add_fmt(str, formats0, error_type_str, XG_DEV(in_at) ? " xe-scream" : ""); + if (XG_DEV(in_at)) { + xdebug_str_add_const(str, formats12); + } + } else { + xdebug_str_add_const(str, formats0); + if (XG_DEV(in_at)) { + xdebug_str_add_const(str, formats10); + } + } +} + +void xdebug_append_error_description(xdebug_str *str, int html, const char *error_type_str, const char *buffer, const char *error_filename, const int error_lineno) +{ + const char **formats = select_formats(html); + char *escaped; + + if (!html) { + escaped = estrdup(buffer); + } else { + zend_string *tmp; + char *first_closing = strchr(buffer, ''); + + /* We do need to escape HTML entities here, as HTML chars could be in + * the error message. However, PHP in some circumstances also adds an + * HTML link to a manual page. That bit, we don't need to escape. So + * this bit of code finds the portion that doesn't need escaping, adds + * it to a tmp string, and then adds an HTML escaped string for the + * rest of the original buffer. */ + if (first_closing && strstr(buffer, "() <a href=") != NULL) { + smart_string special_escaped = { 0, 0, 0 }; + + *first_closing = '\0'; + first_closing++; + + smart_string_appends(&special_escaped, buffer); + tmp = php_escape_html_entities((unsigned char *) first_closing, strlen(first_closing), 0, 0, NULL); + smart_string_appends(&special_escaped, tmp->val); + zend_string_free(tmp); + + smart_string_0(&special_escaped); + escaped = estrdup(special_escaped.c); + smart_string_free(&special_escaped); + } else if (strncmp(buffer, "assert()", 8) == 0) { + /* Also don't escape if we're in an assert, as things are already + * escaped. It's all nice and consistent ey? */ + escaped = estrdup(buffer); + } else { + tmp = php_escape_html_entities((unsigned char *) buffer, strlen(buffer), 0, 0, NULL); + escaped = estrdup(tmp->val); + zend_string_free(tmp); + } + } + + if (strlen(XINI_LIB(file_link_format)) > 0 && html && strcmp(error_filename, "Unknown") != 0) { + char *file_link; + + xdebug_format_file_link(&file_link, error_filename, error_lineno); + xdebug_str_add_fmt(str, formats11, error_type_str, escaped, file_link, error_filename, error_lineno); + xdfree(file_link); + } else { + xdebug_str_add_fmt(str, formats1, error_type_str, escaped, error_filename, error_lineno); + } + + efree(escaped); +} + +static void add_single_value(xdebug_str *str, zval *zv, int html) +{ + xdebug_str *tmp_value = NULL; + char *tmp_html_value = NULL; + size_t newlen; + + if (html) { + tmp_value = xdebug_get_zval_value_line(zv, 0, NULL); + tmp_html_value = xdebug_xmlize(tmp_value->d, tmp_value->l, &newlen); + + xdebug_str_add_literal(str, "<span>"); + xdebug_str_add(str, tmp_html_value, 0); + xdebug_str_add_literal(str, "</span>"); + + xdebug_str_free(tmp_value); + efree(tmp_html_value); + } else { + tmp_value = xdebug_get_zval_value_line(zv, 0, NULL); + + if (tmp_value) { + xdebug_str_add_str(str, tmp_value); + xdebug_str_free(tmp_value); + } else { + xdebug_str_add_literal(str, "???"); + } + } +} + +#define XDEBUG_VAR_FORMAT_INITIALISED 0 +#define XDEBUG_VAR_FORMAT_UNINITIALISED 1 + +static const char* text_var_formats2 = { + " $%s = %s\n", + " $%s = *uninitialized*\n", +}; + +static const char* ansi_var_formats2 = { + " $%s = %s\n", + " $%s = *uninitialized*\n", +}; + +static const char* html_var_formats2 = { + "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s =</pre></td><td colspan='3' bgcolor='#eeeeec'>%s</td></tr>\n", + "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s =</pre></td><td colspan='3' bgcolor='#eeeeec' valign='top'><i>Undefined</i></td></tr>\n", +}; + +static const char** get_var_format_string(int html) +{ + if (html) { + return html_var_formats; + } else if ((XINI_DEV(cli_color) == 1 && xdebug_is_output_tty()) || (XINI_DEV(cli_color) == 2)) { + return ansi_var_formats; + } else { + return text_var_formats; + } +} + + +static void xdebug_dump_used_var_with_contents(void *htmlq, xdebug_hash_element* he, void *argument) +{ + int html = *(int*) htmlq; + zval zvar; + xdebug_str *contents; + xdebug_str *name = (xdebug_str*) he->ptr; + HashTable *tmp_ht; + const char **formats; + xdebug_str *str = (xdebug_str *) argument; + + if (!he->ptr) { + return; + } + + /* Bail out on $this and $GLOBALS */ + if (strcmp(name->d, "this") == 0 || strcmp(name->d, "GLOBALS") == 0) { + return; + } + + if (EG(current_execute_data) && !(ZEND_CALL_INFO(EG(current_execute_data)) & ZEND_CALL_HAS_SYMBOL_TABLE)) { + zend_rebuild_symbol_table(); + } + + tmp_ht = xdebug_lib_get_active_symbol_table(); + { + zend_execute_data *ex = EG(current_execute_data); + while (ex && (!ex->func || !ZEND_USER_CODE(ex->func->type))) { + ex = ex->prev_execute_data; + } + if (ex) { + xdebug_lib_set_active_data(ex); + xdebug_lib_set_active_symbol_table(ex->symbol_table); + } + } + + xdebug_get_php_symbol(&zvar, name); + xdebug_lib_set_active_symbol_table(tmp_ht); + + formats = get_var_format_string(PG(html_errors)); + + if (Z_TYPE(zvar) == IS_UNDEF) { + xdebug_str_add_fmt(str, formatsXDEBUG_VAR_FORMAT_UNINITIALISED, name->d); + return; + } + + if (html) { + contents = xdebug_get_zval_value_html(NULL, &zvar, 0, NULL); + } else { + contents = xdebug_get_zval_value_line(&zvar, 0, NULL); + } + + if (contents) { + xdebug_str_add_fmt(str, formatsXDEBUG_VAR_FORMAT_INITIALISED, name->d, contents->d); + } else { + xdebug_str_add_fmt(str, formatsXDEBUG_VAR_FORMAT_UNINITIALISED, name->d); + } + + if (contents) { + xdebug_str_free(contents); + } + zval_ptr_dtor_nogc(&zvar); +} + +void xdebug_append_printable_stack(xdebug_str *str, int html) +{ + int printed_frames = 0; + const char **formats = select_formats(html); + int i; + function_stack_entry *fse; + + if (!XG_BASE(stack) || XDEBUG_VECTOR_COUNT(XG_BASE(stack)) < 1) { + return; + } + + fse = XDEBUG_VECTOR_HEAD(XG_BASE(stack)); + + xdebug_str_add_const(str, formats2); + + for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, fse++) + { + int c = 0; /* Comma flag */ + unsigned int j = 0; /* Counter */ + char *tmp_name; + int variadic_opened = 0; + int sent_variables = fse->varc; + + if (sent_variables > 0 && fse->varsent_variables-1.is_variadic && Z_ISUNDEF(fse->varsent_variables-1.data)) { + sent_variables--; + } + + if (xdebug_is_stack_frame_filtered(XDEBUG_FILTER_STACK, fse)) { + continue; + } + tmp_name = xdebug_show_fname(fse->function, html ? XDEBUG_SHOW_FNAME_ALLOW_HTML : XDEBUG_SHOW_FNAME_DEFAULT); + if (html) { + xdebug_str_add_fmt(str, formats3, fse->level, XDEBUG_SECONDS_SINCE_START(fse->nanotime), fse->memory, tmp_name); + } else { + xdebug_str_add_fmt(str, formats3, XDEBUG_SECONDS_SINCE_START(fse->nanotime), fse->memory, fse->level, tmp_name); + } + xdfree(tmp_name); + + /* Printing vars */ + for (j = 0; j < sent_variables; j++) { + if (c) { + xdebug_str_add_literal(str, ", "); + } else { + c = 1; + } + + if ( + (fse->varj.is_variadic && Z_ISUNDEF(fse->varj.data)) + ) { + xdebug_str_add_literal(str, "..."); + } + + if (fse->varj.name) { + if (html) { + xdebug_str_add_literal(str, "<span>$"); + xdebug_str_add_zstr(str, fse->varj.name); + xdebug_str_add_literal(str, " = </span>"); + } else { + xdebug_str_add_literal(str, "$"); + xdebug_str_add_zstr(str, fse->varj.name); + xdebug_str_add_literal(str, " = "); + } + } + + if (!variadic_opened && fse->varj.is_variadic && Z_ISUNDEF(fse->varj.data)) { + if (html) { + xdebug_str_add_literal(str, "<i>variadic</i>("); + } else { + xdebug_str_add_literal(str, "variadic("); + } + c = 0; + variadic_opened = 1; + continue; + } + + if (!Z_ISUNDEF(fse->varj.data)) { + add_single_value(str, &fse->varj.data, html); + } else { + xdebug_str_add_literal(str, "???"); + } + } + + if (variadic_opened) { + xdebug_str_add_literal(str, ")"); + } + + if (fse->include_filename) { + if (html) { + xdebug_str_add_literal(str, "<font color='#00bb00'>'"); + xdebug_str_add_zstr(str, fse->include_filename); + xdebug_str_add_literal(str, "</font>"); + } else { + xdebug_str_addc(str, '\''); + xdebug_str_add_zstr(str, fse->include_filename); + xdebug_str_addc(str, '\''); + } + } + + if (html) { + char *formatted_filename; + xdebug_format_filename(&formatted_filename, "...%s%n", fse->filename); + + if (strlen(XINI_LIB(file_link_format)) > 0 && strcmp(ZSTR_VAL(fse->filename), "Unknown") != 0) { + char *file_link; + + xdebug_format_file_link(&file_link, ZSTR_VAL(fse->filename), fse->lineno); + xdebug_str_add_fmt(str, formats10, ZSTR_VAL(fse->filename), file_link, formatted_filename, fse->lineno); + xdfree(file_link); + } else { + xdebug_str_add_fmt(str, formats5, ZSTR_VAL(fse->filename), formatted_filename, fse->lineno); + } + + xdfree(formatted_filename); + } else { + xdebug_str_add_fmt(str, formats5, ZSTR_VAL(fse->filename), fse->lineno); + } + + printed_frames++; + if (XINI_DEV(max_stack_frames) > 0 && printed_frames >= XINI_DEV(max_stack_frames)) { + break; + } + } + + if (XINI_DEV(dump_globals) && !(XINI_DEV(dump_once) && XG_LIB(dumped))) { + char *tmp = xdebug_get_printable_superglobals(html); + + if (tmp) { + xdebug_str_add(str, tmp, 1); + } + XG_LIB(dumped) = 1; + } + + if (XINI_DEV(show_local_vars) && XG_BASE(stack) && XDEBUG_VECTOR_TAIL(XG_BASE(stack))) { + int scope_nr = XDEBUG_VECTOR_COUNT(XG_BASE(stack)); + + fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + if (fse->user_defined == XDEBUG_BUILT_IN && xdebug_vector_element_is_valid(XG_BASE(stack), fse -1)) { + fse = fse - 1; + scope_nr--; + } + if (fse->declared_vars && fse->declared_vars->size) { + xdebug_hash *tmp_hash; + + xdebug_str_add_fmt(str, formats6, scope_nr); + tmp_hash = xdebug_declared_var_hash_from_llist(fse->declared_vars); + xdebug_hash_apply_with_argument(tmp_hash, (void*) &html, xdebug_dump_used_var_with_contents, (void *) str); + xdebug_hash_destroy(tmp_hash); + } + } +} + +void xdebug_append_error_footer(xdebug_str *str, int html) +{ + const char **formats = select_formats(html); + + xdebug_str_add_const(str, formats7); +} + +char *xdebug_get_printable_stack(int html, int error_type, const char *buffer, const char *error_filename, const int error_lineno, int include_decription) +{ + char *prepend_string; + char *append_string; + char *error_type_str = xdebug_error_type(error_type); + char *error_type_str_simple = xdebug_error_type_simple(error_type); + xdebug_str str = XDEBUG_STR_INITIALIZER; + + prepend_string = INI_STR((char*) "error_prepend_string"); + append_string = INI_STR((char*) "error_append_string"); + + if (prepend_string) { + xdebug_str_add(&str, prepend_string, 0); + } + xdebug_append_error_head(&str, html, error_type_str_simple); + if (include_decription) { + xdebug_append_error_description(&str, html, error_type_str, buffer, error_filename, error_lineno); + } + xdebug_append_printable_stack(&str, html); + xdebug_append_error_footer(&str, html); + if (append_string) { + xdebug_str_add(&str, append_string, 0); + } + + xdfree(error_type_str); + xdfree(error_type_str_simple); + + return str.d; +} + +static void php_output_error(const char *error) +{ +#ifdef PHP_DISPLAY_ERRORS_STDERR + if (PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR) { + fputs(error, stderr); + fflush(stderr); + return; + } +#endif + php_printf("%s", error); +} + +char *xdebug_strip_php_stack_trace(char *buffer) +{ + char *tmp_buf, *p; + + if (strncmp(buffer, "Uncaught ", 9) != 0) { + return NULL; + } + + /* find first new line */ + p = strchr(buffer, '\n'); + if (!p) { + p = buffer + strlen(buffer); + } else { + /* find the last " in ", which isn't great and might not work... but in most cases it will */ + p = xdebug_strrstr(buffer, " in "); + if (!p) { + p = buffer + strlen(buffer); + } + } + /* Create new buffer */ + tmp_buf = calloc(p - buffer + 1, 1); + strncpy(tmp_buf, buffer, p - buffer); + + return tmp_buf; +} + +static char *xdebug_handle_stack_trace(int type, char *error_type_str, const char *error_filename, const unsigned int error_lineno, char *buffer) +{ + char *printable_stack; + char *tmp_buf; + + /* We need to see if we have an uncaught exception fatal error now */ + if (type == E_ERROR && ((tmp_buf = xdebug_strip_php_stack_trace(buffer)) != NULL)) { + xdebug_str str = XDEBUG_STR_INITIALIZER; + + /* Append error */ + xdebug_append_error_head(&str, PG(html_errors), "uncaught-exception"); + xdebug_append_error_description(&str, PG(html_errors), error_type_str, tmp_buf, error_filename, error_lineno); + xdebug_append_printable_stack(&str, PG(html_errors)); + if (XG_BASE(last_exception_trace)) { + xdebug_str_add(&str, XG_BASE(last_exception_trace), 0); + } + xdebug_append_error_footer(&str, PG(html_errors)); + + free(tmp_buf); + printable_stack = str.d; + } else { + printable_stack = xdebug_get_printable_stack(PG(html_errors), type, buffer, error_filename, error_lineno, 1); + } + + return printable_stack; +} + +static void clear_last_error() +{ + if (PG(last_error_message)) { + zend_string_release(PG(last_error_message)); + PG(last_error_message) = NULL; + } + if (PG(last_error_file)) { +# if PHP_VERSION_ID >= 80100 + zend_string_release(PG(last_error_file)); +# else + free(PG(last_error_file)); +# endif + PG(last_error_file) = NULL; + } +} + +/* Error callback for formatting stack traces */ +#if PHP_VERSION_ID >= 80100 +void xdebug_develop_error_cb(int orig_type, zend_string *error_filename, const unsigned int error_lineno, zend_string *message) +{ +#else +void xdebug_develop_error_cb(int orig_type, const char *error_filename, const unsigned int error_lineno, zend_string *message) +{ +#endif + char *error_type_str; + int display; + int type = orig_type & E_ALL; + error_handling_t error_handling; + zend_class_entry *exception_class; + + + error_type_str = xdebug_error_type(type); + + /* check for repeated errors to be ignored */ + if (PG(ignore_repeated_errors) && PG(last_error_message)) { + /* no check for PG(last_error_file) is needed since it cannot + * be NULL if PG(last_error_message) is not NULL */ + + if (!zend_string_equals(PG(last_error_message), message) || + (!PG(ignore_repeated_source) && ( + (PG(last_error_lineno) != (int)error_lineno) || +#if PHP_VERSION_ID >= 80100 + !zend_string_equals(PG(last_error_file), error_filename) +#else + strcmp(PG(last_error_file), error_filename) != 0 +#endif + )) + ) { + display = 1; + } else { + display = 0; + } + } else { + display = 1; + } + + error_handling = EG(error_handling); + exception_class = EG(exception_class); + + /* according to error handling mode, throw exception or show it */ + if (error_handling == EH_THROW) { + switch (type) { + case E_ERROR: + case E_CORE_ERROR: + case E_COMPILE_ERROR: + case E_USER_ERROR: + case E_PARSE: + /* fatal errors are real errors and cannot be made exceptions */ + break; + case E_STRICT: + case E_DEPRECATED: + case E_USER_DEPRECATED: + /* for the sake of BC to old damaged code */ + break; + case E_NOTICE: + case E_USER_NOTICE: + /* notices are no errors and are not treated as such like E_WARNINGS */ + break; + default: + /* throw an exception if we are in EH_THROW mode + * but DO NOT overwrite a pending exception + */ + if (!EG(exception)) { + zend_throw_error_exception(exception_class, message, 0, type); + } + xdfree(error_type_str); + return; + } + } + + /* Store last error message for error_get_last() */ + if (display) { + clear_last_error(); + if (!error_filename) { +#if PHP_VERSION_ID >= 80100 + error_filename = zend_string_init(ZEND_STRL("Unknown"), 0); +#else + error_filename = "Unknown"; +#endif + } + PG(last_error_type) = type; + PG(last_error_message) = zend_string_copy(message); +#if PHP_VERSION_ID >= 80100 + PG(last_error_file) = zend_string_copy(error_filename); +#else + PG(last_error_file) = strdup(error_filename); +#endif + PG(last_error_lineno) = error_lineno; + } + + if ((EG(error_reporting) | XINI_DEV(force_error_reporting)) & type) { + /* Log to logger */ + if (PG(log_errors)) { + +#ifdef PHP_WIN32 + if (type==E_CORE_ERROR || type==E_CORE_WARNING) { + php_syslog(LOG_ALERT, "PHP %s: %s (%s)", error_type_str, ZSTR_VAL(message), GetCommandLine()); + } +#endif +#if PHP_VERSION_ID >= 80100 + xdebug_log_stack(error_type_str, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno); +#else + xdebug_log_stack(error_type_str, ZSTR_VAL(message), error_filename, error_lineno); +#endif + if (XINI_DEV(dump_globals) && !(XINI_DEV(dump_once) && XG_LIB(dumped))) { + char *printable_stack = xdebug_get_printable_superglobals(0); + + if (printable_stack) { + int pc; + + xdebug_arg *parts = xdebug_arg_ctor(); + + xdebug_explode("\n", printable_stack, parts, -1); + + for (pc = 0; pc < parts->c; pc++) { + char *tmp_line = xdebug_sprintf("PHP %s", parts->argspc); + php_log_err(tmp_line); + xdfree(tmp_line); + } + + xdebug_arg_dtor(parts); + xdfree(printable_stack); + php_log_err((char*) "PHP "); + } + } + } + + /* Display errors */ + if ((PG(display_errors) || XINI_DEV(force_display_errors)) && !PG(during_request_startup)) { + char *printable_stack; + +#if PHP_VERSION_ID >= 80100 + printable_stack = xdebug_handle_stack_trace(type, error_type_str, ZSTR_VAL(error_filename), error_lineno, ZSTR_VAL(message)); +#else + printable_stack = xdebug_handle_stack_trace(type, error_type_str, error_filename, error_lineno, ZSTR_VAL(message)); +#endif + + if (XG_LIB(do_collect_errors) && (type != E_ERROR) && (type != E_COMPILE_ERROR) && (type != E_USER_ERROR)) { + xdebug_llist_insert_next(XG_DEV(collected_errors), XDEBUG_LLIST_TAIL(XG_DEV(collected_errors)), printable_stack); + } else { + php_output_error(printable_stack); + xdfree(printable_stack); + } + } else if (XG_LIB(do_collect_errors)) { + char *printable_stack; +#if PHP_VERSION_ID >= 80100 + printable_stack = xdebug_get_printable_stack(PG(html_errors), type, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno, 1); +#else + printable_stack = xdebug_get_printable_stack(PG(html_errors), type, ZSTR_VAL(message), error_filename, error_lineno, 1); +#endif + xdebug_llist_insert_next(XG_DEV(collected_errors), XDEBUG_LLIST_TAIL(XG_DEV(collected_errors)), printable_stack); + } + } + + { +#if PHP_VERSION_ID >= 80100 + zend_string *tmp_error_filename = zend_string_copy(error_filename); +#else + zend_string *tmp_error_filename = zend_string_init(error_filename, strlen(error_filename), 0); +#endif + xdebug_debugger_error_cb(tmp_error_filename, error_lineno, type, error_type_str, ZSTR_VAL(message)); + zend_string_release(tmp_error_filename); + } + + xdfree(error_type_str); + + if (type & XINI_DEV(halt_level) & XDEBUG_ALLOWED_HALT_LEVELS) { + type = E_USER_ERROR; + } + + /* Bail out if we can't recover */ + switch (type) { + case E_CORE_ERROR: + if (!php_get_module_initialized()) { + /* bad error in module startup - no way we can live with this */ + exit(-2); + } + XDEBUG_BREAK_INTENTIONALLY_MISSING + + case E_ERROR: + case E_RECOVERABLE_ERROR: + case E_PARSE: + case E_COMPILE_ERROR: + case E_USER_ERROR: + EG(exit_status) = 255; + if (php_get_module_initialized()) { + if (!PG(display_errors) && + !SG(headers_sent) && + SG(sapi_headers).http_response_code == 200 + ) { + sapi_header_line ctr = { 0, 0, 0 }; + + ctr.line = (char*) "HTTP/1.0 500 Internal Server Error"; + ctr.line_len = sizeof("HTTP/1.0 500 Internal Server Error") - 1; + sapi_header_op(SAPI_HEADER_REPLACE, &ctr); + } + /* the parser would return 1 (failure), we can bail out nicely */ + if (!(orig_type & E_DONT_BAIL)) { + /* restore memory limit */ + zend_set_memory_limit(PG(memory_limit)); + zend_objects_store_mark_destructed(&EG(objects_store)); + _zend_bailout((char*) __FILE__, __LINE__); + return; + } + } + break; + } +} + +void xdebug_develop_throw_exception_hook(zend_object *exception, zval *file, zval *line, zval *code, char *code_str, zval *message) +{ + zend_class_entry *exception_ce = exception->ce; + zval *xdebug_message_trace, *previous_exception; + char *exception_trace; + xdebug_str tmp_str = XDEBUG_STR_INITIALIZER; + zval dummy; + + previous_exception = zend_read_property(exception_ce, exception, "previous", sizeof("previous")-1, 1, &dummy); + if (previous_exception && Z_TYPE_P(previous_exception) == IS_OBJECT) { + xdebug_message_trace = zend_read_property(exception_ce, Z_OBJ_P(previous_exception), "xdebug_message", sizeof("xdebug_message")-1, 1, &dummy); + if (xdebug_message_trace && Z_TYPE_P(xdebug_message_trace) != IS_NULL) { + xdebug_str_add(&tmp_str, Z_STRVAL_P(xdebug_message_trace), 0); + } + } + + if (!PG(html_errors)) { + xdebug_str_addc(&tmp_str, '\n'); + } + xdebug_append_error_description(&tmp_str, PG(html_errors), STR_NAME_VAL(exception_ce->name), message ? Z_STRVAL_P(message) : "", Z_STRVAL_P(file), Z_LVAL_P(line)); + xdebug_append_printable_stack(&tmp_str, PG(html_errors)); + exception_trace = tmp_str.d; + +#if PHP_VERSION_ID >= 80200 + exception_ce->ce_flags |= ZEND_ACC_ALLOW_DYNAMIC_PROPERTIES; +#endif + zend_update_property_string(exception_ce, exception, "xdebug_message", sizeof("xdebug_message")-1, exception_trace); + + if (XG_BASE(last_exception_trace)) { + xdfree(XG_BASE(last_exception_trace)); + } + XG_BASE(last_exception_trace) = exception_trace; + + if (XINI_DEV(show_ex_trace) || (instanceof_function(exception_ce, zend_ce_error) && XINI_DEV(show_error_trace))) { + if (PG(log_errors)) { + xdebug_log_stack(STR_NAME_VAL(exception_ce->name), Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line)); + } + if (PG(display_errors)) { + xdebug_str displ_tmp_str = XDEBUG_STR_INITIALIZER; + xdebug_append_error_head(&displ_tmp_str, PG(html_errors), "exception"); + xdebug_str_add(&displ_tmp_str, exception_trace, 0); + xdebug_append_error_footer(&displ_tmp_str, PG(html_errors)); + + php_printf("%s", displ_tmp_str.d); + xdebug_str_dtor(displ_tmp_str); + } + } +} + +/* {{{ proto int xdebug_get_stack_depth() + Returns the stack depth */ +PHP_FUNCTION(xdebug_get_stack_depth) +{ + /* We substract one so that the function call to xdebug_get_stack_depth() + * is not part of the returned depth. */ + RETURN_LONG(XDEBUG_VECTOR_COUNT(XG_BASE(stack)) - 1); +} + +/* {{{ proto array xdebug_get_function_stack() + Returns an array representing the current stack */ +PHP_FUNCTION(xdebug_get_function_stack) +{ + function_stack_entry *fse; + unsigned int i; + unsigned int j; + zval *frame; + zval *params; + int variadic_opened = 0; + + if (!XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + php_error(E_WARNING, "Function must be enabled in php.ini by setting 'xdebug.mode' to 'develop'"); + array_init(return_value); + return; + } + + array_init(return_value); + + fse = XDEBUG_VECTOR_HEAD(XG_BASE(stack)); + + for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)) - 1; i++, fse++) { + int sent_variables = fse->varc; + + if (fse->function.function) { + if (strcmp(fse->function.function, "xdebug_get_function_stack") == 0) { + return; + } + } + + if (sent_variables > 0 && fse->varsent_variables-1.is_variadic && Z_ISUNDEF(fse->varsent_variables-1.data)) { + sent_variables--; + } + + /* Initialize frame array */ + XDEBUG_MAKE_STD_ZVAL(frame); + array_init(frame); + + /* Add data */ + if (fse->function.function) { + add_assoc_string_ex(frame, "function", HASH_KEY_SIZEOF("function"), fse->function.function); + } + if (fse->function.object_class) { + add_assoc_string_ex(frame, "type", HASH_KEY_SIZEOF("type"), (char*) (fse->function.type == XFUNC_STATIC_MEMBER ? "static" : "dynamic")); + add_assoc_str_ex(frame, "class", HASH_KEY_SIZEOF("class"), zend_string_copy(fse->function.object_class)); + } + add_assoc_str_ex(frame, "file", HASH_KEY_SIZEOF("file"), zend_string_copy(fse->filename)); + add_assoc_long_ex(frame, "line", HASH_KEY_SIZEOF("line"), fse->lineno); + + /* Add parameters */ + XDEBUG_MAKE_STD_ZVAL(params); + array_init(params); + add_assoc_zval_ex(frame, "params", HASH_KEY_SIZEOF("params"), params); + + for (j = 0; j < sent_variables; j++) { + xdebug_str *argument = NULL; + + if (fse->varj.is_variadic) { + zval *vparams; + + XDEBUG_MAKE_STD_ZVAL(vparams); + array_init(vparams); + + if (fse->varj.name) { + add_assoc_zval_ex(params, ZSTR_VAL(fse->varj.name), ZSTR_LEN(fse->varj.name), vparams); + } else { + add_index_zval(params, j, vparams); + } + efree(params); + params = vparams; + variadic_opened = 1; + continue; + } + if (!Z_ISUNDEF(fse->varj.data)) { + argument = xdebug_get_zval_value_line(&fse->varj.data, 0, NULL); + } else { + argument = xdebug_str_create_from_char((char*) "???"); + } + if (fse->varj.name && !variadic_opened && argument) { + add_assoc_stringl_ex(params, ZSTR_VAL(fse->varj.name), ZSTR_LEN(fse->varj.name), argument->d, argument->l); + } else { + add_index_stringl(params, j - variadic_opened, argument->d, argument->l); + } + if (argument) { + xdebug_str_free(argument); + argument = NULL; + } + } + + if (fse->include_filename) { + add_assoc_str_ex(frame, "include_filename", HASH_KEY_SIZEOF("include_filename"), zend_string_copy(fse->include_filename)); + } + + add_next_index_zval(return_value, frame); + efree(params); + efree(frame); + } +} +/* }}} */
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/develop/stack.h
Added
@@ -0,0 +1,38 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2020 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef XDEBUG_STACK_H +#define XDEBUG_STACK_H + +#include "lib/str.h" + +#define XDEBUG_STACK_NO_DESC 0x01 + +void xdebug_append_error_head(xdebug_str *str, int html, const char *error_type_str); +void xdebug_append_error_description(xdebug_str *str, int html, const char *error_type_str, const char *buffer, const char *error_filename, const int error_lineno); +void xdebug_append_printable_stack(xdebug_str *str, int html); +void xdebug_append_error_footer(xdebug_str *str, int html); +void xdebug_log_stack(const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno); +char *xdebug_strip_php_stack_trace(char *buffer); +char *xdebug_get_printable_stack(int html, int error_type, const char *buffer, const char *error_filename, const int error_lineno, int include_decription); + +#if PHP_VERSION_ID >= 80100 +void xdebug_develop_error_cb(int orig_type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message); +#else +void xdebug_develop_error_cb(int orig_type, const char *error_filename, const uint32_t error_lineno, zend_string *message); +#endif + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/develop/superglobals.c
Added
@@ -0,0 +1,209 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "lib/php-header.h" +#include "SAPI.h" + +#include "php_xdebug.h" +#include "superglobals.h" + +#include "lib/compat.h" +#include "lib/lib.h" +#include "lib/var_export_html.h" +#include "lib/var_export_line.h" + +extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); + +void xdebug_superglobals_dump_dtor(void *user, void *ptr) +{ + free(ptr); +} + +static void dump_hash_elem(zval *z, const char *name, long index_key, const char *elem, int html, xdebug_str *str) +{ + if (html) { + if (elem) { + xdebug_str_add_fmt(str, "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s'%s' =</pre></td>", name, elem); + } else { + xdebug_str_add_fmt(str, "<tr><td colspan='2' align='right' bgcolor='#eeeeec' valign='top'><pre>$%s%ld =</pre></td>", name, index_key); + } + } + + if (z != NULL) { + xdebug_str *val; + + if (html) { + val = xdebug_get_zval_value_html(NULL, z, 0, NULL); + + xdebug_str_add_literal(str, "<td colspan='3' bgcolor='#eeeeec'>"); + xdebug_str_add_str(str, val); + xdebug_str_add_literal(str, "</td>"); + } else { + val = xdebug_get_zval_value_line(z, 0, NULL); + + if (elem) { + xdebug_str_add_fmt(str, "\n $%s'%s' = ", name, elem); + } else { + xdebug_str_add_fmt(str, "\n $%s%ld = ", name, index_key); + } + xdebug_str_add_str(str, val); + } + + xdebug_str_free(val); + } else { + /* not found */ + if (html) { + xdebug_str_add_literal(str, "<td colspan='3' bgcolor='#eeeeec'><i>undefined</i></td>"); + } else if (elem) { + xdebug_str_add_fmt(str, "\n $%s'%s' is undefined", name, elem); + } else { + xdebug_str_add_fmt(str, "\n $%s%ld is undefined", name, index_key); + } + } + + if (html) { + xdebug_str_add_literal(str, "</tr>\n"); + } +} + +static int dump_hash_elem_va(zval *pDest, zend_ulong index_key, zend_string *hash_key, const char *name, int html, xdebug_str *str) +{ + if (HASH_KEY_IS_NUMERIC(hash_key)) { + dump_hash_elem(pDest, name, index_key, NULL, html, str); + } else { + dump_hash_elem(pDest, name, 0, HASH_APPLY_KEY_VAL(hash_key), html, str); + } + + return SUCCESS; +} + +static void dump_hash(xdebug_llist *l, const char *name, int name_len, int html, xdebug_str *str) +{ + zval *z; + zend_ulong num; + zend_string *key; + zval *val; + HashTable *ht = NULL; + xdebug_llist_element *elem; + + if (!XDEBUG_LLIST_COUNT(l)) { + return; + } + + { + zend_string *s_name = zend_string_init(name, name_len, 0); + if ((z = zend_hash_find(&EG(symbol_table), s_name))) { + if (Z_TYPE_P(z) == IS_REFERENCE) { + z = &z->value.ref->val; + } + if (Z_TYPE_P(z) == IS_ARRAY) { + ht = Z_ARRVAL_P(z); + } + } + zend_string_release(s_name); + } + + if (html) { + xdebug_str_add_fmt(str, "<tr><th colspan='5' align='left' bgcolor='#e9b96e'>Dump <i>$%s</i></th></tr>\n", name); + } else { + xdebug_str_add_fmt(str, "\nDump $%s", name); + } + + elem = XDEBUG_LLIST_HEAD(l); + + while (elem != NULL) { + zend_string *s; + + s = zend_string_init(elem->ptr, strlen(elem->ptr), 0); + + if (ht && (*((char *) (elem->ptr)) == '*')) { + ZEND_HASH_FOREACH_KEY_VAL_IND(ht, num, key, val) { + dump_hash_elem_va(val, num, key, name, html, str); + } ZEND_HASH_FOREACH_END(); + } else if (ht && (z = zend_hash_find(ht, s))) { + dump_hash_elem(z, name, 0, elem->ptr, html, str); + } else if (XINI_DEV(dump_undefined)) { + dump_hash_elem(NULL, name, 0, elem->ptr, html, str); + } + + elem = XDEBUG_LLIST_NEXT(elem); + + zend_string_release(s); + } +} + +char* xdebug_get_printable_superglobals(int html) +{ + xdebug_str str = XDEBUG_STR_INITIALIZER; + + dump_hash(&XG_DEV(server), "_SERVER", HASH_KEY_SIZEOF("_SERVER"), html, &str); + dump_hash(&XG_DEV(get), "_GET", HASH_KEY_SIZEOF("_GET"), html, &str); + dump_hash(&XG_DEV(post), "_POST", HASH_KEY_SIZEOF("_POST"), html, &str); + dump_hash(&XG_DEV(cookie), "_COOKIE", HASH_KEY_SIZEOF("_COOKIE"), html, &str); + dump_hash(&XG_DEV(files), "_FILES", HASH_KEY_SIZEOF("_FILES"), html, &str); + dump_hash(&XG_DEV(env), "_ENV", HASH_KEY_SIZEOF("_ENV"), html, &str); + dump_hash(&XG_DEV(session), "_SESSION", HASH_KEY_SIZEOF("_SESSION"), html, &str); + dump_hash(&XG_DEV(request), "_REQUEST", HASH_KEY_SIZEOF("_REQUEST"), html, &str); + + return str.d; +} + +void xdebug_superglobals_dump_tok(xdebug_llist *l, char *str) +{ + char *tok; + const char *sep = ","; + + tok = strtok(str, sep); + while (tok != NULL) { + char *p = tok + strlen(tok) - 1; + + while ((*tok == ' ') || (*tok == '\t')) { + tok++; + } + + while ((p > tok) && ((*p == ' ') || (*p == '\t'))) { + p--; + } + + *(p+1) = 0; + + /* we need to strdup each element so that we can safely free it */ + xdebug_llist_insert_next(l, NULL, strdup(tok)); + + tok = strtok(NULL, sep); + } +} + +PHP_FUNCTION(xdebug_dump_superglobals) +{ + int html = PG(html_errors); + char *superglobal_info = NULL; + + if (html) { + php_printf("<table class='xdebug-superglobals' dir='ltr' border='1' cellspacing='0'>\n"); + } + + superglobal_info = xdebug_get_printable_superglobals(html); + if (superglobal_info) { + php_printf("%s", xdebug_get_printable_superglobals(html)); + } else { + php_printf("<tr><td><i>No information about superglobals is available or configured.</i></td></tr>\n"); + } + + if (html) { + php_printf("</table>\n"); + } +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/develop/superglobals.h
Added
@@ -0,0 +1,37 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __HAVE_XDEBUG_SUPERGLOBALS_H__ +#define __HAVE_XDEBUG_SUPERGLOBALS_H__ + +#include "lib/php-header.h" + +#include "develop_private.h" + +void xdebug_superglobals_dump_dtor(void *, void*); +char *xdebug_get_printable_superglobals(int html); +void xdebug_superglobals_dump_tok(xdebug_llist *l, char *str); + +# define DUMP_TOK(__llist) \ + xdebug_llist_empty(&XG_DEV(__llist), NULL); \ + if (new_value && new_value->val) { \ + char *str = estrndup(new_value->val, new_value->len); \ + xdebug_superglobals_dump_tok(&XG_DEV(__llist), str); \ + efree(str); \ + } \ + return SUCCESS; + +#endif /* __HAVE_XDEBUG_SUPERGLOBALS_H__ */
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/gcstats/gc_stats.c
Added
@@ -0,0 +1,356 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#include "lib/php-header.h" +#include "zend_builtin_functions.h" +#include "SAPI.h" +#include "Zend/zend_long.h" + +#include "php_xdebug.h" +#include "gc_stats_private.h" + +#include "base/base.h" +#include "lib/lib.h" +#include "lib/log.h" + +/* Set correct int format to use */ +#define XDEBUG_GCINT_FMT ZEND_LONG_FMT_SPEC + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +static void xdebug_gc_stats_print_run(xdebug_gc_run *run); +static void xdebug_gc_stats_run_free(xdebug_gc_run *run); +int (*xdebug_old_gc_collect_cycles)(void); + +static int xdebug_gc_collect_cycles(void) +{ + int ret; + uint32_t collected; + xdebug_gc_run *run; + zend_execute_data *execute_data; + long int memory; + uint64_t start; + xdebug_func tmp; + zend_gc_status status; + + if (!XG_GCSTATS(active)) { + return xdebug_old_gc_collect_cycles(); + } + + execute_data = EG(current_execute_data); + + zend_gc_get_status(&status); + collected = status.collected; + start = xdebug_get_nanotime(); + memory = zend_memory_usage(0); + + ret = xdebug_old_gc_collect_cycles(); + + run = xdmalloc(sizeof(xdebug_gc_run)); + run->function_name = NULL; + run->class_name = NULL; + + zend_gc_get_status(&status); + run->collected = status.collected - collected; + run->duration = xdebug_get_nanotime() - start; + run->memory_before = memory; + run->memory_after = zend_memory_usage(0); + + xdebug_build_fname(&tmp, execute_data); + + run->function_name = tmp.function ? xdstrdup(tmp.function) : NULL; + run->class_name = tmp.object_class ? zend_string_copy(tmp.object_class) : NULL; + + xdebug_gc_stats_print_run(run); + + xdebug_gc_stats_run_free(run); + xdebug_func_dtor_by_ref(&tmp); + + return ret; +} + +static void xdebug_gc_stats_run_free(xdebug_gc_run *run) +{ + if (!run) { + return; + } + + if (run->function_name) { + xdfree(run->function_name); + } + if (run->class_name) { + zend_string_release(run->class_name); + } + xdfree(run); +} + +static int xdebug_gc_stats_init(char *requested_filename, zend_string *script_name) +{ + char *filename_to_use = NULL; + char *generated_filename = NULL; + char *output_dir = xdebug_lib_get_output_dir(); /* not duplicated */ + + if (!gc_enabled()) { + xdebug_log_ex(XLOG_CHAN_GCSTATS, XLOG_ERR, "DISABLED", "PHP's Garbage Collection is disabled"); + return FAILURE; + } + + if (requested_filename && strlen(requested_filename)) { + filename_to_use = xdstrdup(requested_filename); + } else { + if (!strlen(XINI_GCSTATS(output_name)) || + xdebug_format_output_filename(&generated_filename, XINI_GCSTATS(output_name), ZSTR_VAL(script_name)) <= 0) + { + return FAILURE; + } + + if (IS_SLASH(output_dirstrlen(output_dir) - 1)) { + filename_to_use = xdebug_sprintf("%s%s", output_dir, generated_filename); + } else { + filename_to_use = xdebug_sprintf("%s%c%s", output_dir, DEFAULT_SLASH, generated_filename); + } + } + + XG_GCSTATS(file) = xdebug_fopen(filename_to_use, "w", NULL, &XG_GCSTATS(filename)); + + if (!XG_GCSTATS(file)) { + xdebug_log_diagnose_permissions(XLOG_CHAN_GCSTATS, output_dir, filename_to_use); + + xdfree(filename_to_use); + if (generated_filename) { + xdfree(generated_filename); + } + + return FAILURE; + } + xdfree(filename_to_use); + + fprintf(XG_GCSTATS(file), "Garbage Collection Report\n"); + fprintf(XG_GCSTATS(file), "version: 1\ncreator: xdebug %s (PHP %s)\n\n", XDEBUG_VERSION, PHP_VERSION); + + fprintf(XG_GCSTATS(file), "Collected | Efficiency%% | Duration | Memory Before | Memory After | Reduction%% | Function\n"); + fprintf(XG_GCSTATS(file), "----------+-------------+----------+---------------+--------------+------------+---------\n"); + + fflush(XG_GCSTATS(file)); + + if (generated_filename) { + xdfree(generated_filename); + } + + return SUCCESS; +} + +static void xdebug_gc_stats_stop() +{ + XG_GCSTATS(active) = 0; + + if (XG_GCSTATS(file)) { + if (!gc_enabled()) { + fprintf(XG_GCSTATS(file), "Garbage Collection Disabled End\n"); + xdebug_log_ex(XLOG_CHAN_GCSTATS, XLOG_ERR, "DISABLED", "PHP's Garbage Collection is disabled at the end of the script"); + } + + fclose(XG_GCSTATS(file)); + XG_GCSTATS(file) = NULL; + } +} + +#define AS_PERCENT(n) ((n)*100.0) +#define ROOTS_AS_PERCENT(n) AS_PERCENT((n) / 10000.0) + +static void xdebug_gc_stats_print_run(xdebug_gc_run *run) +{ + double reduction; + + if (run->memory_before) { + reduction = (1 - (float)run->memory_after / (float)run->memory_before) * 100.0; + } else { + reduction = 0; + } + + if (!XG_GCSTATS(file)) { + return; + } + + if (!run->function_name) { + fprintf(XG_GCSTATS(file), + "%9" XDEBUG_GCINT_FMT " | %9.2f %% | %5.2f ms | %13" XDEBUG_GCINT_FMT " | %12" XDEBUG_GCINT_FMT " | %8.2f %% | -\n", + run->collected, + ROOTS_AS_PERCENT(run->collected), + run->duration / (double)NANOS_IN_MILLISEC, + run->memory_before, + run->memory_after, + reduction + ); + } else if (!run->class_name && run->function_name) { + fprintf(XG_GCSTATS(file), + "%9" XDEBUG_GCINT_FMT " | %9.2f %% | %5.2f ms | %13" XDEBUG_GCINT_FMT " | %12" XDEBUG_GCINT_FMT " | %8.2f %% | %s\n", + run->collected, + ROOTS_AS_PERCENT(run->collected), + run->duration / (double)NANOS_IN_MILLISEC, + run->memory_before, + run->memory_after, + reduction, + run->function_name + ); + } else if (run->class_name && run->function_name) { + fprintf(XG_GCSTATS(file), + "%9" XDEBUG_GCINT_FMT " | %9.2f %% | %5.2f ms | %13" XDEBUG_GCINT_FMT " | %12" XDEBUG_GCINT_FMT " | %8.2f %% | %s::%s\n", + run->collected, + ROOTS_AS_PERCENT(run->collected), + run->duration / (double)NANOS_IN_MILLISEC, + run->memory_before, + run->memory_after, + reduction, + ZSTR_VAL(run->class_name), + run->function_name + ); + } + + fflush(XG_GCSTATS(file)); +} + +/* {{{ proto void xdebug_get_gcstats_filename() + Returns the name of the current garbage collection statistics report file */ +PHP_FUNCTION(xdebug_get_gcstats_filename) +{ + if (XG_GCSTATS(filename)) { + RETURN_STRING(XG_GCSTATS(filename)); + } else { + RETURN_FALSE; + } +} +/* }}} */ + +/* {{{ proto void xdebug_start_gcstats(string $fname) + Start collecting garbage collection statistics */ +PHP_FUNCTION(xdebug_start_gcstats) +{ + char *fname = NULL; + size_t fname_len = 0; + function_stack_entry *fse; + + if (XG_GCSTATS(active)) { + php_error(E_NOTICE, "Garbage Collection statistics are already being collected."); + RETURN_FALSE; + } + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|s", &fname, &fname_len) == FAILURE) { + return; + } + + fse = xdebug_get_stack_frame(0); + + if (xdebug_gc_stats_init(fname, fse->filename) == SUCCESS) { + XG_GCSTATS(active) = 1; + RETVAL_STRING(XG_GCSTATS(filename)); + return; + } + + php_error(E_NOTICE, "Garbage Collection statistics could not be started"); + + XG_GCSTATS(active) = 0; + RETURN_FALSE; +} +/* }}} */ + +/* {{{ proto void xdebug_stop_gcstats() + Stop collecting garbage collection statistics */ +PHP_FUNCTION(xdebug_stop_gcstats) +{ + if (!XG_GCSTATS(active)) { + php_error(E_NOTICE, "Garbage Collection statistics was not started"); + RETURN_FALSE; + } + + xdebug_gc_stats_stop(); + RETURN_STRING(XG_GCSTATS(filename)); +} + +/* {{{ proto void xdebug_get_gc_run_count() + Return number of times garbage collection was triggered. */ +PHP_FUNCTION(xdebug_get_gc_run_count) +{ + zend_gc_status status; + + zend_gc_get_status(&status); + RETURN_LONG(status.runs); +} + +/* {{{ proto void xdebug_get_gc_total_collected_roots() + Return total number of collected root variables during garbage collection. */ +PHP_FUNCTION(xdebug_get_gc_total_collected_roots) +{ + zend_gc_status status; + + zend_gc_get_status(&status); + RETURN_LONG(status.collected); +} + +/* {{{ helpers */ +void xdebug_gcstats_init_if_requested(zend_op_array* op_array) +{ + RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_GCSTATS); + if (!xdebug_lib_start_with_request(XDEBUG_MODE_GCSTATS)) { + return; + } + + if (XG_GCSTATS(active)) { + return; + } + + if (xdebug_gc_stats_init(NULL, op_array->filename) == SUCCESS) { + XG_GCSTATS(active) = 1; + } +} + +/* }}} */ + +/* {{{ initialisation */ +void xdebug_init_gc_stats_globals(xdebug_gc_stats_globals_t *xg) +{ + xg->file = NULL; + xg->filename = NULL; + xg->active = 0; +} + +void xdebug_gcstats_minit() +{ + /* Replace garbage collection handler with our own */ + xdebug_old_gc_collect_cycles = gc_collect_cycles; + gc_collect_cycles = xdebug_gc_collect_cycles; +} + +void xdebug_gcstats_mshutdown() +{ + gc_collect_cycles = xdebug_old_gc_collect_cycles; +} + +void xdebug_gcstats_rinit() +{ + xdebug_init_gc_stats_globals(&XG(globals).gc_stats); +} + +void xdebug_gcstats_rshutdown() +{ + if (XG_GCSTATS(active)) { + xdebug_gc_stats_stop(); + } + + if (XG_GCSTATS(filename)) { + xdfree(XG_GCSTATS(filename)); + } +} +/* }}} */
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/gcstats/gc_stats.h
Changed
(renamed from xdebug-3.1.5/src/gcstats/gc_stats.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/gcstats/gc_stats_private.h
Changed
(renamed from xdebug-3.1.5/src/gcstats/gc_stats_private.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/compat.c
Added
@@ -0,0 +1,446 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans <derick@xdebug.org> | + | (c) 1997-2004 Jim Winstead <jimw@trainedmonkey.com> | + | (c) 1998-2004 Andi Gutmans <andi@zend.com> and | + | Zeev Suraski <zeev@zend.com> | + +----------------------------------------------------------------------+ + | This source file is subject to the following Modified BSD license: | + | | + | Redistribution and use in source and binary forms, with or without | + | modification, are permitted provided that the following conditions | + | are met: | + | | + | 1. Redistributions of source code must retain the above copyright | + | notice, this list of conditions and the following disclaimer. | + | | + | 2. Redistributions in binary form must reproduce the above | + | copyright notice, this list of conditions and the following | + | disclaimer in the documentation and/or other materials provided | + | with the distribution. | + | | + | 3. The name of the author may not be used to endorse or promote | + | products derived from this software without specific prior | + | written permission. | + | | + | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | + | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | + | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | + | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY | + | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | + | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE | + | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | + | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER | + | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | + | OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN | + | IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | + +----------------------------------------------------------------------+ + */ + +#include "lib/php-header.h" +#include "main/php_version.h" +#include "compat.h" +#include "zend_extensions.h" + +#include "zend_compile.h" +#include "ext/standard/base64.h" +#include "ext/standard/php_string.h" + +char *xdebug_str_to_str(char *haystack, size_t length, const char *needle, size_t needle_len, const char *str, size_t str_len, size_t *new_len) +{ + zend_string *new_str; + char *retval; + + new_str = php_str_to_str(haystack, length, (char*) needle, needle_len, (char*) str, str_len); + *new_len = new_str->len; + + retval = estrndup(new_str->val, new_str->len); + + zend_string_release(new_str); + + return retval; +} + +/* {{{ base64 tables */ +static const char base64_table = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/', '\0' +}; + +static const char base64_pad = '='; + +static const short base64_reverse_table256 = { + -2, -2, -2, -2, -2, -2, -2, -2, -2, -1, -1, -2, -2, -1, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -1, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, 62, -2, -2, -2, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -2, -2, -2, -2, -2, -2, + -2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -2, -2, -2, -2, -2, + -2, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2 +}; +/* }}} */ + +static unsigned char *xdebug_base64_encode_impl(const unsigned char *in, size_t inl, unsigned char *out) /* {{{ */ +{ + + while (inl > 2) { /* keep going until we have less than 24 bits */ + *out++ = base64_tablein0 >> 2; + *out++ = base64_table((in0 & 0x03) << 4) + (in1 >> 4); + *out++ = base64_table((in1 & 0x0f) << 2) + (in2 >> 6); + *out++ = base64_tablein2 & 0x3f; + + in += 3; + inl -= 3; /* we just handle 3 octets of data */ + } + + /* now deal with the tail end of things */ + if (inl != 0) { + *out++ = base64_tablein0 >> 2; + if (inl > 1) { + *out++ = base64_table((in0 & 0x03) << 4) + (in1 >> 4); + *out++ = base64_table(in1 & 0x0f) << 2; + *out++ = base64_pad; + } else { + *out++ = base64_table(in0 & 0x03) << 4; + *out++ = base64_pad; + *out++ = base64_pad; + } + } + + *out = '\0'; + + return out; +} +/* }}} */ + +static int xdebug_base64_decode_impl(const unsigned char *in, size_t inl, unsigned char *out, size_t *outl, zend_bool strict) /* {{{ */ +{ + int ch; + size_t i = 0, padding = 0, j = *outl; + + /* run through the whole string, converting as we go */ + while (inl-- > 0) { + ch = *in++; + if (ch == base64_pad) { + padding++; + continue; + } + + ch = base64_reverse_tablech; + if (!strict) { + /* skip unknown characters and whitespace */ + if (ch < 0) { + continue; + } + } else { + /* skip whitespace */ + if (ch == -1) { + continue; + } + /* fail on bad characters or if any data follows padding */ + if (ch == -2 || padding) { + goto fail; + } + } + + switch (i % 4) { + case 0: + outj = ch << 2; + break; + case 1: + outj++ |= ch >> 4; + outj = (ch & 0x0f) << 4; + break; + case 2: + outj++ |= ch >>2; + outj = (ch & 0x03) << 6; + break; + case 3: + outj++ |= ch; + break; + } + i++; + } + + /* fail if the input is truncated (only one char in last group) */ + if (strict && i % 4 == 1) { + goto fail; + } + + /* fail if the padding length is wrong (not VV==, VVV=), but accept zero padding + * RFC 4648: "In some circumstances, the use of padding -- is not required" */ + if (strict && padding && (padding > 2 || (i + padding) % 4 != 0)) { + goto fail; + } + + *outl = j; + outj = '\0'; + + return 1; + +fail: + return 0; +} +/* }}} */ + +unsigned char *xdebug_base64_encode(unsigned char *data, size_t data_len, size_t *new_len) +{ + unsigned char *retval = xdmalloc((((data_len + 2) / 3) + 1) * (4 * sizeof(char))); + unsigned char *end; + + end = xdebug_base64_encode_impl(data, data_len, retval); + *new_len = end - retval; + + return retval; +} + +unsigned char *xdebug_base64_decode(unsigned char *data, size_t data_len, size_t *new_len) +{ + unsigned char *retval = xdmalloc(data_len + 1); + + xdebug_base64_decode_impl(data, data_len, retval, new_len, 0); + + return retval; +} + +zend_string *xdebug_addslashes(zend_string *str) +{ + /* maximum string length, worst case situation */ + char *target; + const char *source, *end; + size_t offset; + zend_string *new_str; + + if (!str) { + return ZSTR_EMPTY_ALLOC(); + } + + source = ZSTR_VAL(str); + end = source + ZSTR_LEN(str); + + while (source < end) { + switch (*source) { + case '\0': + case '\'': + case '\"': + case '\\': + goto do_escape; + default: + source++; + break; + } + } + + return zend_string_copy(str); + +do_escape: + offset = source - (char *)ZSTR_VAL(str); + new_str = zend_string_safe_alloc(2, ZSTR_LEN(str) - offset, offset, 0); + memcpy(ZSTR_VAL(new_str), ZSTR_VAL(str), offset); + target = ZSTR_VAL(new_str) + offset; + + while (source < end) { + switch (*source) { + case '\0': + *target++ = '\\'; + *target++ = '0'; + break; + case '\'': + case '\"': + case '\\': + *target++ = '\\'; + XDEBUG_BREAK_INTENTIONALLY_MISSING + + default: + *target++ = *source; + break; + } + source++; + } + + *target = '\0'; + + if (ZSTR_LEN(new_str) - (target - ZSTR_VAL(new_str)) > 16) { + new_str = zend_string_truncate(new_str, target - ZSTR_VAL(new_str), 0); + } else { + ZSTR_LEN(new_str) = target - ZSTR_VAL(new_str); + } + + return new_str; +} + +void xdebug_stripcslashes(char *str, int *len) +{ + char *source, *target, *end; + int nlen = *len, i; + char numtmp4; + + for (source=str, end=str+nlen, target=str; source < end; source++) { + if (*source == '\\' && source+1 < end) { + source++; + switch (*source) { + case 'n': *target++='\n'; nlen--; break; + case 'r': *target++='\r'; nlen--; break; + case 'a': *target++='\a'; nlen--; break; + case 't': *target++='\t'; nlen--; break; + case 'v': *target++='\v'; nlen--; break; + case 'b': *target++='\b'; nlen--; break; + case 'f': *target++='\f'; nlen--; break; + case '\\': *target++='\\'; nlen--; break; + case 'x': + if (source+1 < end && isxdigit((int)(*(source+1)))) { + numtmp0 = *++source; + if (source+1 < end && isxdigit((int)(*(source+1)))) { + numtmp1 = *++source; + numtmp2 = '\0'; + nlen-=3; + } else { + numtmp1 = '\0'; + nlen-=2; + } + *target++=(char)strtol(numtmp, NULL, 16); + break; + } + XDEBUG_BREAK_INTENTIONALLY_MISSING + + default: + i=0; + while (source < end && *source >= '0' && *source <= '7' && i<3) { + numtmpi++ = *source++; + } + if (i) { + numtmpi='\0'; + *target++=(char)strtol(numtmp, NULL, 8); + nlen-=i; + source--; + } else { + *target++=*source; + nlen--; + } + } + } else { + *target++=*source; + } + } + + if (nlen != 0) { + *target='\0'; + } + + *len = nlen; +} + +zend_ulong xdebug_get_pid(void) +{ +#ifndef ZTS + return (zend_ulong) getpid(); +#else +# ifdef _WIN32 + return (zend_ulong) GetCurrentThreadId(); +# else + return (zend_ulong) pthread_self(); +# endif +#endif +} + +void xdebug_setcookie(const char *name, int name_len, char *value, int value_len, time_t expires, const char *path, int path_len, const char *domain, int domain_len, int secure, int url_encode, int httponly) +{ + zend_string *name_s = name ? zend_string_init(name, name_len, 0) : NULL; + zend_string *value_s = value ? zend_string_init(value, value_len, 0) : NULL; + zend_string *path_s = path ? zend_string_init(path, path_len, 0) : NULL; + zend_string *domain_s = domain ? zend_string_init(domain, domain_len, 0) : NULL; + zend_string *samesite_s = zend_string_init("Lax", sizeof("Lax") - 1, 0); + + php_setcookie(name_s, value_s, expires, path_s, domain_s, secure, httponly, samesite_s, url_encode); + + zend_string_release(samesite_s); + name ? zend_string_release(name_s) : 0; + value ? zend_string_release(value_s) : 0; + path ? zend_string_release(path_s) : 0; + domain ? zend_string_release(domain_s) : 0; +} + +char *xdebug_get_compiled_variable_name(zend_op_array *op_array, uint32_t var, int *cv_len) +{ + zend_string *cv = NULL; + cv = zend_get_compiled_variable_name(op_array, var); + *cv_len = cv->len; + + return cv->val; +} + +#ifdef ZEND_HASH_GET_APPLY_COUNT /* PHP 7.2 or earlier recursion protection */ +zend_bool xdebug_zend_hash_is_recursive(HashTable* ht) +{ + return (ZEND_HASH_GET_APPLY_COUNT(ht) > 0); +} + +zend_bool xdebug_zend_hash_apply_protection_begin(HashTable* ht) +{ + if (!ht) { + return 1; + } + if (ZEND_HASH_GET_APPLY_COUNT(ht) > 0) { + return 0; + } + if (ZEND_HASH_APPLY_PROTECTION(ht)) { + ZEND_HASH_INC_APPLY_COUNT(ht); + } + return 1; +} + +zend_bool xdebug_zend_hash_apply_protection_end(HashTable* ht) +{ + if (!ht) { + return 1; + } + if (ZEND_HASH_GET_APPLY_COUNT(ht) == 0) { + return 0; + } + if (ZEND_HASH_APPLY_PROTECTION(ht)) { + ZEND_HASH_DEC_APPLY_COUNT(ht); + } + return 1; +} +#else /* PHP 7.3 or later */ +zend_bool xdebug_zend_hash_is_recursive(HashTable* ht) +{ + return GC_IS_RECURSIVE(ht); +} + +zend_bool xdebug_zend_hash_apply_protection_begin(zend_array* ht) +{ + if (GC_IS_RECURSIVE(ht)) { + return 0; + } + if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { + GC_PROTECT_RECURSION(ht); + } + return 1; +} + +zend_bool xdebug_zend_hash_apply_protection_end(zend_array* ht) +{ + if (!GC_IS_RECURSIVE(ht)) { + return 0; + } + if (!(GC_FLAGS(ht) & GC_IMMUTABLE)) { + GC_UNPROTECT_RECURSION(ht); + } + return 1; +} +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/compat.h
Added
@@ -0,0 +1,80 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __HAVE_XDEBUG_COMPAT_H__ +#define __HAVE_XDEBUG_COMPAT_H__ + +#include "lib/php-header.h" +#include "str.h" + +#include "ext/standard/head.h" +#include "ext/standard/php_var.h" +#define xdebug_php_var_dump php_var_dump + +char *xdebug_str_to_str(char *haystack, size_t length, const char *needle, size_t needle_len, const char *str, size_t str_len, size_t *new_len); + +unsigned char *xdebug_base64_encode(unsigned char *data, size_t data_len, size_t *new_len); +unsigned char *xdebug_base64_decode(unsigned char *data, size_t data_len, size_t *new_len); + +zend_string *xdebug_addslashes(zend_string *str); +void xdebug_stripcslashes(char *string, int *new_len); + +zend_ulong xdebug_get_pid(void); + +void xdebug_setcookie(const char *name, int name_len, char *value, int value_len, time_t expires, const char *path, int path_len, const char *domain, int domain_len, int secure, int url_encode, int httponly); +char *xdebug_get_compiled_variable_name(zend_op_array *op_array, uint32_t var, int *cv_len); + +/* Recursion protection is done differently from PHP 7.3 onwards */ +zend_bool xdebug_zend_hash_is_recursive(HashTable* ht); +zend_bool xdebug_zend_hash_apply_protection_begin(HashTable* ht); +zend_bool xdebug_zend_hash_apply_protection_end(HashTable* ht); + +# define XDEBUG_MAKE_STD_ZVAL(zv) \ + zv = ecalloc(sizeof(zval), 1); + +# define HASH_KEY_SIZEOF(k) (sizeof(k) - 1) +# define HASH_KEY_STRLEN(k) (strlen(k)) +# define HASH_KEY_IS_NUMERIC(k) ((k) == NULL) +# define HASH_APPLY_KEY_VAL(k) (k)->val +# define HASH_APPLY_KEY_LEN(k) (k)->len + 1 + +# define STR_NAME_VAL(k) (k)->val +# define STR_NAME_LEN(k) (k)->len + +# if defined (__GNUC__) +# define XDEBUG_GNUC_CHECK_VERSION(major, minor) \ + ((__GNUC__ > (major)) || \ + ((__GNUC__ == (major)) && (__GNUC_MINOR__ >= (minor)))) +# else +# define XDEBUG_GNUC_CHECK_VERSION(major, minor) 0 +# endif + +# if XDEBUG_GNUC_CHECK_VERSION(7, 0) +# define XDEBUG_BREAK_INTENTIONALLY_MISSING __attribute__ ((fallthrough)); +# else +# define XDEBUG_BREAK_INTENTIONALLY_MISSING +# endif + +# if XDEBUG_GNUC_CHECK_VERSION(2, 7) || __has_attribute(format) +# define XDEBUG_ATTRIBUTE_FORMAT(type, idx, first) __attribute__ ((format(type, idx, first))) +# else +# define XDEBUG_ATTRIBUTE_FORMAT(type, idx, first) +# endif + +#define XDEBUG_OPCODE_HANDLER_ARGS zend_execute_data *execute_data +#define XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU execute_data + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/crc32.c
Changed
(renamed from xdebug-3.1.5/src/lib/crc32.c)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/crc32.h
Changed
(renamed from xdebug-3.1.5/src/lib/crc32.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/file.c
Added
@@ -0,0 +1,201 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2021 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "php_xdebug.h" +#include "lib_private.h" +#include "log.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +#include "file.h" + +void xdebug_file_init(xdebug_file *xf) +{ + xf->type = XDEBUG_FILE_TYPE_NULL; + xf->fp.normal = NULL; +#if HAVE_XDEBUG_ZLIB + xf->fp.gz = NULL; +#endif + xf->name = NULL; +} + +xdebug_file *xdebug_file_ctor(void) +{ + xdebug_file *tmp = xdmalloc(sizeof(xdebug_file)); + xdebug_file_init(tmp); + + return tmp; +} + +void xdebug_file_deinit(xdebug_file *xf) +{ + xf->type = XDEBUG_FILE_TYPE_NULL; + xf->fp.normal = NULL; +#if HAVE_XDEBUG_ZLIB + xf->fp.gz = NULL; +#endif + xdfree(xf->name); +} + +void xdebug_file_dtor(xdebug_file *xf) +{ + xdebug_file_deinit(xf); + xdfree(xf); +} + +int xdebug_file_open(xdebug_file *file, const char *filename, const char *extension, const char *mode) +{ + if (XINI_LIB(use_compression)) { +#ifdef HAVE_XDEBUG_ZLIB + FILE *tmp_file; + char *combined_extension; + + /* Can't use profiler append with compression */ + if (strcmp(mode, "ab") == 0) { + xdebug_log_ex( + XLOG_CHAN_CONFIG, XLOG_WARN, "ZLIB-A", + "Cannot append to profiling file while file compression is turned on. Falling back to creating an uncompressed file" + ); + goto uncompressed; + } + + combined_extension = extension ? xdebug_sprintf("%s.gz", extension) : xdstrdup("gz"); + tmp_file = xdebug_fopen((char*) filename, mode, combined_extension, &(file->name)); + xdfree(combined_extension); + + if (!tmp_file) { + return 0; + } + + file->type = XDEBUG_FILE_TYPE_GZ; + file->fp.normal = tmp_file; + file->fp.gz = gzdopen(fileno(tmp_file), mode); + + if (!file->fp.gz) { + fclose(tmp_file); + return 0; + } + + return 1; +#else + char *combined_extension; + + combined_extension = extension ? xdebug_sprintf("%s.gz", extension) : xdstrdup("gz"); + xdebug_log_ex( + XLOG_CHAN_CONFIG, XLOG_WARN, "NOZLIB", + "Cannot create the compressed file '%s.%s', because support for zlib has not been compiled in. Falling back to '%s%s%s'", + filename, combined_extension, + filename, extension ? "." : "", extension ? extension : "" + ); + xdfree(combined_extension); +#endif + } + +#ifdef HAVE_XDEBUG_ZLIB +uncompressed: +#endif + file->type = XDEBUG_FILE_TYPE_NORMAL; + file->fp.normal = xdebug_fopen((char*) filename, mode, extension, &(file->name)); + + if (!file->fp.normal) { + return 0; + } + + return 1; +} + +int XDEBUG_ATTRIBUTE_FORMAT(printf, 2, 3) xdebug_file_printf(xdebug_file *file, const char *fmt, ...) +{ + va_list argv; + + switch (file->type) { + case XDEBUG_FILE_TYPE_NORMAL: + va_start(argv, fmt); + vfprintf(file->fp.normal, fmt, argv); + va_end(argv); + break; +#if HAVE_XDEBUG_ZLIB + case XDEBUG_FILE_TYPE_GZ: { + xdebug_str formatted_string = XDEBUG_STR_INITIALIZER; + + va_start(argv, fmt); + xdebug_str_add_va_fmt(&formatted_string, fmt, argv); + va_end(argv); + + gzwrite(file->fp.gz, formatted_string.d, formatted_string.l); + + xdebug_str_destroy(&formatted_string); + break; + } +#endif + default: + xdebug_log_ex(XLOG_CHAN_BASE, XLOG_CRIT, "FTYPE", "Unknown file type used with '%s'", file->name); + return 0; + } + + return 1; +} + +int xdebug_file_flush(xdebug_file *file) +{ + switch (file->type) { + case XDEBUG_FILE_TYPE_NORMAL: + return fflush(file->fp.normal); +#if HAVE_XDEBUG_ZLIB + case XDEBUG_FILE_TYPE_GZ: + return gzflush(file->fp.gz, Z_FULL_FLUSH); +#endif + default: + xdebug_log_ex(XLOG_CHAN_BASE, XLOG_CRIT, "FTYPE", "Unknown file type used with '%s'", file->name); + return EOF; + } +} + +int xdebug_file_close(xdebug_file *file) +{ + switch (file->type) { + case XDEBUG_FILE_TYPE_NORMAL: + return fclose(file->fp.normal); +#if HAVE_XDEBUG_ZLIB + case XDEBUG_FILE_TYPE_GZ: { + int gzret; + + gzret = gzclose(file->fp.gz); + fclose(file->fp.normal); + + return gzret; + } +#endif + default: + xdebug_log_ex(XLOG_CHAN_BASE, XLOG_CRIT, "FTYPE", "Unknown file type used with '%s'", file->name); + return EOF; + } +} + +size_t xdebug_file_write(const void *ptr, size_t size, size_t nmemb, xdebug_file *file) +{ + switch (file->type) { + case XDEBUG_FILE_TYPE_NORMAL: + return fwrite(ptr, size, nmemb, file->fp.normal); +#if HAVE_XDEBUG_ZLIB + case XDEBUG_FILE_TYPE_GZ: + return gzfwrite(ptr, size, nmemb, file->fp.gz); +#endif + default: + xdebug_log_ex(XLOG_CHAN_BASE, XLOG_CRIT, "FTYPE", "Unknown file type used with '%s'", file->name); + return EOF; + } +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/file.h
Changed
(renamed from xdebug-3.1.5/src/lib/file.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/hash.c
Changed
(renamed from xdebug-3.1.5/src/lib/hash.c)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/hash.h
Changed
(renamed from xdebug-3.1.5/src/lib/hash.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/headers.c
Changed
(renamed from xdebug-3.1.5/src/lib/headers.c)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/headers.h
Changed
(renamed from xdebug-3.1.5/src/lib/headers.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/lib.c
Added
@@ -0,0 +1,767 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "php_xdebug.h" + +#include "headers.h" + +#include "lib_private.h" +#include "log.h" + +extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); + +void xdebug_init_library_globals(xdebug_library_globals_t *xg) +{ + xg->headers = NULL; + xg->mode = 0xFFFFFFFF; + xg->mode_from_environment = 0; + + xg->log_file = 0; + + xg->active_execute_data = NULL; + xg->opcode_handlers_set = xdebug_set_create(256); + memset(xg->original_opcode_handlers, 0, sizeof(xg->original_opcode_handlers)); + memset(xg->opcode_multi_handlers, 0, sizeof(xg->opcode_multi_handlers)); + + XINI_LIB(log_level) = 0; + xg->diagnosis_buffer = NULL; +} + + +void xdebug_library_zend_startup(void) +{ + xdebug_lib_zend_startup_overload_sapi_headers(); +} + +void xdebug_library_zend_shutdown(void) +{ + xdebug_lib_zend_shutdown_restore_sapi_headers(); +} + + +void xdebug_library_minit(void) +{ + xdebug_set_opcode_multi_handler(ZEND_ASSIGN); + xdebug_set_opcode_multi_handler(ZEND_ASSIGN_DIM); + xdebug_set_opcode_multi_handler(ZEND_ASSIGN_OBJ); + xdebug_set_opcode_multi_handler(ZEND_ASSIGN_STATIC_PROP); + xdebug_set_opcode_multi_handler(ZEND_QM_ASSIGN); + xdebug_set_opcode_multi_handler(ZEND_INCLUDE_OR_EVAL); +} + +static void xdebug_multi_opcode_handler_dtor(xdebug_multi_opcode_handler_t *ptr) +{ + if (ptr->next) { + xdebug_multi_opcode_handler_dtor(ptr->next); + } + xdfree(ptr); +} + +void xdebug_library_mshutdown(void) +{ + int i; + + /* Restore all opcode handlers that we have set */ + for (i = 0; i < 256; i++) { + if (XG_LIB(opcode_multi_handlers)i != NULL) { + xdebug_multi_opcode_handler_dtor(XG_LIB(opcode_multi_handlers)i); + } + xdebug_unset_opcode_handler(i); + } + + xdebug_set_free(XG_LIB(opcode_handlers_set)); +} + +void xdebug_library_rinit(void) +{ + XG_LIB(diagnosis_buffer) = xdebug_str_new(); + xdebug_open_log(); + + XG_LIB(headers) = xdebug_llist_alloc(xdebug_llist_string_dtor); + + XG_LIB(dumped) = 0; + XG_LIB(do_collect_errors) = 0; +} + +void xdebug_library_post_deactivate(void) +{ + /* Clean up collected headers */ + xdebug_llist_destroy(XG_LIB(headers), NULL); + XG_LIB(headers) = NULL; + + + xdebug_close_log(); + xdebug_str_free(XG_LIB(diagnosis_buffer)); +} + + +void xdebug_disable_opcache_optimizer(void) +{ + zend_string *key = zend_string_init(ZEND_STRL("opcache.optimization_level"), 1); + zend_string *value = zend_string_init(ZEND_STRL("0"), 1); + + zend_alter_ini_entry(key, value, ZEND_INI_SYSTEM, ZEND_INI_STAGE_STARTUP); + + zend_string_release(key); + zend_string_release(value); +} + + +static int xdebug_lib_set_mode_item(const char *mode, int len) +{ + if (strncmp(mode, "off", len) == 0) { + XG_LIB(mode) |= XDEBUG_MODE_OFF; + return 1; + } + if (strncmp(mode, "develop", len) == 0) { + XG_LIB(mode) |= XDEBUG_MODE_DEVELOP; + return 1; + } + if (strncmp(mode, "coverage", len) == 0) { + XG_LIB(mode) |= XDEBUG_MODE_COVERAGE; + return 1; + } + if (strncmp(mode, "debug", len) == 0) { + XG_LIB(mode) |= XDEBUG_MODE_STEP_DEBUG; + return 1; + } + if (strncmp(mode, "gcstats", len) == 0) { + XG_LIB(mode) |= XDEBUG_MODE_GCSTATS; + return 1; + } + if (strncmp(mode, "profile", len) == 0) { + XG_LIB(mode) |= XDEBUG_MODE_PROFILING; + return 1; + } + if (strncmp(mode, "trace", len) == 0) { + XG_LIB(mode) |= XDEBUG_MODE_TRACING; + return 1; + } + + return 0; +} + +static int xdebug_lib_set_mode_from_setting(const char *mode) +{ + const char *mode_ptr = mode; + char *comma = NULL; + int errors = 0; + + XG_LIB(mode) = 0; + + comma = strchr(mode_ptr, ','); + while (comma) { + errors += !xdebug_lib_set_mode_item(mode_ptr, comma - mode_ptr); + mode_ptr = comma + 1; + while (*mode_ptr == ' ') { + mode_ptr++; + } + comma = strchr(mode_ptr, ','); + } + errors += !xdebug_lib_set_mode_item(mode_ptr, strlen(mode_ptr)); + + return !errors; +} + +int xdebug_lib_set_mode(const char *mode) +{ + char *config = getenv("XDEBUG_MODE"); + int result = 0; + + /* XDEBUG_MODE environment variable */ + if (config && strlen(config)) { + result = xdebug_lib_set_mode_from_setting(config); + + if (!result) { + xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_CRIT, "ENVMODE", "Invalid mode '%s' set for 'XDEBUG_MODE' environment variable, fall back to 'xdebug.mode' configuration setting", config); + } else { + XG_LIB(mode_from_environment) = 1; + return result; + } + } + + /* 'xdebug.mode' configuration setting */ + result = xdebug_lib_set_mode_from_setting(mode); + + if (!result) { + xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_CRIT, "MODE", "Invalid mode '%s' set for 'xdebug.mode' configuration setting", mode); + } + + return result; +} + +int xdebug_lib_get_start_with_request(void) +{ + return XG_LIB(start_with_request); +} + +int xdebug_lib_set_start_with_request(char *value) +{ + if (strcmp(value, "default") == 0) { + XG_LIB(start_with_request) = XDEBUG_START_WITH_REQUEST_DEFAULT; + return 1; + } + if (strcmp(value, "yes") == 0 || strcmp(value, "1") == 0) { + XG_LIB(start_with_request) = XDEBUG_START_WITH_REQUEST_YES; + return 1; + } + if (strcmp(value, "no") == 0 || value0 == '\0') { + XG_LIB(start_with_request) = XDEBUG_START_WITH_REQUEST_NO; + return 1; + } + if (strcmp(value, "trigger") == 0) { + XG_LIB(start_with_request) = XDEBUG_START_WITH_REQUEST_TRIGGER; + return 1; + } + + return 0; +} + +int xdebug_lib_start_with_request(int for_mode) +{ + if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_YES) { + return 1; + } + + if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_DEFAULT) { + if (for_mode == XDEBUG_MODE_PROFILING && XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + return 1; + } + } + + return 0; +} + +int xdebug_lib_never_start_with_request(void) +{ + if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_NO) { + return 1; + } + + return 0; +} + + +int xdebug_lib_get_start_upon_error(void) +{ + return XG_LIB(start_upon_error); +} + +int xdebug_lib_set_start_upon_error(char *value) +{ + if (strcmp(value, "default") == 0) { + XG_LIB(start_upon_error) = XDEBUG_START_UPON_ERROR_DEFAULT; + return 1; + } + if (strcmp(value, "yes") == 0 || strcmp(value, "1") == 0) { + XG_LIB(start_upon_error) = XDEBUG_START_UPON_ERROR_YES; + return 1; + } + if (strcmp(value, "no") == 0 || value0 == '\0') { + XG_LIB(start_upon_error) = XDEBUG_START_UPON_ERROR_NO; + return 1; + } + + return 0; +} + +int xdebug_lib_start_upon_error(void) +{ + if (XG_LIB(start_upon_error) == XDEBUG_START_UPON_ERROR_YES) { + return 1; + } + + return 0; +} + +const char *xdebug_lib_mode_from_value(int mode) +{ + switch (mode) { + case XDEBUG_MODE_DEVELOP: + return "develop"; + case XDEBUG_MODE_COVERAGE: + return "coverage"; + case XDEBUG_MODE_STEP_DEBUG: + return "debug"; + case XDEBUG_MODE_GCSTATS: + return "gcstats"; + case XDEBUG_MODE_PROFILING: + return "profile"; + case XDEBUG_MODE_TRACING: + return "trace"; + default: + return "?"; + } +} + +static const char *find_in_globals(const char *element) +{ + zval *trigger_val = NULL; + const char *env_value = getenv(element); + + if (env_value) { + return env_value; + } + + if ( + ( + (trigger_val = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_ENV), element, strlen(element))) != NULL + ) || ( + (trigger_val = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_GET), element, strlen(element))) != NULL + ) || ( + (trigger_val = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_POST), element, strlen(element))) != NULL + ) || ( + (trigger_val = zend_hash_str_find(Z_ARR(PG(http_globals)TRACK_VARS_COOKIE), element, strlen(element))) != NULL + ) + ) { + return Z_STRVAL_P(trigger_val); + } + + return NULL; +} + +int xdebug_lib_has_shared_secret(void) +{ + char *shared_secret = XINI_LIB(trigger_value); + + if (shared_secret != NULL && shared_secret0 != '\0') { + return 1; + } + + return 0; +} + +static int does_shared_secret_match_single(int mode, const char *trimmed_trigger_value, const char *trimmed_shared_secret, char **found_trigger_value) +{ + if (strcmp(trimmed_shared_secret, trimmed_trigger_value) == 0) { + xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_DEBUG, "TRGSEC-MATCH", "The trigger value '%s' matched the shared secret '%s' for mode '%s'", trimmed_trigger_value, trimmed_shared_secret, xdebug_lib_mode_from_value(mode)); + + if (found_trigger_value != NULL) { + *found_trigger_value = xdstrdup(trimmed_trigger_value); + } + + return 1; + } + + return 0; +} + +static int does_shared_secret_match(int mode, const char *trigger_name, const char *trigger_value, char **found_trigger_value) +{ + int retval = 0; + const char *shared_secret = XINI_LIB(trigger_value); + char *trimmed_trigger_value = xdebug_trim(trigger_value); + + /* Check we have a multi-value-shared secret setting */ + if (strchr(shared_secret, ',') != NULL) { + int i; + xdebug_arg *values = xdebug_arg_ctor(); + + xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_DEBUG, "TRGSEC-MULT", "The shared secret (xdebug.trigger_value) is multi-value for mode '%s'", xdebug_lib_mode_from_value(mode)); + + xdebug_explode(",", shared_secret, values, -1); + + for (i = 0; i < values->c; i++) { + char *trimmed_shared_secret = xdebug_trim(values->argsi); + + retval = does_shared_secret_match_single(mode, trimmed_trigger_value, trimmed_shared_secret, found_trigger_value); + + xdfree(trimmed_shared_secret); + + /* Jump out of the loop if we found a match */ + if (retval != 0) { + break; + } + } + + xdebug_arg_dtor(values); + + if (retval == 0) { + xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "TRGSEC-MNO", "The trigger value '%s', as set through '%s', did not match any of the shared secrets (xdebug.trigger_value) for mode '%s'", trimmed_trigger_value, trigger_name, xdebug_lib_mode_from_value(mode)); + } + } else { + char *trimmed_shared_secret = xdebug_trim(shared_secret); + + retval = does_shared_secret_match_single(mode, trimmed_trigger_value, trimmed_shared_secret, found_trigger_value); + + xdfree(trimmed_shared_secret); + + if (retval == 0) { + xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "TRGSEC-NO", "The trigger value '%s', as set through '%s', did not match the shared secret (xdebug.trigger_value) for mode '%s'", trimmed_trigger_value, trigger_name, xdebug_lib_mode_from_value(mode)); + } + } + + xdfree(trimmed_trigger_value); + + return retval; +} + +static int trigger_enabled(int for_mode, char **found_trigger_value) +{ + const char *trigger_value = NULL; + const char *trigger_name = "XDEBUG_TRIGGER"; + + xdebug_log(XLOG_CHAN_CONFIG, XLOG_DEBUG, "Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode '%s'", xdebug_lib_mode_from_value(for_mode)); + + /* First we check for the generic 'XDEBUG_TRIGGER' option */ + trigger_value = find_in_globals(trigger_name); + + /* If not found, we fall back to the per-mode name for backwards compatibility reasons */ + if (!trigger_value) { + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING) && (for_mode == XDEBUG_MODE_PROFILING)) { + trigger_name = "XDEBUG_PROFILE"; + } else if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) && (for_mode == XDEBUG_MODE_TRACING)) { + trigger_name = "XDEBUG_TRACE"; + } else if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG) && (for_mode == XDEBUG_MODE_STEP_DEBUG)) { + trigger_name = "XDEBUG_SESSION"; + } + + if (trigger_name) { + xdebug_log(XLOG_CHAN_CONFIG, XLOG_INFO, "Trigger value for 'XDEBUG_TRIGGER' not found, falling back to '%s'", trigger_name); + trigger_value = find_in_globals(trigger_name); + } + } + + if (!trigger_value) { + xdebug_log(XLOG_CHAN_CONFIG, XLOG_INFO, "Trigger value for '%s' not found, so not activating", trigger_name); + + if (found_trigger_value != NULL) { + *found_trigger_value = NULL; + } + return 0; + } + + /* If there is no configured shared secret trigger, always trigger */ + if (!xdebug_lib_has_shared_secret()) { + xdebug_log(XLOG_CHAN_CONFIG, XLOG_INFO, "No shared secret: Activating"); + if (found_trigger_value != NULL) { + *found_trigger_value = xdstrdup(trigger_value); + } + return 1; + } + + /* Check if the configured trigger value matches the one found in the + * trigger element */ + if (does_shared_secret_match(for_mode, trigger_name, trigger_value, found_trigger_value)) { + return 1; + } + + return 0; +} + +static int is_mode_trigger_and_enabled(int for_mode, int force_trigger, char **found_trigger_value) +{ + if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_TRIGGER) { + return force_trigger || trigger_enabled(for_mode, found_trigger_value); + } + + if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_DEFAULT) { + if ( + XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG) || + XDEBUG_MODE_IS(XDEBUG_MODE_TRACING) + ) { + return force_trigger || trigger_enabled(for_mode, found_trigger_value); + } + } + + return 0; +} + +/* Returns 1 if the mode is 'trigger', or 'default', where the default mode for + * a feature is to trigger, and the trigger is present. If found_trigger_value + * is not NULL, then it is set to the found trigger value */ +int xdebug_lib_start_with_trigger(int for_mode, char **found_trigger_value) +{ + return is_mode_trigger_and_enabled(for_mode, 0, found_trigger_value); +} + +/* Returns 1 if the mode is 'trigger', or 'default', where the default mode for + * a feature is to trigger. Does not check whether a trigger is present. */ +int xdebug_lib_start_if_mode_is_trigger(int for_mode) +{ + return is_mode_trigger_and_enabled(for_mode, 1, NULL); +} + + +function_stack_entry *xdebug_get_stack_frame(int nr) +{ + if (!XG_BASE(stack)) { + return NULL; + } + if (nr < 0 || nr >= XDEBUG_VECTOR_COUNT(XG_BASE(stack))) { + return NULL; + } + + return xdebug_vector_element_get(XG_BASE(stack), XDEBUG_VECTOR_COUNT(XG_BASE(stack)) - nr - 1); +} + +static void xdebug_used_var_hash_from_llist_dtor(void *data) +{ + xdebug_str *var_name = (xdebug_str*) data; + + xdebug_str_free(var_name); +} + +static int xdebug_compare_le_xdebug_str(const void *le1, const void *le2) +{ + return strcmp( + ((xdebug_str *) XDEBUG_LLIST_VALP(*(xdebug_llist_element **) le1))->d, + ((xdebug_str *) XDEBUG_LLIST_VALP(*(xdebug_llist_element **) le2))->d + ); +} + +xdebug_hash* xdebug_declared_var_hash_from_llist(xdebug_llist *list) +{ + xdebug_hash *tmp; + xdebug_llist_element *le; + xdebug_str *var_name; + + tmp = xdebug_hash_alloc_with_sort(32, xdebug_used_var_hash_from_llist_dtor, xdebug_compare_le_xdebug_str); + for (le = XDEBUG_LLIST_HEAD(list); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { + var_name = (xdebug_str*) XDEBUG_LLIST_VALP(le); + xdebug_hash_add(tmp, var_name->d, var_name->l, xdebug_str_copy(var_name)); + } + + return tmp; +} + +void xdebug_lib_set_active_data(zend_execute_data *execute_data) +{ + XG_LIB(active_execute_data) = execute_data; + XG_LIB(active_object) = execute_data ? &execute_data->This : NULL; +} + +void xdebug_lib_set_active_stack_entry(function_stack_entry *fse) +{ + XG_LIB(active_stack_entry) = fse; +} + +void xdebug_lib_set_active_symbol_table(HashTable *symbol_table) +{ + XG_LIB(active_symbol_table) = symbol_table; +} + +int xdebug_lib_has_active_data(void) +{ + return !!XG_LIB(active_execute_data); +} + +int xdebug_lib_has_active_function(void) +{ + return !!XG_LIB(active_execute_data)->func; +} + +int xdebug_lib_has_active_object(void) +{ + return !!XG_LIB(active_object); +} + +int xdebug_lib_has_active_symbol_table(void) +{ + return !!XG_LIB(active_symbol_table); +} + +zend_execute_data *xdebug_lib_get_active_data(void) +{ + return XG_LIB(active_execute_data); +} + +zend_op_array *xdebug_lib_get_active_func_oparray(void) +{ + return &XG_LIB(active_execute_data)->func->op_array; +} + +function_stack_entry *xdebug_lib_get_active_stack_entry(void) +{ + return XG_LIB(active_stack_entry); +} + +HashTable *xdebug_lib_get_active_symbol_table(void) +{ + return XG_LIB(active_symbol_table); +} + +zval *xdebug_lib_get_active_object(void) +{ + return XG_LIB(active_object); +} + +int xdebug_isset_opcode_handler(int opcode) +{ + return xdebug_set_in(XG_LIB(opcode_handlers_set), opcode); +} + +void xdebug_set_opcode_handler(int opcode, user_opcode_handler_t handler) +{ + if (xdebug_isset_opcode_handler(opcode)) { + abort(); + } + XG_LIB(original_opcode_handlersopcode) = zend_get_user_opcode_handler(opcode); + xdebug_set_add(XG_LIB(opcode_handlers_set), opcode); + zend_set_user_opcode_handler(opcode, handler); +} + +static int xdebug_opcode_multi_handler(zend_execute_data *execute_data) +{ + const zend_op *cur_opcode = execute_data->opline; + + xdebug_multi_opcode_handler_t *handler_ptr = XG_LIB(opcode_multi_handlerscur_opcode->opcode); + + while (handler_ptr) { + handler_ptr->handler(execute_data); + handler_ptr = handler_ptr->next; + } + + return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); +} + +void xdebug_set_opcode_multi_handler(int opcode) +{ + if (xdebug_isset_opcode_handler(opcode)) { + abort(); + } + XG_LIB(original_opcode_handlersopcode) = zend_get_user_opcode_handler(opcode); + xdebug_set_add(XG_LIB(opcode_handlers_set), opcode); + zend_set_user_opcode_handler(opcode, xdebug_opcode_multi_handler); +} + +void xdebug_register_with_opcode_multi_handler(int opcode, user_opcode_handler_t handler) +{ + xdebug_multi_opcode_handler_t *ptr; + xdebug_multi_opcode_handler_t *tmp = xdmalloc(sizeof(xdebug_multi_opcode_handler_t)); + tmp->handler = handler; + tmp->next = NULL; + + if (!xdebug_isset_opcode_handler(opcode)) { + abort(); + } + + if (XG_LIB(opcode_multi_handlers)opcode == NULL) { + XG_LIB(opcode_multi_handlers)opcode = tmp; + return; + } + + ptr = XG_LIB(opcode_multi_handlers)opcode; + while (ptr->next) { + ptr = ptr->next; + } + + ptr->next = tmp; +} + +void xdebug_unset_opcode_handler(int opcode) +{ + if (xdebug_set_in(XG_LIB(opcode_handlers_set), opcode)) { + zend_set_user_opcode_handler(opcode, XG_LIB(original_opcode_handlersopcode)); + } +} + +int xdebug_call_original_opcode_handler_if_set(int opcode, XDEBUG_OPCODE_HANDLER_ARGS) +{ + if (xdebug_isset_opcode_handler(opcode)) { + user_opcode_handler_t handler = XG_LIB(original_opcode_handlersopcode); + + if (handler) { + return handler(XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); + } + } + + return ZEND_USER_OPCODE_DISPATCH; +} + +/* Does not duplicate the return value, don't free. Return NULL if it's + * not-set, or an empty string */ +char *xdebug_lib_get_output_dir(void) +{ + char *output_dir = XINI_LIB(output_dir); + + if (output_dir == NULL || output_dir0 == '\0') { + return NULL; + } + + return output_dir; +} + +void xdebug_llist_string_dtor(void *dummy, void *elem) +{ + char *s = elem; + + if (s) { + xdfree(s); + } +} + +char* xdebug_wrap_location_around_function_name(const char *prefix, zend_op_array *opa, char *fname) +{ + return xdebug_sprintf( + "%s{%s:%s:%d-%d}", + fname, + prefix, + opa->filename->val, + opa->line_start, + opa->line_end + ); +} + +char* xdebug_wrap_closure_location_around_function_name(zend_op_array *opa, char *fname) +{ + xdebug_str tmp = XDEBUG_STR_INITIALIZER; + char *tmp_loc_info; + + if (fnamestrlen(fname) - 1 != '}') { + xdebug_str_add(&tmp, fname, 0); + + return tmp.d; + } + + xdebug_str_addl(&tmp, fname, strlen(fname) - 1, 0); + + tmp_loc_info = xdebug_sprintf( + ":%s:%d-%d}", + opa->filename->val, + opa->line_start, + opa->line_end + ); + xdebug_str_add(&tmp, tmp_loc_info, 1); + + return tmp.d; +} + +static void xdebug_declared_var_dtor(void *dummy, void *elem) +{ + xdebug_str *s = (xdebug_str*) elem; + + xdebug_str_free(s); +} + +void xdebug_lib_register_compiled_variables(function_stack_entry *fse, zend_op_array *op_array) +{ + unsigned int i = 0; + + if (!fse->declared_vars) { + fse->declared_vars = xdebug_llist_alloc(xdebug_declared_var_dtor); + } + + if (!op_array->vars) { + return; + } + + /* gather used variables from compiled vars information */ + while (i < (unsigned int) op_array->last_var) { + xdebug_llist_insert_next(fse->declared_vars, XDEBUG_LLIST_TAIL(fse->declared_vars), xdebug_str_create(STR_NAME_VAL(op_array->varsi), STR_NAME_LEN(op_array->varsi))); + i++; + } +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/lib.h
Added
@@ -0,0 +1,324 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2021 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __XDEBUG_LIBRARY_H__ +#define __XDEBUG_LIBRARY_H__ + +#ifdef ZTS +# include "TSRM.h" +#endif + +#include "zend.h" +#include "zend_API.h" +#include "compat.h" + +typedef struct xdebug_var_name { + zend_string *name; + zval data; + int is_variadic; +} xdebug_var_name; + +#define XFUNC_UNKNOWN 0x00 +#define XFUNC_NORMAL 0x01 +#define XFUNC_STATIC_MEMBER 0x02 +#define XFUNC_MEMBER 0x03 + +#define XFUNC_INCLUDES 0x10 +#define XFUNC_EVAL 0x10 +#define XFUNC_INCLUDE 0x11 +#define XFUNC_INCLUDE_ONCE 0x12 +#define XFUNC_REQUIRE 0x13 +#define XFUNC_REQUIRE_ONCE 0x14 +#define XFUNC_MAIN 0x15 +#if PHP_VERSION_ID >= 80100 +# define XFUNC_FIBER 0x16 +#endif + +#define XFUNC_ZEND_PASS 0x20 + +#define XDEBUG_IS_NORMAL_FUNCTION(f) ((f)->type == XFUNC_NORMAL || (f)->type == XFUNC_STATIC_MEMBER || (f)->type == XFUNC_MEMBER) + +#define XDEBUG_REGISTER_LONG_CONSTANT(__c) REGISTER_LONG_CONSTANT(#__c, __c, CONST_CS|CONST_PERSISTENT) + +#define XDEBUG_NONE 0 +#define XDEBUG_JIT 1 +#define XDEBUG_REQ 2 + +#define XDEBUG_BREAK 1 +#define XDEBUG_STEP 2 + +#define XDEBUG_BUILT_IN 0 +#define XDEBUG_USER_DEFINED 1 + +#define XDEBUG_MAX_FUNCTION_LEN 1024 + +#define XDEBUG_TRACE_OPTION_APPEND 1 +#define XDEBUG_TRACE_OPTION_COMPUTERIZED 2 +#define XDEBUG_TRACE_OPTION_HTML 4 +#define XDEBUG_TRACE_OPTION_NAKED_FILENAME 8 + +#define XDEBUG_CC_OPTION_UNUSED 1 +#define XDEBUG_CC_OPTION_DEAD_CODE 2 +#define XDEBUG_CC_OPTION_BRANCH_CHECK 4 + +#define STATUS_STARTING 0 +#define STATUS_STOPPING 1 +#define STATUS_STOPPED 2 +#define STATUS_RUNNING 3 +#define STATUS_BREAK 4 + +#define REASON_OK 0 +#define REASON_ERROR 1 +#define REASON_ABORTED 2 +#define REASON_EXCEPTION 3 + +#define XDEBUG_CMDLOOP_NONBLOCK 0 +#define XDEBUG_CMDLOOP_BLOCK 1 + +#define XDEBUG_CMDLOOP_NONBAIL 0 +#define XDEBUG_CMDLOOP_BAIL 1 + +#define XDEBUG_ERROR_OK 0 +#define XDEBUG_ERROR_PARSE 1 +#define XDEBUG_ERROR_DUP_ARG 2 +#define XDEBUG_ERROR_INVALID_ARGS 3 +#define XDEBUG_ERROR_UNIMPLEMENTED 4 +#define XDEBUG_ERROR_COMMAND_UNAVAILABLE 5 + +#define XDEBUG_ERROR_CANT_OPEN_FILE 100 +#define XDEBUG_ERROR_STREAM_REDIRECT_FAILED 101 /* unused */ + +#define XDEBUG_ERROR_BREAKPOINT_NOT_SET 200 +#define XDEBUG_ERROR_BREAKPOINT_TYPE_NOT_SUPPORTED 201 +#define XDEBUG_ERROR_BREAKPOINT_INVALID 202 +#define XDEBUG_ERROR_BREAKPOINT_NO_CODE 203 +#define XDEBUG_ERROR_BREAKPOINT_INVALID_STATE 204 +#define XDEBUG_ERROR_NO_SUCH_BREAKPOINT 205 +#define XDEBUG_ERROR_EVALUATING_CODE 206 +#define XDEBUG_ERROR_INVALID_EXPRESSION 207 /* unused */ + +#define XDEBUG_ERROR_PROPERTY_NON_EXISTENT 300 +#define XDEBUG_ERROR_PROPERTY_NON_EXISTANT 300 /* compatibility typo */ +#define XDEBUG_ERROR_STACK_DEPTH_INVALID 301 +#define XDEBUG_ERROR_CONTEXT_INVALID 302 /* unused */ + +#define XDEBUG_ERROR_PROFILING_NOT_STARTED 800 + +#define XDEBUG_ERROR_ENCODING_NOT_SUPPORTED 900 + +typedef struct _xdebug_func { + zend_string *object_class; + zend_string *scope_class; + char *function; + int type; + int internal; +} xdebug_func; + +typedef struct xdebug_profile { + uint64_t nanotime; + uint64_t nanotime_mark; + long memory; + long mem_mark; + xdebug_llist *call_list; +} xdebug_profile; + +typedef struct _function_stack_entry { + /* function properties */ + xdebug_func function; + unsigned int function_nr; + unsigned short user_defined:1; + unsigned short level:15; + + /* argument properties */ + unsigned short varc; + xdebug_var_name *var; + zval *return_value; + xdebug_llist *declared_vars; + HashTable *symbol_table; + zend_execute_data *execute_data; + unsigned char is_variadic; + unsigned char arg_done; + + /* filter properties */ + unsigned char filtered_code_coverage; + unsigned char filtered_stack; + unsigned char filtered_tracing; + + /* location properties */ + int lineno; + zend_string *filename; + zend_string *include_filename; + + /* tracing properties */ + signed long memory; + signed long prev_memory; + uint64_t nanotime; + + /* profiling properties */ + xdebug_profile profile; + struct { + int lineno; + zend_string *filename; + char *funcname; + } profiler; + + /* misc properties */ + zend_op_array *op_array; +} function_stack_entry; + +function_stack_entry *xdebug_get_stack_frame(int nr); + + +xdebug_hash* xdebug_declared_var_hash_from_llist(xdebug_llist *list); +int xdebug_trigger_enabled(int setting, const char *var_name, char *var_value); + +typedef struct _xdebug_multi_opcode_handler_t xdebug_multi_opcode_handler_t; + +struct _xdebug_multi_opcode_handler_t +{ + user_opcode_handler_t handler; + xdebug_multi_opcode_handler_t *next; +}; + +typedef struct _xdebug_library_globals_t { + int mode; + int start_with_request; /* One of the XDEBUG_START_WITH_REQUEST_* constants */ + int start_upon_error; /* One of the XDEBUG_START_UPON_ERROR_* constants */ + int mode_from_environment; /* Keeps track whether the mode was set with XDEBUG_MODE for diagnostics purposes */ + + zend_execute_data *active_execute_data; + function_stack_entry *active_stack_entry; + HashTable *active_symbol_table; + zval *active_object; + + /* Headers */ + xdebug_llist *headers; + + zend_bool dumped; + + /* used for collection errors */ + zend_bool do_collect_errors; + + FILE *log_file; /* File handler for protocol log */ + zend_bool log_opened_message_sent; + char *log_open_timestring; + xdebug_str *diagnosis_buffer; + + user_opcode_handler_t original_opcode_handlers256; + xdebug_multi_opcode_handler_t *opcode_multi_handlers256; + xdebug_set *opcode_handlers_set; +} xdebug_library_globals_t; + +typedef struct _xdebug_library_settings_t { + char *requested_mode; + + char *output_dir; + char *trigger_value; + + char *file_link_format; + char *filename_format; + + /* Whether to use zlib compression for profiling and trace files, if ZLIB support + * is enabled */ + zend_bool use_compression; + + /* variable dumping limitation settings */ + zend_long display_max_children; + zend_long display_max_data; + zend_long display_max_depth; + + /* Logging settings */ + char *log; /* Filename to log protocol communication to */ + zend_long log_level; /* Log level XDEBUG_LOG_{ERR,WARN,INFO,DEBUG} */ +} xdebug_library_settings_t; + +void xdebug_init_library_globals(xdebug_library_globals_t *xg); + +void xdebug_library_zend_startup(void); +void xdebug_library_zend_shutdown(void); +void xdebug_library_minit(void); +void xdebug_library_mshutdown(void); +void xdebug_library_rinit(void); +void xdebug_library_post_deactivate(void); + +void xdebug_disable_opcache_optimizer(void); + +#define XDEBUG_MODE_OFF 0 +#define XDEBUG_MODE_DEVELOP 1<<0 +#define XDEBUG_MODE_COVERAGE 1<<1 +#define XDEBUG_MODE_STEP_DEBUG 1<<2 +#define XDEBUG_MODE_GCSTATS 1<<3 +#define XDEBUG_MODE_PROFILING 1<<4 +#define XDEBUG_MODE_TRACING 1<<5 +int xdebug_lib_set_mode(const char *mode); + +#define XDEBUG_MODE_IS_OFF() ((XG(globals.library.mode) == XDEBUG_MODE_OFF)) +#define XDEBUG_MODE_IS(v) ((XG(globals.library.mode) & (v)) ? 1 : 0) +#define RETURN_IF_MODE_IS_NOT(m) if (!XDEBUG_MODE_IS((m))) { return; } +#define RETURN_FALSE_IF_MODE_IS_NOT(m) if (!XDEBUG_MODE_IS((m))) { RETURN_FALSE; } +#define WARN_AND_RETURN_IF_MODE_IS_NOT(m) if (!XDEBUG_MODE_IS((m))) { php_error(E_NOTICE, "Functionality is not enabled"); return; } + +#define XDEBUG_START_WITH_REQUEST_DEFAULT 1 +#define XDEBUG_START_WITH_REQUEST_YES 2 +#define XDEBUG_START_WITH_REQUEST_NO 3 +#define XDEBUG_START_WITH_REQUEST_TRIGGER 4 +int xdebug_lib_set_start_with_request(char *value); +int xdebug_lib_start_with_request(int for_mode); +int xdebug_lib_start_with_trigger(int for_mode, char **found_trigger_value); +int xdebug_lib_start_if_mode_is_trigger(int for_mode); +int xdebug_lib_never_start_with_request(void); +int xdebug_lib_get_start_with_request(void); +int xdebug_lib_has_shared_secret(void); + +#define XDEBUG_START_UPON_ERROR_DEFAULT 1 +#define XDEBUG_START_UPON_ERROR_YES 2 +#define XDEBUG_START_UPON_ERROR_NO 3 +int xdebug_lib_set_start_upon_error(char *value); +int xdebug_lib_start_upon_error(void); +int xdebug_lib_get_start_upon_error(void); + +const char *xdebug_lib_mode_from_value(int mode); + +void xdebug_lib_set_active_data(zend_execute_data *execute_data); +void xdebug_lib_set_active_stack_entry(function_stack_entry *fse); +void xdebug_lib_set_active_symbol_table(HashTable *symbol_table); + +int xdebug_lib_has_active_data(void); +int xdebug_lib_has_active_function(void); +int xdebug_lib_has_active_object(void); +int xdebug_lib_has_active_symbol_table(void); + +zend_execute_data *xdebug_lib_get_active_data(void); +zend_op_array *xdebug_lib_get_active_func_oparray(void); +zval *xdebug_lib_get_active_object(void); +function_stack_entry *xdebug_lib_get_active_stack_entry(void); +HashTable *xdebug_lib_get_active_symbol_table(void); + +int xdebug_isset_opcode_handler(int opcode); +void xdebug_set_opcode_handler(int opcode, user_opcode_handler_t handler); +void xdebug_unset_opcode_handler(int opcode); +void xdebug_set_opcode_multi_handler(int opcode); +void xdebug_register_with_opcode_multi_handler(int opcode, user_opcode_handler_t handler); +int xdebug_call_original_opcode_handler_if_set(int opcode, XDEBUG_OPCODE_HANDLER_ARGS); + +char *xdebug_lib_get_output_dir(void); + +void xdebug_llist_string_dtor(void *dummy, void *elem); +char* xdebug_wrap_location_around_function_name(const char *prefix, zend_op_array *opa, char *fname); +char* xdebug_wrap_closure_location_around_function_name(zend_op_array *opa, char *fname); + +void xdebug_lib_register_compiled_variables(function_stack_entry *fse, zend_op_array *op_array); +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/lib_private.h
Changed
(renamed from xdebug-3.1.5/src/lib/lib_private.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/llist.c
Changed
(renamed from xdebug-3.1.5/src/lib/llist.c)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/llist.h
Changed
(renamed from xdebug-3.1.5/src/lib/llist.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/log.c
Added
@@ -0,0 +1,934 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "php_xdebug.h" +#include "ext/standard/info.h" + +#include "headers.h" + +#include "lib_private.h" +#include "log.h" +#include "var.h" + +char* xdebug_lib_docs_base(void) +{ + char *env = getenv("XDEBUG_DOCS_BASE"); + + if (env) { + return env; + } + + return (char*) "https://xdebug.org/docs/"; +} + +extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); + +const char *xdebug_level_msg_prefix11 = { + "C", "E", "", "W", "", "", "", "I", "", "", "D" +}; +const char *xdebug_log_prefix11 = { + "CRIT:", "ERR: ", "", "WARN: ", "", "", "", "INFO: ", "", "", "DEBUG: " +}; +const char *xdebug_log_prefix_emoji11 = { + "☠", "🛑 ", "", "⚠️ ", "", "", "", "🛈 ", "", "", "• " +}; +const char *xdebug_channel_msg_prefix8 = { + "CFG-", "LOG-", "DBG-", "GC-", "PROF-", "TRACE-", "COV-", "BASE-" +}; +const char *xdebug_channel_name8 = { + "Config ", "Log Files ", "Step Debug ", "GC Stats ", "Profiler ", "Tracing ", "Coverage ", "Base " +}; + +static inline int xdebug_internal_log(int channel, int log_level, const char *message) +{ + zend_ulong pid; + + if (!XG_LIB(log_file)) { + return 0; + } + + pid = xdebug_get_pid(); + + if (!XG_LIB(log_opened_message_sent) && XG_LIB(log_open_timestring)) { + XG_LIB(log_opened_message_sent) = 1; + + fprintf(XG_LIB(log_file), "" ZEND_ULONG_FMT " Log opened at %s\n", pid, XG_LIB(log_open_timestring)); + fflush(XG_LIB(log_file)); + xdfree(XG_LIB(log_open_timestring)); + XG_LIB(log_open_timestring) = NULL; + } + + fprintf( + XG_LIB(log_file), + "" ZEND_ULONG_FMT " %s%s%s\n", + pid, + xdebug_channel_namechannel, + xdebug_log_prefixlog_level, + message + ); + + fflush(XG_LIB(log_file)); + + return 1; +} + +#define TR_START "<tr><td class=\"e\">" +#define TR_END "</td></tr>\n" + +static inline void xdebug_diagnostic_log(int channel, int log_level, const char *error_code, const char *message) +{ + if (!XG_LIB(diagnosis_buffer) || log_level > XLOG_WARN) { + return; + } + + if (sapi_module.phpinfo_as_text) { + xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_channel_namechannel, 0); + xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_log_prefixlog_level, 0); + xdebug_str_add(XG_LIB(diagnosis_buffer), message, 0); + } else { + xdebug_str_add_const(XG_LIB(diagnosis_buffer), "<tr><td class=\"i\">"); + xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_log_prefix_emojilog_level, 0); + xdebug_str_add_const(XG_LIB(diagnosis_buffer), "</td><td class=\"v\">"); + xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_channel_namechannel, 0); + xdebug_str_add(XG_LIB(diagnosis_buffer), message, 0); + xdebug_str_add_const(XG_LIB(diagnosis_buffer), "</td><td class=\"d\"><a href=\""); + xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_lib_docs_base(), 0); + xdebug_str_add_const(XG_LIB(diagnosis_buffer), "errors#"); + xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_channel_msg_prefixchannel, 0); + xdebug_str_add(XG_LIB(diagnosis_buffer), xdebug_level_msg_prefixlog_level, 0); + if (error_code) { + xdebug_str_addc(XG_LIB(diagnosis_buffer), '-'); + xdebug_str_add(XG_LIB(diagnosis_buffer), error_code, 0); + } + xdebug_str_add_const(XG_LIB(diagnosis_buffer), "\">🖹</a></td></tr>"); + } + + xdebug_str_addc(XG_LIB(diagnosis_buffer), '\n'); +} + +static inline void xdebug_php_log(int channel, int log_level, const char *error_code, const char *message) +{ + xdebug_str formatted_message = XDEBUG_STR_INITIALIZER; + + if (log_level > XLOG_ERR) { + return; + } + + xdebug_str_add_const(&formatted_message, "Xdebug: "); + xdebug_str_add(&formatted_message, xdebug_channel_namechannel, 0); + xdebug_str_add(&formatted_message, message, 0); + + if (error_code && log_level == XLOG_CRIT) { + xdebug_str_add_const(&formatted_message, " (See: "); + xdebug_str_add(&formatted_message, xdebug_lib_docs_base(), 0); + xdebug_str_add_const(&formatted_message, "errors#"); + xdebug_str_add(&formatted_message, xdebug_channel_msg_prefixchannel, 0); + xdebug_str_add(&formatted_message, xdebug_level_msg_prefixlog_level, 0); + xdebug_str_addc(&formatted_message, '-'); + xdebug_str_add(&formatted_message, error_code, 0); + xdebug_str_addc(&formatted_message, ')'); + } + + php_log_err(formatted_message.d); + + xdebug_str_destroy(&formatted_message); +} + +void XDEBUG_ATTRIBUTE_FORMAT(printf, 4, 5) xdebug_log_ex(int channel, int log_level, const char *error_code, const char *fmt, ...) +{ + xdebug_str message = XDEBUG_STR_INITIALIZER; + va_list argv; + int logged_to_xdebug_log = 0; + + if (XINI_LIB(log_level) < log_level) { + return; + } + + va_start(argv, fmt); + xdebug_str_add_va_fmt(&message, fmt, argv); + va_end(argv); + + logged_to_xdebug_log = xdebug_internal_log(channel, log_level, message.d); + + xdebug_diagnostic_log(channel, log_level, error_code, message.d); + + if (!logged_to_xdebug_log || XINI_LIB(log_level) == XLOG_CRIT) { + xdebug_php_log(channel, log_level, error_code, message.d); + } + + xdebug_str_destroy(&message); +} + +static void log_filename_not_opened(int channel, const char *directory, const char *filename) +{ + xdebug_str full_filename = XDEBUG_STR_INITIALIZER; + + if (directory) { + xdebug_str_add(&full_filename, directory, 0); + if (!IS_SLASH(directorystrlen(directory) - 1)) { + xdebug_str_addc(&full_filename, DEFAULT_SLASH); + } + } + xdebug_str_add(&full_filename, filename, 0); + + xdebug_log_ex(channel, XLOG_ERR, "OPEN", "File '%s' could not be opened.", full_filename.d); + + xdebug_str_destroy(&full_filename); +} + +void xdebug_log_diagnose_permissions(int channel, const char *directory, const char *filename) +{ +#ifndef WIN32 + struct stat dir_info; +#endif + + log_filename_not_opened(channel, directory, filename); + +#ifndef WIN32 + if (!directory) { + return; + } + + if (stat(directory, &dir_info) == -1) { + xdebug_log_ex(channel, XLOG_WARN, "STAT", "%s: %s", directory, strerror(errno)); + return; + } + + if (!S_ISDIR(dir_info.st_mode)) { + xdebug_log_ex(channel, XLOG_WARN, "NOTDIR", "The path '%s' is not a directory.", directory); + return; + } + + xdebug_log_ex(channel, XLOG_WARN, "PERM", "The path '%s' has the permissions: 0%03o.", directory, dir_info.st_mode & 0777); +#endif +} + +static int xdebug_info_printf(const char *fmt, ...) /* {{{ */ +{ + char *buf; + size_t len, written; + va_list argv; + + va_start(argv, fmt); + len = vspprintf(&buf, 0, fmt, argv); + va_end(argv); + + written = php_output_write(buf, len); + efree(buf); + return written; +} +/* }}} */ + +static void print_logo(void) +{ + if (!sapi_module.phpinfo_as_text) { + PUTS("<tr><td colspan=\"2\" class=\"l\">"); + PUTS("<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"176\" height=\"91\" viewBox=\"0 0 351 181\"><title>Xdebug</title><g fill=\"none\" fill-rule=\"evenodd\" stroke=\"#FFF\"><g transform=\"translate(5 5)\"><path fill=\"#317E1E\" fill-rule=\"nonzero\" stroke-width=\"5\" d=\"M127.9 85.5l68.2 70.7.4 17.3h-38.6l-60.8-59.7-60 59.7h-39v-17.6l69.7-69.8-69.6-71.2V-2.5h38.7l60.2 60 61-60h38.3v16l-68.5 72z\"></path><circle cx=\"75.9\" cy=\"74.6\" r=\"3.5\" stroke-opacity=\".8\" stroke-width=\"4\"></circle><circle cx=\"105.1\" cy=\"85\" r=\"3.5\" stroke-opacity=\".8\" stroke-width=\"4\"></circle><circle cx=\"158.4\" cy=\"15\" r=\"3.5\" stroke-opacity=\".8\" stroke-width=\"4\"></circle><circle cx=\"50.9\" cy=\"140\" r=\"3.5\" stroke-opacity=\".8\" stroke-width=\"4\"></circle><circle cx=\"180.4\" cy=\"158.5\" r=\"3.5\" stroke-opacity=\".8\" stroke-width=\"4\"></circle><path stroke-linecap=\"square\" stroke-linejoin=\"round\" stroke-width=\"4\" d=\"M32.6 158.2L42 149M104.3 69.1l49.4-49.4\"></path><path stroke-linejoin=\"round\" stroke-width=\"4\" d=\"M102.3 82.7L30.3 10H11.2M167.4 10H183M11.2 160.7l79.2-78\"></path><path stroke-linejoin=\"round\" stroke-opacity=\".7\" stroke-width=\"4\" d=\"M116.3 74.6L181 10\"></path><path stroke-linejoin=\"round\" stroke-width=\"4\" d=\"M20.7 19.7l52.7 52.6\"></path><path stroke-linejoin=\"round\" stroke-opacity=\".7\" stroke-width=\"4\" d=\"M116.3 96.7l32 32\"></path><path stroke-linejoin=\"round\" stroke-width=\"4\" d=\"M155.2 133.6l22.1 22M53.6 137.5L97 94.9l67.1 66.6h4.9\"></path></g><g fill=\"#000\" fill-rule=\"nonzero\" stroke-width=\"4\"><path d=\"M158.3 107.7V72.9c0-.5 0-.5-.8-.5-.7 0-.7 0-.7.6v34.7c0 .6 0 .5.7.5.8 0 .7 0 .7-.5zm3.9 11.2a22.5 22.5 0 0 1-20-.7c-3.4-2-5.2-4.8-5.2-8.4V69.6c0-3 1.5-5.6 4.3-7.4a17 17 0 0 1 9.2-2.4c3 0 5.6.3 7.7 1V47H178v73h-15l-.8-1.1zM200.9 84V73.2c0-.8 0-.8-.8-.8s-.8 0-.8.8V84h1.6zm-1.6 12.5v11c0 .7 0 .7.8.7.7 0 .8 0 .8-.8V97.2h19.8v10.4c0 8.9-7.3 13.2-20.7 13.2-13.3 0-20.5-4.5-20.5-13.7V73.6c0-9.2 7.2-13.8 20.5-13.8 13.4 0 20.7 4.4 20.7 13.4v23.3h-21.4zM243.3 107.7V73c0-.6 0-.6-.7-.6-.8 0-.8 0-.8.5v34.8c0 .6 0 .5.8.5.7 0 .7 0 .7-.5zm-5.4 11.1l-.9 1.3h-15V47h19.8v13.8c2.1-.7 4.7-1 7.9-1 3.1 0 6.1.8 8.8 2.3 3 1.6 4.6 4.2 4.6 7.5v40.2c0 3.6-1.8 6.4-5.3 8.4a22.5 22.5 0 0 1-19.9.6zM285.8 119.7c-2.1.8-4.7 1.1-7.8 1.1a17 17 0 0 1-9.1-2.4c-2.8-1.7-4.4-4.2-4.4-7.2v-51h19.8v47.5c0 .6 0 .5.8.5.7 0 .7 0 .7-.4V60h19.8v60h-19.8v-.4zM328.3 108.3V73c0-.6 0-.6-.7-.6-.8 0-.8 0-.8.6V108c0 .6 0 .6.8.6.7 0 .7 0 .7-.4zm-.9 11.8c-2 .5-4.2.7-6.9.7a17 17 0 0 1-9.1-2.4c-2.9-1.7-4.4-4.2-4.4-7.2V71c0-7.4 5.2-11.2 14.6-11.2 2.3 0 5 .7 8.3 2l1.7-1.7H348v57.3c0 4.4-1 9.5-2.8 12-2.1 3.2-7.7 4.5-17 4.5h-18.4v-12h14.9c1.1 0 2-.7 2.7-1.8z\"></path></g></g></svg>"); + PUTS("</td></tr>\n"); + } else { + PUTS("\331m__ __ _ _ \n" + "\331m\\ \\ / / | | | | \n" + "\331m \\ V / __| | ___| |__ _ _ __ _ \n" + "\331m > < / _` |/ _ \\ '_ \\| | | |/ _` |\n" + "\331m / . \\ (_| | __/ |_) | |_| | (_| |\n" + "\331m/_/ \\_\\__,_|\\___|_.__/ \\__,_|\\__, |\n" + "\331m __/ |\n" + "\331m |___/ \n\n\330m"); + + } +} + +static void print_feature_row(const char *name, int flag, const char *doc_name) +{ + if (!sapi_module.phpinfo_as_text) { + PUTS("<tr>"); + PUTS("<td class=\"e\">"); + PUTS(name); + PUTS("</td><td class=\"v\">"); + PUTS(XDEBUG_MODE_IS(flag) ? "✔ enabled" : "✘ disabled"); + PUTS("</td><td class=\"d\"><a href=\""); + PUTS(xdebug_lib_docs_base()); + PUTS(doc_name); + PUTS("\">🖹</a></td></tr>\n"); + } else { + php_info_print_table_row(2, name, XDEBUG_MODE_IS(flag) ? "✔ enabled" : "✘ disabled"); + } +} + +void xdebug_print_info(void) +{ + /* Header block */ + php_info_print_table_start(); + + print_logo(); + + php_info_print_table_row(2, "Version", XDEBUG_VERSION); + + if (!sapi_module.phpinfo_as_text) { + xdebug_info_printf("<tr><td colspan='2' style='background-color: white; text-align: center'>%s</td></tr>\n", "<a style='color: #317E1E; background-color: transparent; font-weight: bold; text-decoration: underline' href='https://xdebug.org/support'>Support Xdebug on Patreon, GitHub, or as a business</a>"); + } else { + xdebug_info_printf("Support Xdebug on Patreon, GitHub, or as a business: https://xdebug.org/support\n"); + } + php_info_print_table_end(); + + /* Modes block */ + php_info_print_table_start(); + + if (!sapi_module.phpinfo_as_text) { + php_info_print_table_colspan_header( + 3, + (char*) (XG_LIB(mode_from_environment) ? "Enabled Features<br/>(through 'XDEBUG_MODE' env variable)" : "Enabled Features<br/>(through 'xdebug.mode' setting)") + ); + } else { + php_info_print_table_colspan_header( + 2, + (char*) (XG_LIB(mode_from_environment) ? "Enabled Features (through 'XDEBUG_MODE' env variable)" : "Enabled Features (through 'xdebug.mode' setting)") + ); + } + + if (!sapi_module.phpinfo_as_text) { + php_info_print_table_header(3, "Feature", "Enabled/Disabled", "Docs"); + } else { + php_info_print_table_header(2, "Feature", "Enabled/Disabled"); + } + + print_feature_row("Development Helpers", XDEBUG_MODE_DEVELOP, "develop"); + print_feature_row("Coverage", XDEBUG_MODE_COVERAGE, "code_coverage"); + print_feature_row("GC Stats", XDEBUG_MODE_GCSTATS, "garbage_collection"); + print_feature_row("Profiler", XDEBUG_MODE_PROFILING, "profiler"); + print_feature_row("Step Debugger", XDEBUG_MODE_STEP_DEBUG, "remote"); + print_feature_row("Tracing", XDEBUG_MODE_TRACING, "trace"); + + php_info_print_table_end(); + + /* Optional compiled in features */ + php_info_print_table_start(); + php_info_print_table_colspan_header(2, (char*) "Optional Features"); + +#if HAVE_XDEBUG_ZLIB + php_info_print_table_row(2, "Compressed File Support", "yes (gzip)"); +#else + php_info_print_table_row(2, "Compressed File Support", "no"); +#endif + +#if WIN32 + php_info_print_table_row(2, "Clock Source", XG_BASE(nanotime_context).use_rel_time ? "QueryPerformanceFrequency" : "GetSystemTimePreciseAsFileTime"); +#else +# if HAVE_XDEBUG_CLOCK_GETTIME_NSEC_NP + php_info_print_table_row(2, "Clock Source", "clock_gettime_nsec_np"); +# elif HAVE_XDEBUG_CLOCK_GETTIME + php_info_print_table_row(2, "Clock Source", "clock_gettime"); +# else + php_info_print_table_row(2, "Clock Source", "gettimeofday"); +# endif +#endif + +#if HAVE_LINUX_RTNETLINK_H + php_info_print_table_row(2, "'xdebug://gateway' pseudo-host support", "yes"); +#else + php_info_print_table_row(2, "'xdebug://gateway' pseudo-host support", "no"); +#endif +#if HAVE_RES_NINIT + php_info_print_table_row(2, "'xdebug://nameserver' pseudo-host support", "yes"); +#else + php_info_print_table_row(2, "'xdebug://nameserver' pseudo-host support", "no"); +#endif + + if (XG_BASE(private_tmp)) { + php_info_print_table_row(2, "Systemd Private Temp Directory", XG_BASE(private_tmp)); + } else { + php_info_print_table_row(2, "Systemd Private Temp Directory", "not enabled"); + } + + + php_info_print_table_end(); +} + +PHPAPI extern char *php_ini_opened_path; +PHPAPI extern char *php_ini_scanned_path; +PHPAPI extern char *php_ini_scanned_files; + +static void xdebug_print_php_section(void) +{ + php_info_print_table_start(); + php_info_print_table_colspan_header(2, (char*) "PHP"); + + php_info_print_table_colspan_header(2, (char*) "Build Configuration"); + php_info_print_table_row(2, "Version (Run Time)", XG_BASE(php_version_run_time)); + php_info_print_table_row(2, "Version (Compile Time)", XG_BASE(php_version_compile_time)); +#if ZEND_DEBUG + php_info_print_table_row(2, "Debug Build", "yes"); +#else + php_info_print_table_row(2, "Debug Build", "no"); +#endif + +#ifdef ZTS + php_info_print_table_row(2, "Thread Safety", "enabled"); + php_info_print_table_row(2, "Thread API", tsrm_api_name()); +#else + php_info_print_table_row(2, "Thread Safety", "disabled"); +#endif + + php_info_print_table_colspan_header(2, (char*) "Settings"); + php_info_print_table_row(2, "Configuration File (php.ini) Path", PHP_CONFIG_FILE_PATH); + php_info_print_table_row(2, "Loaded Configuration File", php_ini_opened_path ? php_ini_opened_path : "(none)"); + php_info_print_table_row(2, "Scan this dir for additional .ini files", php_ini_scanned_path ? php_ini_scanned_path : "(none)"); + php_info_print_table_row(2, "Additional .ini files parsed", php_ini_scanned_files ? php_ini_scanned_files : "(none)"); + php_info_print_table_end(); +} + +static ZEND_COLD void php_ini_displayer_cb(zend_ini_entry *ini_entry, int type) +{ + if (ini_entry->displayer) { + ini_entry->displayer(ini_entry, type); + } else { + const char *display_string; + size_t display_string_length; + int esc_html=0; + + if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { + if (ini_entry->orig_value && ZSTR_VAL(ini_entry->orig_value)0) { + display_string = ZSTR_VAL(ini_entry->orig_value); + display_string_length = ZSTR_LEN(ini_entry->orig_value); + esc_html = !sapi_module.phpinfo_as_text; + } else { + if (!sapi_module.phpinfo_as_text) { + display_string = "<i>no value</i>"; + display_string_length = sizeof("<i>no value</i>") - 1; + } else { + display_string = "no value"; + display_string_length = sizeof("no value") - 1; + } + } + } else if (ini_entry->value && ZSTR_VAL(ini_entry->value)0) { + display_string = ZSTR_VAL(ini_entry->value); + display_string_length = ZSTR_LEN(ini_entry->value); + esc_html = !sapi_module.phpinfo_as_text; + } else { + if (!sapi_module.phpinfo_as_text) { + display_string = "<i>no value</i>"; + display_string_length = sizeof("<i>no value</i>") - 1; + } else { + display_string = "no value"; + display_string_length = sizeof("no value") - 1; + } + } + + if (esc_html) { + zend_html_puts(display_string, display_string_length); + } else { + PHPWRITE(display_string, display_string_length); + } + } +} + +static int if_overridden_xdebug_mode(char *name) +{ + if ((strcmp("xdebug.mode", name) == 0) && XG_LIB(mode_from_environment)) { + return 1; + } + + return 0; +} + +static int is_using_private_tmp_directory(char *file_name) +{ + if (!file_name) { + return 0; + } + return (XG_BASE(private_tmp) && (strstr(file_name, "/tmp") == file_name)); +} + +static const char* private_tmp_directory(char *file_name) +{ + if (is_using_private_tmp_directory(file_name)) { + return XG_BASE(private_tmp); + } + + return ""; +} + +static void xdebug_print_settings(void) +{ + zend_module_entry *module; + zend_ini_entry *ini_entry; + int module_number; + zend_string *name = zend_string_init("xdebug", 6, 0); + + module = zend_hash_find_ptr(&module_registry, name); + zend_string_release(name); + + if (!module) { + return; + } + + module_number = module->module_number; + + php_info_print_table_start(); + if (!sapi_module.phpinfo_as_text) { + php_info_print_table_header(4, "Directive", "Local Value", "Master Value", "Docs"); + } else { + php_info_print_table_header(3, "Directive", "Local Value", "Master Value"); + } + + ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) { + if (ini_entry->module_number != module_number) { + continue; + } + + /* Hack to not show changed and removed settings */ + if (ini_entry->value && strncmp(ZSTR_VAL(ini_entry->value), "This setting has", 16) == 0) { + continue; + } + + if (!sapi_module.phpinfo_as_text) { + PUTS("<tr>"); + PUTS("<td class=\"e\">"); + PHPWRITE(ZSTR_VAL(ini_entry->name), ZSTR_LEN(ini_entry->name)); + if (if_overridden_xdebug_mode(ZSTR_VAL(ini_entry->name))) { + PUTS(" <small>(through XDEBUG_MODE)</small>"); + } + PUTS("</td><td class=\"v\">"); + if (if_overridden_xdebug_mode(ZSTR_VAL(ini_entry->name))) { + PUTS(getenv("XDEBUG_MODE")); + } else { + /* Hack for Systemd PrivateTmp */ + if ( + ( + (strcmp(ZSTR_VAL(ini_entry->name), "xdebug.output_dir") == 0) || + (strcmp(ZSTR_VAL(ini_entry->name), "xdebug.log") == 0) + ) && + (ini_entry->value && ZSTR_VAL(ini_entry->value)0) && + is_using_private_tmp_directory(ZSTR_VAL(ini_entry->value)) + ) { + PUTS(XG_BASE(private_tmp)); + } + + /* Normal value */ + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); + } + PUTS("</td><td class=\"v\">"); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); + PUTS("</td><td class=\"d\"><a href=\""); + PUTS(xdebug_lib_docs_base()); + PUTS("all_settings#"); + PHPWRITE(ZSTR_VAL(ini_entry->name), ZSTR_LEN(ini_entry->name)); + PUTS("\">🖹</a></td></tr>\n"); + } else { + PHPWRITE(ZSTR_VAL(ini_entry->name), ZSTR_LEN(ini_entry->name)); + if (if_overridden_xdebug_mode(ZSTR_VAL(ini_entry->name))) { + PUTS(" (through XDEBUG_MODE)"); + } + PUTS(" => "); + if (if_overridden_xdebug_mode(ZSTR_VAL(ini_entry->name))) { + PUTS(getenv("XDEBUG_MODE")); + } else { + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ACTIVE); + } + PUTS(" => "); + php_ini_displayer_cb(ini_entry, ZEND_INI_DISPLAY_ORIG); + PUTS("\n"); + } + } ZEND_HASH_FOREACH_END(); + + php_info_print_table_end(); +} + +static void print_html_header(void) +{ + if (sapi_module.phpinfo_as_text) { + return; + } + + PUTS("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n"); + PUTS("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); + PUTS("<head>\n"); + + PUTS("<style type=\"text/css\">\n"); + PUTS("body {background-color: #fff; color: #222; font-family: sans-serif;}\n"); + PUTS("pre {margin: 0; font-family: monospace;}\n"); + PUTS("a:link, a:hover, a:visited {color: black; text-decoration: underline;}\n"); + PUTS("table {border-collapse: separate; border: 1px solid #666; width: 934px; box-shadow: 1px 2px 3px #ccc; border-bottom: none; border-right: none; border-spacing: 0;}\n"); + PUTS(".center {text-align: center;}\n"); + PUTS(".center table {margin: 1em auto; text-align: left;}\n"); + PUTS(".center th {text-align: center !important;}\n"); + PUTS("td, th {border: 1px solid #666; font-size: 75%; vertical-align: baseline; padding: 4px 5px; border-left: none; border-top: none;}\n"); + PUTS("th {top: 0; background: inherit; position: sticky;}\n"); + PUTS("h1 {font-size: 150%;}\n"); + PUTS("h2 {font-size: 125%;}\n"); + PUTS(".p {text-align: left;}\n"); + PUTS(".e {background-color: #e5f5d5; width: 300px; font-weight: bold;}\n"); + PUTS(".h {background-color: #bbde94; font-weight: bold;}\n"); + PUTS(".v {background-color: #ddd; max-width: 300px; overflow-x: auto; word-wrap: break-word;}\n"); + PUTS(".i {background-color: #ddd; text-align: center; font-size: 1em; font-family: serif; width: 1em;}\n"); + PUTS(".v i {color: #999;}\n"); + PUTS(".d {background-color: #ddd; width: 1em; text-align: center;}\n"); + PUTS(".l {background-color: #bbde94;}\n"); + PUTS("img {float: right; border: 0;}\n"); + PUTS("hr {width: 934px; background-color: #ccc; border: 0; height: 1px;}\n"); + PUTS("</style>\n"); + + PUTS("<title>Xdebug "); + PUTS(XDEBUG_VERSION); + PUTS("</title>"); + PUTS("<meta name=\"ROBOTS\" content=\"NOINDEX,NOFOLLOW,NOARCHIVE\" />"); + PUTS("</head>\n"); + PUTS("<body><div class=\"center\">\n"); +} + +static void print_html_footer(void) +{ + if (sapi_module.phpinfo_as_text) { + return; + } + + php_output_write("</div></body></html>", strlen("</div></body></html>")); +} + +static void print_diagnostic_log(void) +{ + php_info_print_table_start(); + if (!sapi_module.phpinfo_as_text) { + php_info_print_table_colspan_header(3, (char*) "Diagnostic Log"); + } else { + php_info_print_table_colspan_header(2, (char*) "Diagnostic Log"); + } + if (XG_LIB(diagnosis_buffer) && XG_LIB(diagnosis_buffer)->l) { + if (!sapi_module.phpinfo_as_text) { + PUTS("<tr class=\"h\"><th colspan=\"2\">Message</th><th>Docs</th></tr>\n"); + } + php_output_write(XG_LIB(diagnosis_buffer)->d, XG_LIB(diagnosis_buffer)->l); + } else { + if (!sapi_module.phpinfo_as_text) { + PUTS("<tr><td class=\"v\" colspan=\"3\">No messages</td></tr>\n"); + } else { + PUTS("No messages\n"); + } + } + php_info_print_table_end(); +} + +static void print_profile_information(void) +{ + char *file_name; + + if (!XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + return; + } + + file_name = xdebug_get_profiler_filename(); + + php_info_print_table_start(); + if (!sapi_module.phpinfo_as_text) { + PUTS("<tr class=\"h\"><th colspan=\"2\">Profiler</th><th>Docs</th></tr>\n"); + if (file_name) { + xdebug_info_printf("<tr><td class=\"e\">Profile File</td><td class=\"v\">%s%s</td><td class=\"d\"><a href=\"%sprofiler\">🖹</a></td></tr>\n", + private_tmp_directory(file_name), + file_name, + xdebug_lib_docs_base()); + } else { + xdebug_info_printf("<tr><td colspan=\"2\" class=\"d\">Profiler is not active</td><td class=\"d\"><a href=\"%sprofiler\">🖹</a></td></tr>\n", + xdebug_lib_docs_base()); + } + } else { + php_info_print_table_colspan_header(2, (char*) "Profiler"); + if (file_name) { + if (is_using_private_tmp_directory(file_name)) { + php_info_print_table_row(2, "Profile File Directory", XG_BASE(private_tmp)); + } + php_info_print_table_row(2, "Profile File", file_name); + } else { + PUTS("Profiler is not active\n"); + } + } + php_info_print_table_end(); +} + +static void print_step_debug_information(void) +{ + int is_active; + + if (!XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + return; + } + + is_active = xdebug_is_debug_connection_active(); + + php_info_print_table_start(); + if (!sapi_module.phpinfo_as_text) { + PUTS("<tr class=\"h\"><th colspan=\"2\">Step Debugging</th><th>Docs</th></tr>\n"); + xdebug_info_printf( + "<tr><td class=\"e\">Debugger</td><td class=\"v\">%s</td>" + "<td class=\"d\"><a href=\"%sstep_debug\">🖹</a></td></tr>\n", + is_active ? "Active" : (XG_DBG(detached) ? "Detached" : "Not Active"), xdebug_lib_docs_base()); + if (XG_DBG(context).connected_hostname) { + if (strcmp(XINI_DBG(cloud_id), "") == 0) { + xdebug_info_printf( + "<tr><td class=\"e\">Connected Client</td><td class=\"v\">%s:%d</td><td class=\"d\"> </td></tr>\n", + XG_DBG(context).connected_hostname, XG_DBG(context).connected_port + ); + } else { + xdebug_info_printf( + "<tr><td class=\"e\">Xdebug Cloud Host</td><td class=\"v\">%s:%d</td><td class=\"d\"> </td></tr>\n", + XG_DBG(context).connected_hostname, XG_DBG(context).connected_port + ); + xdebug_info_printf( + "<tr><td class=\"e\">Xdebug Cloud ID</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", + XINI_DBG(cloud_id) + ); + } + } + if (XG_DBG(detached)) { + xdebug_info_printf( + "<tr><td class=\"e\">Detached</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", + XG_DBG(context).detached_message ? XG_DBG(context).detached_message : "Yes" + ); + } else if (XG_DBG(context).options) { + xdebug_var_export_options *options; + PUTS("<tr class=\"h\"><th colspan=\"3\">DBGp Settings</th></tr>\n"); + + options = (xdebug_var_export_options*) XG_DBG(context).options; + xdebug_info_printf( + "<tr><td class=\"e\">Max Children</td><td class=\"v\">%d</td><td class=\"d\"> </td></tr>\n", + options->max_children + ); + xdebug_info_printf( + "<tr><td class=\"e\">Max Data</td><td class=\"v\">%d</td><td class=\"d\"> </td></tr>\n", + options->max_data + ); + xdebug_info_printf( + "<tr><td class=\"e\">Max Depth</td><td class=\"v\">%d</td><td class=\"d\"> </td></tr>\n", + options->max_depth + ); + xdebug_info_printf( + "<tr><td class=\"e\">Show Hidden Properties</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", + options->show_hidden ? "Yes" : "No" + ); + xdebug_info_printf( + "<tr><td class=\"e\">Extended Properties</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", + options->extended_properties ? "Yes" : "No" + ); + xdebug_info_printf( + "<tr><td class=\"e\">Notifications</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", + XG_DBG(context).send_notifications ? "Yes" : "No" + ); + xdebug_info_printf( + "<tr><td class=\"e\">Resolved Breakpoints</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", + XG_DBG(context).resolved_breakpoints ? "Yes" : "No" + ); + xdebug_info_printf( + "<tr><td class=\"e\">Breakpoint Details</td><td class=\"v\">%s</td><td class=\"d\"> </td></tr>\n", + XG_DBG(context).breakpoint_details ? "Yes" : "No" + ); + } + } else { + php_info_print_table_colspan_header(2, (char*) "Step Debugging"); + if (is_active) { + PUTS("Debugger is active\n"); + } else { + PUTS("Debugger is not active\n"); + } + if (XG_DBG(context).connected_hostname) { + if (strcmp(XINI_DBG(cloud_id), "") == 0) { + xdebug_info_printf("Connected Client => %s:%d\n", + XG_DBG(context).connected_hostname, XG_DBG(context).connected_port + ); + } else { + xdebug_info_printf( + "Xdebug Cloud Host => %s:%d\n", + XG_DBG(context).connected_hostname, XG_DBG(context).connected_port + ); + xdebug_info_printf("Xdebug Cloud ID => %s\n", XINI_DBG(cloud_id)); + } + } + if (XG_DBG(detached)) { + xdebug_info_printf("Detached => %s\n", XG_DBG(context).detached_message ? XG_DBG(context).detached_message : "Yes"); + } else if (XG_DBG(context).options) { + xdebug_var_export_options *options = (xdebug_var_export_options*) XG_DBG(context).options; + + PUTS("\nDBGp Settings\n"); + xdebug_info_printf("Max Children => %d\n", options->max_children); + xdebug_info_printf("Max Data => %d\n", options->max_data); + xdebug_info_printf("Max Depth => %d\n", options->max_depth); + xdebug_info_printf("Show Hidden Properties => %s\n", options->show_hidden ? "Yes" : "No"); + xdebug_info_printf("Extended Properties => %s\n", options->extended_properties ? "Yes" : "No"); + xdebug_info_printf("Notifications => %s\n", XG_DBG(context).send_notifications ? "Yes" : "No"); + xdebug_info_printf("Resolved Breakpoints => %s\n", XG_DBG(context).resolved_breakpoints ? "Yes" : "No"); + xdebug_info_printf("Breakpoint: Details => %s\n", XG_DBG(context).breakpoint_details ? "Yes" : "No"); + xdebug_info_printf("Breakpoint: Include Return Values => %s\n", XG_DBG(context).breakpoint_include_return_value ? "Yes" : "No"); + } + } + php_info_print_table_end(); +} + +static void print_trace_information(void) +{ + char *file_name; + + if (!XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { + return; + } + + file_name = xdebug_get_trace_filename(); + + php_info_print_table_start(); + if (!sapi_module.phpinfo_as_text) { + PUTS("<tr class=\"h\"><th colspan=\"2\">Function Tracing</th><th>Docs</th></tr>\n"); + if (file_name) { + xdebug_info_printf("<tr><td class=\"e\">Trace File</td><td class=\"v\">%s%s</td><td class=\"d\"><a href=\"%strace\">🖹</a></td></tr>\n", + private_tmp_directory(file_name), + file_name, + xdebug_lib_docs_base()); + } else { + xdebug_info_printf("<tr><td colspan=\"2\" class=\"d\">Function tracing is not active</td><td class=\"d\"><a href=\"%strace\">🖹</a></td></tr>\n", + xdebug_lib_docs_base()); + } + } else { + php_info_print_table_colspan_header(2, (char*) "Function Tracing"); + if (file_name) { + if (is_using_private_tmp_directory(file_name)) { + php_info_print_table_row(2, "Trace File Directory", XG_BASE(private_tmp)); + } + php_info_print_table_row(2, "Trace File", file_name); + } else { + PUTS("Function tracing is not active\n"); + } + } + php_info_print_table_end(); +} + +static void xdebug_display_all_info(void) +{ + print_html_header(); + + xdebug_print_info(); + + print_diagnostic_log(); + print_step_debug_information(); + print_profile_information(); + print_trace_information(); + + xdebug_print_php_section(); + + xdebug_print_settings(); + + print_html_footer(); +} + +static void info_modes_set(INTERNAL_FUNCTION_PARAMETERS) +{ + array_init_size(return_value, 6); + + if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { + add_next_index_stringl(return_value, "coverage", 8); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + add_next_index_stringl(return_value, "debug", 5); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + add_next_index_stringl(return_value, "develop", 7); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { + add_next_index_stringl(return_value, "gcstats", 7); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + add_next_index_stringl(return_value, "profile", 7); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { + add_next_index_stringl(return_value, "trace", 5); + } +} + +static void info_extension_flags_set(INTERNAL_FUNCTION_PARAMETERS) +{ + array_init_size(return_value, 1); + +#if HAVE_XDEBUG_ZLIB + add_next_index_stringl(return_value, "compression", 11); +#endif +} + + +PHP_FUNCTION(xdebug_info) +{ + zend_string *group = NULL; + + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_STR(group) + ZEND_PARSE_PARAMETERS_END(); + + if (group == NULL) { + xdebug_display_all_info(); + return; + } + + if (zend_string_equals_literal(group, "mode")) { + info_modes_set(INTERNAL_FUNCTION_PARAM_PASSTHRU); + return; + } + if (zend_string_equals_literal(group, "extension-flags")) { + info_extension_flags_set(INTERNAL_FUNCTION_PARAM_PASSTHRU); + return; + } + + php_error_docref(NULL, E_WARNING, "The information group '%s' is not available", ZSTR_VAL(group)); +} + +void xdebug_open_log(void) +{ + /* initialize remote log file */ + XG_LIB(log_file) = NULL; + XG_LIB(log_opened_message_sent) = 0; + XG_LIB(log_open_timestring) = NULL; + + if (XINI_LIB(log) && strlen(XINI_LIB(log))) { + XG_LIB(log_file) = xdebug_fopen(XINI_LIB(log), "a", NULL, NULL); + } + if (XG_LIB(log_file)) { + XG_LIB(log_open_timestring) = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6); + } else if (strlen(XINI_LIB(log))) { + xdebug_log_diagnose_permissions(XLOG_CHAN_LOGFILE, NULL, XINI_LIB(log)); + } +} + +void xdebug_close_log() +{ + char *timestr; + + if (!XG_LIB(log_file)) { + return; + } + + if (XG_LIB(log_opened_message_sent)) { + zend_ulong pid; + + pid = xdebug_get_pid(); + timestr = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6); + + fprintf(XG_LIB(log_file), "" ZEND_ULONG_FMT " Log closed at %s\n\n", pid, timestr); + fflush(XG_LIB(log_file)); + xdfree(timestr); + } + + if (XG_LIB(log_open_timestring)) { + xdfree(XG_LIB(log_open_timestring)); + XG_LIB(log_open_timestring) = NULL; + } + + fclose(XG_LIB(log_file)); + XG_LIB(log_file) = NULL; +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/log.h
Changed
(renamed from xdebug-3.1.5/src/lib/log.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/mm.h
Changed
(renamed from xdebug-3.1.5/src/lib/mm.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/php-header.h
Added
@@ -0,0 +1,20 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeclaration-after-statement" +#include "php.h" +#pragma GCC diagnostic pop
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/set.c
Changed
(renamed from xdebug-3.1.5/src/lib/set.c)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/set.h
Changed
(renamed from xdebug-3.1.5/src/lib/set.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/str.c
Added
@@ -0,0 +1,257 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include <stdarg.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <locale.h> + +#include "lib/php-header.h" +#include "ext/standard/php_string.h" + +#include "mm.h" +#include "str.h" + +inline static void realloc_if_needed(xdebug_str *xs, int size_to_fit) +{ + if (!xs->a || !xs->l || xs->l + size_to_fit > xs->a - 1) { + xs->d = xdrealloc(xs->d, xs->a + size_to_fit + XDEBUG_STR_PREALLOC); + xs->a = xs->a + size_to_fit + XDEBUG_STR_PREALLOC; + } + if (!xs->l) { + xs->d0 = '\0'; + } +} + +inline static void xdebug_str_internal_addl(xdebug_str *xs, const char *str, int le, int f) +{ + realloc_if_needed(xs, le); + + memcpy(xs->d + xs->l, str, le); + xs->dxs->l + le = '\0'; + xs->l = xs->l + le; + + if (f) { + xdfree((char*) str); + } +} + +void xdebug_str_add(xdebug_str *xs, const char *str, int f) +{ + xdebug_str_internal_addl(xs, str, strlen(str), f); +} + +void xdebug_str_addl(xdebug_str *xs, const char *str, int le, int f) +{ + xdebug_str_internal_addl(xs, str, le, f); +} + +void xdebug_str_add_str(xdebug_str *xs, const xdebug_str *str) +{ + xdebug_str_internal_addl(xs, str->d, str->l, 0); +} + +void xdebug_str_add_zstr(xdebug_str *xs, const zend_string *str) +{ + xdebug_str_internal_addl(xs, ZSTR_VAL(str), ZSTR_LEN(str), 0); +} + +void xdebug_str_addc(xdebug_str *xs, char letter) +{ + realloc_if_needed(xs, 1); + + xs->dxs->l = letter; + xs->dxs->l + 1 = '\0'; + xs->l = xs->l + 1; +} + +void xdebug_str_add_uint64(xdebug_str *xs, uint64_t num) +{ + char buffer21; + char *pos; + int digit; + + pos = &buffer20; + *pos = '\0'; + + do { + digit = num % 10; + num = num / 10; + if (digit < 10) { + *--pos = '0' + digit; + } else { + *--pos = 'a' + digit - 10; + } + } while (num != 0L); + + xdebug_str_internal_addl(xs, pos, &buffer20 - pos, 0); +} + +void xdebug_str_add_va_fmt(xdebug_str *xs, const char *fmt, va_list argv) +{ + int size; + int n; + va_list argv_size, argv_copy; + + realloc_if_needed(xs, 1); + size = xs->a - xs->l; + + va_copy(argv_size, argv); + n = vsnprintf(xs->d + xs->l, size, fmt, argv_size); + va_end(argv_size); + if (n > -1 && n < size) { + xs->l += n; + return; + } + + realloc_if_needed(xs, n + 1); + size = xs->a - xs->l; + + va_copy(argv_copy, argv); + n = vsnprintf(xs->d + xs->l, size, fmt, argv_copy); + va_end(argv_copy); + + if (n > -1 && n < size) { + xs->l += n; + return; + } + + assert(0); +} + +void xdebug_str_add_fmt(xdebug_str *xs, const char *fmt, ...) +{ + va_list args; + + va_start(args, fmt); + xdebug_str_add_va_fmt(xs, fmt, args); + va_end(args); +} + +void xdebug_str_chop(xdebug_str *xs, size_t c) +{ + if (c > xs->l) { + /* Do nothing if the chop amount is larger than the buffer size */ + } else { + xs->l -= c; + xs->dxs->l = '\0'; + } +} + +xdebug_str *xdebug_str_new(void) +{ + xdebug_str *tmp = xdmalloc(sizeof(xdebug_str)); + + tmp->l = 0; + tmp->a = 0; + tmp->d = NULL; + + return tmp; +} + +xdebug_str *xdebug_str_create(const char *c, size_t len) +{ + xdebug_str *tmp = xdebug_str_new(); + + tmp->l = tmp->a = len; + tmp->a++; + tmp->d = xdmalloc(tmp->a); + memcpy(tmp->d, c, tmp->l); + tmp->dtmp->l = '\0'; + + return tmp; +} + +xdebug_str *xdebug_str_create_from_char(char *c) +{ + return xdebug_str_create(c, strlen(c)); +} + +xdebug_str *xdebug_str_copy(xdebug_str *orig) +{ + xdebug_str *tmp = xdebug_str_new(); + + tmp->l = tmp->a = orig->l; + tmp->a++; + tmp->d = xdmalloc(tmp->a); + memcpy(tmp->d, orig->d, tmp->l); + tmp->dorig->l = '\0'; + + return tmp; +} + +void xdebug_str_destroy(xdebug_str *s) +{ + if (s->d) { + xdfree(s->d); + } +} + +void xdebug_str_free(xdebug_str *s) +{ + xdebug_str_destroy(s); + xdfree(s); +} + +char *xdebug_sprintf(const char* fmt, ...) +{ + char *new_str; + int size = 32; + va_list args; + + new_str = (char *) xdmalloc(size); + + for (;;) { + int n; + + va_start(args, fmt); + n = vsnprintf(new_str, size, fmt, args); + va_end(args); + + if (n > -1 && n < size) { + break; + } + if (n < 0) { + size *= 2; + } else { + size = n + 1; + } + new_str = (char *) xdrealloc(new_str, size); + } + + return new_str; +} + +/** + * Duplicate zend_strndup in core to avoid mismatches + * in C-runtime libraries when xdebug and core are built + * with different run-time libraries. + */ +char *xdebug_strndup(const char *s, int length) +{ + char *p; + + p = (char *) xdmalloc(length + 1); + if (p == NULL) { + return p; + } + if (length) { + memcpy(p, s, length); + } + plength = 0; + return p; +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/str.h
Added
@@ -0,0 +1,62 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2020 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __HAVE_XDEBUG_STR_H__ +#define __HAVE_XDEBUG_STR_H__ + +#include <stddef.h> + +#include "lib/php-header.h" + +#include "mm.h" + +#define XDEBUG_STR_INITIALIZER { 0, 0, NULL } +#define XDEBUG_STR_PREALLOC 1024 +#define xdebug_str_dtor(str) xdfree(str.d) + +#define XDEBUG_STR_WRAP_CHAR(v) (&((xdebug_str){strlen(v), strlen(v)+1, ((char*)(v))})) + +typedef struct xdebug_str { + size_t l; + size_t a; + char *d; +} xdebug_str; + +void xdebug_str_add(xdebug_str *xs, const char *str, int f); +void xdebug_str_addl(xdebug_str *xs, const char *str, int le, int f); +void xdebug_str_add_str(xdebug_str *xs, const xdebug_str *str); +void xdebug_str_add_zstr(xdebug_str *xs, const zend_string *str); +void xdebug_str_addc(xdebug_str *xs, char letter); +void xdebug_str_add_uint64(xdebug_str *xs, uint64_t num); +void xdebug_str_add_fmt(xdebug_str *xs, const char *fmt, ...); +void xdebug_str_add_va_fmt(xdebug_str *xs, const char *fmt, va_list argv); +#define xdebug_str_add_literal(s,l) xdebug_str_addl((s), (l), sizeof(l)-1, 0) +#define xdebug_str_add_const(s,l) xdebug_str_addl((s), (l), strlen(l), 0) + +void xdebug_str_chop(xdebug_str *xs, size_t c); + +xdebug_str *xdebug_str_new(void); +xdebug_str *xdebug_str_create_from_char(char *c); +#define xdebug_str_create_from_const_char(c) xdebug_str_create_from_char((char*) (c)) +xdebug_str *xdebug_str_create(const char *c, size_t len); +xdebug_str *xdebug_str_copy(xdebug_str *orig); +void xdebug_str_destroy(xdebug_str *s); +void xdebug_str_free(xdebug_str *s); + +char* xdebug_sprintf(const char* fmt, ...); +char* xdebug_strndup(const char *s, int length); + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/timing.c
Changed
(renamed from xdebug-3.1.5/src/lib/timing.c)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/timing.h
Changed
(renamed from xdebug-3.1.5/src/lib/timing.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/usefulstuff.c
Added
@@ -0,0 +1,724 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include <stdlib.h> +#include <string.h> + +#ifndef WIN32 +# include <unistd.h> +# include <sys/types.h> +# include <sys/socket.h> +# include <sys/resource.h> +# include <sys/file.h> +#else +# define PATH_MAX MAX_PATH +# include <winsock2.h> +# include <io.h> +# include <process.h> +#endif + +#include "php_xdebug.h" + +#include "mm.h" +#include "crc32.h" +#include "str.h" + +#include "lib_private.h" +#include "usefulstuff.h" +#include "log.h" + +#include "ext/standard/php_lcg.h" +#include "ext/standard/flock_compat.h" +#include "main/php_ini.h" + +#ifndef NAME_MAX +# ifdef _AIX +# include <unistd.h> +# define NAME_MAX pathconf("/dev/null",_PC_NAME_MAX) +# else +# define NAME_MAX (MAXNAMELEN-1) +# endif +#endif + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +xdebug_arg *xdebug_arg_ctor(void) +{ + xdebug_arg *tmp = /*(xdebug_arg*)*/ xdmalloc(sizeof(xdebug_arg)); + + tmp->args = NULL; + tmp->c = 0; + + return tmp; +} + +void xdebug_arg_dtor(xdebug_arg *arg) +{ + int i; + + for (i = 0; i < arg->c; i++) { + xdfree(arg->argsi); + } + if (arg->args) { + xdfree(arg->args); + } + xdfree(arg); +} + +xdebug_str* xdebug_join(const char *delim, xdebug_arg *args, int begin, int end) +{ + int i; + xdebug_str *ret = xdebug_str_new(); + + if (begin < 0) { + begin = 0; + } + if (end > args->c - 1) { + end = args->c - 1; + } + for (i = begin; i < end; i++) { + xdebug_str_add(ret, args->argsi, 0); + xdebug_str_add(ret, delim, 0); + } + xdebug_str_add(ret, args->argsend, 0); + return ret; +} + +void xdebug_explode(const char *delim, const char *str, xdebug_arg *args, int limit) +{ + const char *p1, *p2, *endp; + + endp = str + strlen(str); + + p1 = str; + p2 = xdebug_memnstr(str, delim, strlen(delim), endp); + + if (p2 == NULL) { + args->c++; + args->args = (char**) xdrealloc(args->args, sizeof(char*) * args->c); + args->argsargs->c - 1 = (char*) xdmalloc(strlen(str) + 1); + memcpy(args->argsargs->c - 1, p1, strlen(str)); + args->argsargs->c - 1strlen(str) = '\0'; + } else { + do { + args->c++; + args->args = (char**) xdrealloc(args->args, sizeof(char*) * args->c); + args->argsargs->c - 1 = (char*) xdmalloc(p2 - p1 + 1); + memcpy(args->argsargs->c - 1, p1, p2 - p1); + args->argsargs->c - 1p2 - p1 = '\0'; + p1 = p2 + strlen(delim); + } while ((p2 = xdebug_memnstr(p1, delim, strlen(delim), endp)) != NULL && (limit == -1 || --limit > 1)); + + if (p1 <= endp) { + args->c++; + args->args = (char**) xdrealloc(args->args, sizeof(char*) * args->c); + args->argsargs->c - 1 = (char*) xdmalloc(endp - p1 + 1); + memcpy(args->argsargs->c - 1, p1, endp - p1); + args->argsargs->c - 1endp - p1 = '\0'; + } + } +} + +const char* xdebug_memnstr(const char *haystack, const char *needle, int needle_len, const char *end) +{ + const char *p = haystack; + char first = *needle; + + /* let end point to the last character where needle may start */ + end -= needle_len; + + while (p <= end) { + while (*p != first) + if (++p > end) + return NULL; + if (memcmp(p, needle, needle_len) == 0) + return p; + p++; + } + return NULL; +} + +char* xdebug_strrstr(const char* haystack, const char* needle) +{ + char *loc = NULL; + char *found = NULL; + size_t pos = 0; + + while ((found = strstr(haystack + pos, needle)) != 0) { + loc = found; + pos = (found - haystack) + 1; + } + + return loc; +} + +char *xdebug_trim(const char *str) +{ + char *trimmed = NULL, *begin = (char *) str, *end = NULL; + + /* trim leading space */ + while (isspace((unsigned char) *begin)) { + ++begin; + } + + /* All spaces */ + if (*begin == '\0') { + return xdstrdup(""); + } + + /* trim trailing space */ + end = begin + strlen(begin) - 1; + while (end > begin && isspace((unsigned char) *end)) { + --end; + } + end++; + + trimmed = xdmalloc(end - begin + 1); + memcpy(trimmed, begin, (end - begin)); + trimmed(end - begin) = '\0'; + + return trimmed; +} + +/* not all versions of php export this */ +static int xdebug_htoi(char *s) +{ + int value; + int c; + + c = s0; + if (isupper(c)) { + c = tolower(c); + } + value = (c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10) * 16; + + c = s1; + if (isupper(c)) { + c = tolower(c); + } + value += c >= '0' && c <= '9' ? c - '0' : c - 'a' + 10; + + return value; +} + +/* not all versions of php export this */ +int xdebug_raw_url_decode(char *str, int len) +{ + char *dest = str; + char *data = str; + + while (len--) { + if (*data == '%' && len >= 2 && isxdigit((int) *(data + 1)) && isxdigit((int) *(data + 2))) { + *dest = (char) xdebug_htoi(data + 1); + data += 2; + len -= 2; + } else { + *dest = *data; + } + data++; + dest++; + } + *dest = '\0'; + return dest - str; +} + +static unsigned char hexchars = "0123456789ABCDEF"; + +char *xdebug_raw_url_encode(char const *s, int len, int *new_length, int skip_slash) +{ + register int x, y; + unsigned char *str; + + str = (unsigned char *) xdmalloc(3 * len + 1); + for (x = 0, y = 0; len--; x++, y++) { + stry = (unsigned char) sx; + if ((stry < '0' && stry != '-' && stry != '.' && (stry != '/' || !skip_slash)) || + (stry < 'A' && stry > '9' && stry != ':') || + (stry > 'Z' && stry < 'a' && stry != '_' && (stry != '\\' || !skip_slash)) || + (stry > 'z')) + { + stry++ = '%'; + stry++ = hexchars(unsigned char) sx >> 4; + stry = hexchars(unsigned char) sx & 15; + } + } + stry = '\0'; + if (new_length) { + *new_length = y; + } + return ((char *) str); +} + +/* fake URI's per IETF RFC 1738 and 2396 format */ +char *xdebug_path_from_url(zend_string *fileurl) +{ + /* deal with file: url's */ + char *dfp = NULL; + const char *fp = NULL, *efp = ZSTR_VAL(fileurl); +#ifdef PHP_WIN32 + int l = 0; + int i; +#endif + char *tmp = NULL, *ret = NULL; + + dfp = xdstrdup(efp); + fp = dfp; + xdebug_raw_url_decode(dfp, strlen(dfp)); + tmp = strstr(fp, "file://"); + + if (tmp) { + fp = tmp + 7; + if (fp0 == '/' && fp2 == ':') { + fp++; + } + ret = xdstrdup(fp); +#ifdef PHP_WIN32 + l = strlen(ret); + /* convert '/' to '\' */ + for (i = 0; i < l; i++) { + if (reti == '/') { + reti = '\\'; + } + } +#endif + } else { + ret = xdstrdup(ZSTR_VAL(fileurl)); + } + + free(dfp); + return ret; +} + +/* fake URI's per IETF RFC 1738 and 2396 format */ +char *xdebug_path_to_url(zend_string *fileurl) +{ + int l, i, new_len; + char *tmp = NULL; + char *encoded_fileurl; + + /* encode the url */ + encoded_fileurl = xdebug_raw_url_encode(ZSTR_VAL(fileurl), ZSTR_LEN(fileurl), &new_len, 1); + + if (strncmp(ZSTR_VAL(fileurl), "phar://", 7) == 0) { + /* ignore, phar is cool */ + tmp = xdstrdup(ZSTR_VAL(fileurl)); + } else if (ZSTR_VAL(fileurl)0 != '/' && ZSTR_VAL(fileurl)0 != '\\' && ZSTR_VAL(fileurl)1 != ':') { + /* convert relative paths */ + cwd_state new_state; + char cwdMAXPATHLEN; + char *result; + + result = VCWD_GETCWD(cwd, MAXPATHLEN); + if (!result) { + cwd0 = '\0'; + } + + new_state.cwd = estrdup(cwd); + new_state.cwd_length = strlen(cwd); + + if (!virtual_file_ex(&new_state, ZSTR_VAL(fileurl), NULL, 1)) { + char *s = estrndup(new_state.cwd, new_state.cwd_length); + tmp = xdebug_sprintf("file://%s",s); + efree(s); + } + efree(new_state.cwd); + + } else if (ZSTR_VAL(fileurl)1 == '/' || ZSTR_VAL(fileurl)1 == '\\') { + /* convert UNC paths (eg. \\server\sharepath) */ + /* See https://docs.microsoft.com/en-us/archive/blogs/ie/file-uris-in-windows */ + tmp = xdebug_sprintf("file:%s", encoded_fileurl); + } else if (ZSTR_VAL(fileurl)0 == '/' || ZSTR_VAL(fileurl)0 == '\\') { + /* convert *nix paths (eg. /path) */ + tmp = xdebug_sprintf("file://%s", encoded_fileurl); + } else if (ZSTR_VAL(fileurl)1 == ':') { + /* convert windows drive paths (eg. c:\path) */ + tmp = xdebug_sprintf("file:///%s", encoded_fileurl); + } else { + /* no clue about it, use it raw */ + tmp = xdstrdup(encoded_fileurl); + } + l = strlen(tmp); + /* convert '\' to '/' */ + for (i = 0; i < l; i++) { + if (tmpi == '\\') { + tmpi='/'; + } + } + xdfree(encoded_fileurl); + return tmp; +} + +#ifndef PHP_WIN32 +static FILE *xdebug_open_file(char *fname, const char *mode, const char *extension, char **new_fname) +{ + FILE *fh; + char *tmp_fname; + + if (extension) { + tmp_fname = xdebug_sprintf("%s.%s", fname, extension); + } else { + tmp_fname = xdstrdup(fname); + } + fh = fopen(tmp_fname, mode); + if (fh && new_fname) { + *new_fname = tmp_fname; + } else { + xdfree(tmp_fname); + } + return fh; +} + +static FILE *xdebug_open_file_with_random_ext(char *fname, const char *mode, const char *extension, char **new_fname) +{ + FILE *fh; + char *tmp_fname; + + if (extension) { + tmp_fname = xdebug_sprintf("%s.%06x.%s", fname, (long) (1000000 * php_combined_lcg()), extension); + } else { + tmp_fname = xdebug_sprintf("%s.%06x", fname, (long) (1000000 * php_combined_lcg()), extension); + } + fh = fopen(tmp_fname, mode); + if (fh && new_fname) { + *new_fname = tmp_fname; + } else { + xdfree(tmp_fname); + } + return fh; +} + +FILE *xdebug_fopen(char *fname, const char *mode, const char *extension, char **new_fname) +{ + int r; + FILE *fh; + struct stat buf; + char *tmp_fname = NULL; + int filename_len = 0; + + /* We're not doing any tricks for append mode... as that has atomic writes + * anyway. And we ignore read mode as well. */ + if (mode0 == 'a' || mode0 == 'r') { + return xdebug_open_file(fname, mode, extension, new_fname); + } + + /* Make sure we don't open a file with a path that's too long */ + filename_len += (fname ? strlen(fname) : 0); /* filename */ + filename_len += (extension ? strlen(extension) : 0) + 1; /* extension (+ ".") */ + filename_len += 8; /* possible random extension (+ ".") */ + if (filename_len > NAME_MAX) { + fnameNAME_MAX - (extension ? strlen(extension) : 0 ) = '\0'; + } + + /* In write mode however we do have to do some stuff. */ + /* 1. Check if the file exists */ + if (extension) { + tmp_fname = xdebug_sprintf("%s.%s", fname, extension); + } else { + tmp_fname = xdstrdup(fname); + } + r = stat(tmp_fname, &buf); + /* We're not freeing "tmp_fname" as that is used in the freopen as well. */ + + if (r == -1) { + /* 2. Cool, the file doesn't exist so we can open it without probs now. */ + fh = xdebug_open_file(fname, "w", extension, new_fname); + goto lock; + } + + /* 3. It exists, check if we can open it. */ + fh = xdebug_open_file(fname, "r+", extension, new_fname); + if (!fh) { + /* 4. If fh == null we couldn't even open the file, so open a new one with a new name */ + fh = xdebug_open_file_with_random_ext(fname, "w", extension, new_fname); + goto lock; + } + + /* 5. It exists and we can open it, check if we can exclusively lock it. */ + r = flock(fileno(fh), LOCK_EX | LOCK_NB); + if (r == -1) { + if (errno == EWOULDBLOCK) { + fclose(fh); + /* 6. The file is in use, so we open one with a new name. */ + fh = xdebug_open_file_with_random_ext(fname, "w", extension, new_fname); + goto lock; + } + } + + /* 7. We established a lock, now we truncate and return the handle */ + fh = freopen(tmp_fname, "w", fh); + +lock: /* Yes yes, an evil goto label here!!! */ + if (fh) { + /* 8. We have to lock again after the reopen as that basically closes + * the file and opens it again. There is a small race condition here... + */ + flock(fileno(fh), LOCK_EX | LOCK_NB); + } + xdfree(tmp_fname); + return fh; +} +#else +FILE *xdebug_fopen(char *fname, const char *mode, const char *extension, char **new_fname) +{ + char *tmp_fname; + FILE *ret; + + if (extension) { + tmp_fname = xdebug_sprintf("%s.%s", fname, extension); + } else { + tmp_fname = xdstrdup(fname); + } + ret = fopen(tmp_fname, mode); + if (new_fname) { + *new_fname = tmp_fname; + } else { + xdfree(tmp_fname); + } + return ret; +} +#endif + + +int xdebug_format_output_filename(char **filename, char *format, char *script_name) +{ + xdebug_str fname = XDEBUG_STR_INITIALIZER; + char cwd128; + + while (*format) + { + if (*format != '%') { + xdebug_str_addc(&fname, *format); + } else { + format++; + switch (*format) + { + case 'c': /* crc32 of the current working directory */ + if (VCWD_GETCWD(cwd, 127)) { + xdebug_str_add_fmt(&fname, "%lu", xdebug_crc32(cwd, strlen(cwd))); + } + break; + + case 'p': /* pid */ + xdebug_str_add_fmt(&fname, ZEND_ULONG_FMT, xdebug_get_pid()); + break; + + case 'r': /* random number */ + xdebug_str_add_fmt(&fname, "%06x", (long) (1000000 * php_combined_lcg())); + break; + + case 's': { /* script fname */ + char *char_ptr, *script_name_tmp; + + /* we do not always have script_name available, so if we + * don't have it and this format specifier is used then we + * simple do nothing for this specifier */ + if (!script_name) { + break; + } + + /* create a copy to work on */ + script_name_tmp = xdstrdup(script_name); + + /* replace slashes, whitespace and colons with underscores */ + while ((char_ptr = strpbrk(script_name_tmp, "/\\: ")) != NULL) { + char_ptr0 = '_'; + } + /* replace .php with _php */ + char_ptr = strrchr(script_name_tmp, '.'); + if (char_ptr) { + char_ptr0 = '_'; + } + xdebug_str_add(&fname, script_name_tmp, 0); + xdfree(script_name_tmp); + } break; + + case 't': { /* timestamp (in seconds) */ + xdebug_str_add_fmt(&fname, "%lu", xdebug_get_nanotime() / NANOS_IN_SEC); + } break; + + case 'u': { /* timestamp (in microseconds) */ + uint64_t nanotime = xdebug_get_nanotime(); + + xdebug_str_add_fmt(&fname, "%lu.%06d", + nanotime / NANOS_IN_SEC, + (nanotime % NANOS_IN_SEC) / NANOS_IN_MICROSEC + ); + } break; + + case 'H': /* $_SERVER'HTTP_HOST' */ + case 'U': /* $_SERVER'UNIQUE_ID' */ + case 'R': { /* $_SERVER'REQUEST_URI' */ + char *char_ptr, *strval; + zval *data = NULL; + + if (Z_TYPE(PG(http_globals)TRACK_VARS_SERVER) == IS_ARRAY) { + switch (*format) { + case 'H': + data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_SERVER), "HTTP_HOST", sizeof("HTTP_HOST") - 1); + break; + case 'R': + data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_SERVER), "REQUEST_URI", sizeof("REQUEST_URI") - 1); + break; + case 'U': + data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_SERVER), "UNIQUE_ID", sizeof("UNIQUE_ID") - 1); + break; + } + + if (data) { + strval = estrdup(Z_STRVAL_P(data)); + /* replace slashes, dots, question marks, plus + * signs, ampersands, spaces and other evil chars + * with underscores */ + while ((char_ptr = strpbrk(strval, "/\\.?&+:*\"<>| ")) != NULL) { + char_ptr0 = '_'; + } + xdebug_str_add(&fname, strval, 0); + efree(strval); + } + } + } break; + + case 'S': { /* session id */ + zval *data; + char *char_ptr, *strval; + char *sess_name; + + sess_name = zend_ini_string((char*) "session.name", sizeof("session.name"), 0); + + if (sess_name && Z_TYPE(PG(http_globals)TRACK_VARS_COOKIE) == IS_ARRAY && + ((data = zend_hash_str_find(Z_ARRVAL(PG(http_globals)TRACK_VARS_COOKIE), sess_name, strlen(sess_name))) != NULL) && + Z_STRLEN_P(data) < 100 /* Prevent any unrealistically long data being set as filename */ + ) { + strval = estrdup(Z_STRVAL_P(data)); + /* replace slashes, dots, question marks, plus signs, + * ampersands and spaces with underscores */ + while ((char_ptr = strpbrk(strval, "/\\.?&+ ")) != NULL) { + char_ptr0 = '_'; + } + xdebug_str_add(&fname, strval, 0); + efree(strval); + } + } break; + + case '%': /* literal % */ + xdebug_str_addc(&fname, '%'); + break; + } + } + format++; + } + + *filename = fname.d; + + return fname.l; +} + +int xdebug_format_file_link(char **filename, const char *error_filename, int error_lineno) +{ + xdebug_str fname = XDEBUG_STR_INITIALIZER; + char *format = XINI_LIB(file_link_format); + + while (*format) + { + if (*format != '%') { + xdebug_str_addc(&fname, *format); + } else { + format++; + switch (*format) + { + case 'f': /* filename */ + xdebug_str_add(&fname, error_filename, 0); + break; + + case 'l': /* line number */ + xdebug_str_add_fmt(&fname, "%d", error_lineno); + break; + + case '%': /* literal % */ + xdebug_str_addc(&fname, '%'); + break; + } + } + format++; + } + + *filename = fname.d; + + return fname.l; +} + +int xdebug_format_filename(char **formatted_name, const char *default_fmt, zend_string *filename) +{ + xdebug_str fname = XDEBUG_STR_INITIALIZER; + char *name; + xdebug_str *parent, *ancester; + const char *full_filename = ZSTR_VAL(filename); + xdebug_arg *parts; + char *slash = xdebug_sprintf("%c", DEFAULT_SLASH); + char *fmt = XINI_LIB(filename_format); + const char *format = fmt && fmt0 ? fmt : default_fmt; /* If the format is empty, we use the default */ + + /* Create pointers for the format chars */ + parts = xdebug_arg_ctor(); + xdebug_explode(slash, full_filename, parts, -1); + name = parts->argsparts->c - 1; + parent = parts->c > 1 ? + xdebug_join(slash, parts, parts->c - 2, parts->c - 1) : + xdebug_str_create_from_char(name); + ancester = parts->c > 2 ? + xdebug_join(slash, parts, parts->c - 3, parts->c - 1) : + xdebug_str_copy(parent); + + while (*format) + { + if (*format != '%') { + xdebug_str_addc(&fname, *format); + } else { + format++; + switch (*format) + { + case 'n': /* filename */ + xdebug_str_add(&fname, name, 0); + break; + case 'p': /* parent */ + xdebug_str_add_str(&fname, parent); + break; + case 'a': /* ancester */ + xdebug_str_add_str(&fname, ancester); + break; + case 'f': /* full path */ + xdebug_str_add(&fname, full_filename, 0); + break; + case 's': /* slash */ + xdebug_str_addc(&fname, DEFAULT_SLASH); + break; + case '%': /* literal % */ + xdebug_str_addc(&fname, '%'); + break; + } + } + format++; + } + + xdfree(slash); + xdebug_str_free(ancester); + xdebug_str_free(parent); + xdebug_arg_dtor(parts); + + *formatted_name = fname.d; + + return fname.l; +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/usefulstuff.h
Changed
(renamed from xdebug-3.1.5/src/lib/usefulstuff.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/var.c
Added
@@ -0,0 +1,1153 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "lib/php-header.h" +#include "ext/standard/php_string.h" +#include "ext/standard/url.h" +#include "zend.h" +#include "zend_exceptions.h" +#include "zend_extensions.h" +#include "ext/standard/php_smart_string.h" +#include "zend_smart_str.h" +#include "zend_closures.h" + +#include "php_xdebug.h" + +#include "lib/compat.h" +#include "lib/lib_private.h" +#include "lib/mm.h" +#include "lib/var.h" +#include "lib/var_export_html.h" +#include "lib/var_export_line.h" +#include "lib/xml.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +static inline int object_or_ancestor_is_internal(zval dzval) +{ + zend_class_entry *tmp_ce = Z_OBJCE(dzval); + + do { + if (tmp_ce->type == ZEND_INTERNAL_CLASS) { + return 1; + } + tmp_ce = tmp_ce->parent; + } while (tmp_ce); + + return 0; +} + +typedef struct _xdebug_zend_closure_copy { + zend_object std; + zend_function func; + zval this_ptr; + zend_class_entry *called_scope; + zif_handler orig_internal_handler; +} xdebug_zend_closure_copy; + +static int object_with_missing_closure_variables(zval dzval) +{ + zend_class_entry *tmp_ce = NULL; + xdebug_zend_closure_copy *closure = NULL; + + if (Z_TYPE(dzval) != IS_OBJECT) { + return 0; + } + + tmp_ce = Z_OBJCE(dzval); + if (tmp_ce != zend_ce_closure) { + return 0; + } + + closure = (xdebug_zend_closure_copy *) Z_OBJ(dzval); + + if (closure->func.type == ZEND_USER_FUNCTION && closure->func.op_array.static_variables) { + HashTable *static_variables = ZEND_MAP_PTR_GET(closure->func.op_array.static_variables_ptr); + + if (!static_variables) { + return 1; + } + } + + return 0; +} + +HashTable *xdebug_objdebug_pp(zval **zval_pp, int flags) +{ + zval dzval = **zval_pp; + HashTable *tmp; + + if ( + !XG_BASE(in_debug_info) && + (object_or_ancestor_is_internal(dzval) || (flags & XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO)) && + !object_with_missing_closure_variables(dzval) && + Z_OBJ_HANDLER(dzval, get_debug_info) && + !EG(exception) + ) { + void *original_trace_context; + zend_object *orig_exception; + + xdebug_tracing_save_trace_context(&original_trace_context); + XG_BASE(in_debug_info) = 1; + orig_exception = EG(exception); + EG(exception) = NULL; + + tmp = zend_get_properties_for(&dzval, ZEND_PROP_PURPOSE_DEBUG); + + XG_BASE(in_debug_info) = 0; + xdebug_tracing_restore_trace_context(original_trace_context); + EG(exception) = orig_exception; + + return tmp; + } else { + return zend_get_properties_for(&dzval, ZEND_PROP_PURPOSE_VAR_EXPORT); + } + return NULL; +} + +char* xdebug_error_type_simple(int type) +{ + switch (type) { + case E_ERROR: + case E_CORE_ERROR: + case E_COMPILE_ERROR: + case E_USER_ERROR: + return xdstrdup("fatal-error"); + break; + case E_RECOVERABLE_ERROR: + return xdstrdup("recoverable-fatal-error"); + break; + case E_WARNING: + case E_CORE_WARNING: + case E_COMPILE_WARNING: + case E_USER_WARNING: + return xdstrdup("warning"); + break; + case E_PARSE: + return xdstrdup("parse-error"); + break; + case E_NOTICE: + case E_USER_NOTICE: + return xdstrdup("notice"); + break; + case E_STRICT: + return xdstrdup("strict-standards"); + break; + case E_DEPRECATED: + case E_USER_DEPRECATED: + return xdstrdup("deprecated"); + break; + case 0: + return xdstrdup("xdebug"); + break; + default: + return xdstrdup("unknown-error"); + break; + } +} + +char* xdebug_error_type(int type) +{ + switch (type) { + case E_ERROR: + case E_CORE_ERROR: + case E_COMPILE_ERROR: + case E_USER_ERROR: + return xdstrdup("Fatal error"); + break; + case E_RECOVERABLE_ERROR: + return xdstrdup("Recoverable fatal error"); + break; + case E_WARNING: + case E_CORE_WARNING: + case E_COMPILE_WARNING: + case E_USER_WARNING: + return xdstrdup("Warning"); + break; + case E_PARSE: + return xdstrdup("Parse error"); + break; + case E_NOTICE: + case E_USER_NOTICE: + return xdstrdup("Notice"); + break; + case E_STRICT: + return xdstrdup("Strict standards"); + break; + case E_DEPRECATED: + case E_USER_DEPRECATED: + return xdstrdup("Deprecated"); + break; + case 0: + return xdstrdup("Xdebug"); + break; + default: + return xdstrdup("Unknown error"); + break; + } +} + +/*************************************************************************************************************************************/ +#define T(offset) (*(union _temp_variable *)((char*)zdata->current_execute_data->Ts + offset)) + +zval *xdebug_get_zval_with_opline(zend_execute_data *zdata, const zend_op *opline, int node_type, const znode_op *node, int *is_var) +{ + return zend_get_zval_ptr(opline, node_type, node, zdata); +} + +zval *xdebug_get_zval(zend_execute_data *zdata, int node_type, const znode_op *node, int *is_var) +{ + return xdebug_get_zval_with_opline(zdata, zdata->opline, node_type, node, is_var); +} + + +/***************************************************************************** +** PHP Variable related utility functions +*/ + +/***************************************************************************** +** Data returning functions +*/ +#define XF_ST_ROOT 0 +#define XF_ST_ARRAY_INDEX_NUM 1 +#define XF_ST_ARRAY_INDEX_ASSOC 2 +#define XF_ST_OBJ_PROPERTY 3 +#define XF_ST_STATIC_ROOT 4 +#define XF_ST_STATIC_PROPERTY 5 +#define XF_ST_ESCAPED_OBJ_PROPERTY 6 + +inline static HashTable *fetch_ht_from_zval(zval *z) +{ + switch (Z_TYPE_P(z)) { + case IS_ARRAY: + return Z_ARRVAL_P(z); + break; + case IS_OBJECT: + return Z_OBJPROP_P(z); + break; + } + return NULL; +} + +inline static char *fetch_classname_from_zval(zval *z, int *length, zend_class_entry **ce) +{ + zend_string *class_name; + + if (Z_TYPE_P(z) == IS_INDIRECT) { + z = z->value.zv; + } + if (Z_TYPE_P(z) == IS_REFERENCE) { + z = &z->value.ref->val; + } + + if (Z_TYPE_P(z) != IS_OBJECT) { + return NULL; + } + + class_name = Z_OBJ_HANDLER_P(z, get_class_name)(Z_OBJ_P(z)); + + *ce = Z_OBJCE_P(z); + *length = class_name->len; + + return estrdup(class_name->val); +} + +static char* prepare_search_key(char *name, unsigned int *name_length, const char *prefix, int prefix_length) +{ + char *element; + int extra_length = 0; + + if (prefix_length) { + if (prefix0 == '*') { + extra_length = 3; + } else { + extra_length = 2 + prefix_length; + } + } + + element = malloc(*name_length + 1 + extra_length); + memset(element, 0, *name_length + 1 + extra_length); + if (extra_length) { + memcpy(element + 1, prefix, extra_length - 2); + } + memcpy(element + extra_length, name, *name_length); + *name_length += extra_length; + + return element; +} + +char *replace_star_by_null(const char *name, int name_length) +{ + char *tmp = xdstrdup(name); + int i; + + for (i = 0; i < name_length; i++) { + if (tmpi == '*') { + tmpi = '\0'; + } + } + + return tmp; +} + +static zval *get_arrayobject_storage(zval *parent, HashTable **properties) +{ + *properties = zend_get_properties_for(parent, ZEND_PROP_PURPOSE_DEBUG); + return zend_hash_str_find(*properties, "\0ArrayObject\0storage", sizeof("*ArrayObject*storage") - 1); +} + +static zval *get_splobjectstorage_storage(zval *parent, HashTable **properties) +{ + *properties = zend_get_properties_for(parent, ZEND_PROP_PURPOSE_DEBUG); + return zend_hash_str_find(*properties, "\0SplObjectStorage\0storage", sizeof("*SplObjectStorage*storage") - 1); +} + +static void fetch_zval_from_symbol_table( + zval *value_in, char *name, unsigned int name_length, + int type, char* ccn, int ccnl, zend_class_entry *cce) +{ + HashTable *ht = NULL; + char *element = NULL; + unsigned int element_length = name_length; + zend_property_info *zpp; + int free_duplicated_name = 0; + HashTable *myht = NULL; + zval *orig_value_in = value_in; + zval tmp_retval; + + ZVAL_UNDEF(&tmp_retval); + + if (Z_TYPE_P(value_in) == IS_INDIRECT) { + value_in = Z_INDIRECT_P(value_in); + } + ZVAL_DEREF(value_in); + + ht = fetch_ht_from_zval(value_in); + + switch (type) { + case XF_ST_STATIC_ROOT: + case XF_ST_STATIC_PROPERTY: + /* First we try a public,private,protected property */ + if (cce && (cce->type == ZEND_INTERNAL_CLASS || (cce->ce_flags & ZEND_ACC_IMMUTABLE))) { + zend_class_init_statics(cce); + } + + element = prepare_search_key(name, &element_length, "", 0); + if (cce && ((zpp = zend_hash_str_find_ptr(&cce->properties_info, element, element_length)) != NULL) && cce->default_static_members_count && CE_STATIC_MEMBERS(cce)) { + ZVAL_COPY(&tmp_retval, &CE_STATIC_MEMBERS(cce)zpp->offset); + goto cleanup; + } + element_length = name_length; + + /* Then we try to see whether the first char is * and use the part between * and * as class name for the private property */ + if (name0 == '*') { + char *secondStar; + + secondStar = strstr(name + 1, "*"); + if (secondStar) { + free(element); + element_length = name_length - (secondStar + 1 - name); + element = prepare_search_key(secondStar + 1, &element_length, "", 0); + if (cce && ((zpp = zend_hash_str_find_ptr(&cce->properties_info, element, element_length)) != NULL)) { + ZVAL_COPY(&tmp_retval, &CE_STATIC_MEMBERS(cce)zpp->offset); + goto cleanup; + } + } + } + + break; + + case XF_ST_ROOT: + /* Check for return value */ + if ( + XG_DBG(current_return_value) && + (strncmp(name, XDEBUG_RETURN_VALUE_VAR_NAME, name_length) == 0) + ) { + ZVAL_COPY(&tmp_retval, XG_DBG(current_return_value)); + goto cleanup; + } + + /* Check for compiled vars */ + element = prepare_search_key(name, &element_length, "", 0); + if (xdebug_lib_has_active_data() && xdebug_lib_has_active_function()) { + int i = 0; + zend_ulong hash_value = zend_inline_hash_func(element, element_length); + zend_op_array *opa = xdebug_lib_get_active_func_oparray(); + zval **CV; + + while (i < opa->last_var) { + if (ZSTR_H(opa->varsi) == hash_value && + ZSTR_LEN(opa->varsi) == element_length && + strncmp(STR_NAME_VAL(opa->varsi), element, element_length) == 0) + { + zval *CV_z = ZEND_CALL_VAR_NUM(xdebug_lib_get_active_data(), i); + CV = &CV_z; + if (CV) { + ZVAL_COPY(&tmp_retval, *CV); + goto cleanup; + } + } + i++; + } + } + free(element); + ht = xdebug_lib_get_active_symbol_table(); + + XDEBUG_BREAK_INTENTIONALLY_MISSING + + case XF_ST_ARRAY_INDEX_ASSOC: + element = prepare_search_key(name, &name_length, "", 0); + xdebug_stripcslashes(element, (int *) &name_length); + + /* Handle "this" in a different way */ + if (type == XF_ST_ROOT && strcmp("this", element) == 0) { + if (xdebug_lib_has_active_object()) { + ZVAL_COPY(&tmp_retval, xdebug_lib_get_active_object()); + } else { + ZVAL_NULL(&tmp_retval); + } + goto cleanup; + } + + if (ht) { + zval *tmp = zend_hash_str_find(ht, element, name_length); + if (tmp != NULL) { + ZVAL_COPY(&tmp_retval, tmp); + goto cleanup; + } + } + break; + + case XF_ST_ARRAY_INDEX_NUM: + element = prepare_search_key(name, &name_length, "", 0); + if (ht) { + zval *tmp = zend_hash_index_find(ht, strtoull(element, NULL, 10)); + if (tmp != NULL) { + ZVAL_COPY(&tmp_retval, tmp); + goto cleanup; + } + } + break; + + case XF_ST_ESCAPED_OBJ_PROPERTY: + name = xdstrndup(name, name_length); + free_duplicated_name = 1; + xdebug_stripcslashes(name, (int *) &name_length); + + XDEBUG_BREAK_INTENTIONALLY_MISSING + + case XF_ST_OBJ_PROPERTY: + /* Let's see if there is a debug handler */ + if (value_in && Z_TYPE_P(value_in) == IS_OBJECT) { + myht = xdebug_objdebug_pp(&value_in, XDEBUG_VAR_OBJDEBUG_DEFAULT); + + if (myht) { + /* As a normal (public) property */ + zval *tmp = zend_symtable_str_find(myht, name, name_length); + if (tmp != NULL) { + ZVAL_COPY(&tmp_retval, tmp); + zend_release_properties(myht); + goto cleanup; + } + + /* As a private property */ + { + char *unmangled = replace_star_by_null(name, name_length); + zval *tmp = zend_symtable_str_find(myht, unmangled, name_length); + if (tmp != NULL) { + ZVAL_COPY(&tmp_retval, tmp); + zend_release_properties(myht); + xdfree(unmangled); + goto cleanup; + } + xdfree(unmangled); + } + + zend_release_properties(myht); + } + } + /* First we try an object handler */ + if (cce) { + zval *tmp_val; + tmp_val = zend_read_property(cce, Z_OBJ_P(value_in), name, name_length, 1, &tmp_retval); + if (tmp_val != &tmp_retval && tmp_val != &EG(uninitialized_zval)) { + ZVAL_COPY(&tmp_retval, tmp_val); + goto cleanup; + } + + if (EG(exception)) { + zend_clear_exception(); + } + } + + /* Then we try a public property */ + element = prepare_search_key(name, &element_length, "", 0); + if (ht) { + zval *tmp = zend_symtable_str_find(ht, element, element_length); + if (tmp != NULL) { + ZVAL_COPY(&tmp_retval, tmp); + goto cleanup; + } + } + element_length = name_length; + + /* Then we try it again as protected property */ + free(element); + element = prepare_search_key(name, &element_length, "*", 1); + if (ht) { + zval *tmp = zend_hash_str_find(ht, element, element_length); + if (tmp != NULL) { + ZVAL_COPY(&tmp_retval, tmp); + goto cleanup; + } + } + element_length = name_length; + + /* Then we try it again as private property */ + free(element); + element = prepare_search_key(name, &element_length, ccn, ccnl); + if (ht) { + zval *tmp = zend_hash_str_find(ht, element, element_length); + if (tmp != NULL) { + ZVAL_COPY(&tmp_retval, tmp); + goto cleanup; + } + } + element_length = name_length; + + if (strncmp(ccn, "ArrayObject", ccnl) == 0 && strncmp(name, "storage", name_length) == 0) { + zval *tmp = get_arrayobject_storage(value_in, &myht); + element = NULL; + if (tmp != NULL) { + ZVAL_COPY(&tmp_retval, tmp); + zend_release_properties(myht); + goto cleanup; + } + zend_release_properties(myht); + } + + /* All right, time for a mega hack. It's SplObjectStorage access time! */ + if (strncmp(ccn, "SplObjectStorage", ccnl) == 0 && strncmp(name, "storage", name_length) == 0) { + zval *tmp = get_splobjectstorage_storage(value_in, &myht); + element = NULL; + if (tmp != NULL) { + ZVAL_COPY(&tmp_retval, tmp); + zend_release_properties(myht); + goto cleanup; + } + zend_release_properties(myht); + } + + break; + } + +cleanup: + if (element) { + free(element); + } + if (free_duplicated_name && name) { + xdfree(name); + } + + zval_ptr_dtor_nogc(orig_value_in); + ZVAL_COPY_VALUE(orig_value_in, &tmp_retval); +} + +inline static int is_objectish(zval *value) +{ + switch (Z_TYPE_P(value)) { + case IS_OBJECT: + return 1; + + case IS_INDIRECT: + if (Z_TYPE_P(Z_INDIRECT_P(value)) == IS_OBJECT) { + return 1; + } + break; + + case IS_REFERENCE: + if (Z_TYPE_P(Z_REFVAL_P(value)) == IS_OBJECT) { + return 1; + } + break; + } + + return 0; +} + +void xdebug_get_php_symbol(zval *retval, xdebug_str* name) +{ + int found = -1; + int state = 0; + char *ptr = name->d; + size_t ctr = 0; + char *keyword = NULL, *keyword_end = NULL; + int type = XF_ST_ROOT; + char *current_classname = NULL; + zend_class_entry *current_ce = NULL; + int cc_length = 0; + char quotechar = 0; + + ZVAL_UNDEF(retval); + + do { + if (ctr == name->l) { + found = 0; + } else { + switch (state) { + case 0: + if (ptrctr == '$') { + keyword = &ptrctr + 1; + break; + } + if (ptrctr == ':') { /* special tricks */ + keyword = &ptrctr; + state = 7; + break; + } + keyword = &ptrctr; + state = 1; + + XDEBUG_BREAK_INTENTIONALLY_MISSING + + case 1: + if (ptrctr == '') { + keyword_end = &ptrctr; + if (keyword) { + fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); + if (current_classname) { + efree(current_classname); + } + current_classname = NULL; + cc_length = 0; + current_ce = NULL; + keyword = NULL; + } + state = 3; + } else if (ptrctr == '-') { + keyword_end = &ptrctr; + if (keyword) { + fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); + if (current_classname) { + efree(current_classname); + } + current_classname = NULL; + cc_length = 0; + current_ce = NULL; + if (is_objectish(retval)) { + current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce); + } + keyword = NULL; + } + state = 2; + type = XF_ST_OBJ_PROPERTY; + } else if (ptrctr == ':') { + keyword_end = &ptrctr; + if (keyword) { + fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); + if (current_classname) { + efree(current_classname); + } + current_classname = NULL; + cc_length = 0; + if (is_objectish(retval)) { + current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce); + } + keyword = NULL; + } + state = 8; + type = XF_ST_STATIC_PROPERTY; + } + break; + case 2: + if (ptrctr != '>') { + if (ptrctr == '{') { + state = 11; + } else { + keyword = &ptrctr; + state = 1; + } + } + break; + case 8: + if (ptrctr != ':') { + keyword = &ptrctr; + state = 1; + } + break; + case 3: /* Parsing in ... */ + /* Associative arrays */ + if (ptrctr == '\'' || ptrctr == '"') { + state = 4; + keyword = &ptrctr + 1; + quotechar = ptrctr; + type = XF_ST_ARRAY_INDEX_ASSOC; + } + /* Numerical index */ + if (ptrctr >= '0' && ptrctr <= '9') { + cc_length = 0; + state = 6; + keyword = &ptrctr; + type = XF_ST_ARRAY_INDEX_NUM; + } + /* Numerical index starting with a - */ + if (ptrctr == '-') { + state = 9; + keyword = &ptrctr; + } + break; + case 9: + /* Numerical index starting with a - */ + if (ptrctr >= '0' && ptrctr <= '9') { + state = 6; + type = XF_ST_ARRAY_INDEX_NUM; + } + break; + case 4: + if (ptrctr == '\\') { + state = 10; /* Escaped character */ + } else if (ptrctr == quotechar) { + quotechar = 0; + state = 5; + keyword_end = &ptrctr; + fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); + if (current_classname) { + efree(current_classname); + } + current_classname = NULL; + cc_length = 0; + if (is_objectish(retval)) { + current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce); + } + keyword = NULL; + } + break; + case 10: /* Escaped character */ + state = 4; + break; + case 5: + if (ptrctr == '') { + state = 1; + } + break; + case 6: + if (ptrctr == '') { + state = 1; + keyword_end = &ptrctr; + fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); + if (current_classname) { + efree(current_classname); + } + current_classname = NULL; + cc_length = 0; + if (is_objectish(retval)) { + current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce); + } + keyword = NULL; + } + break; + case 7: /* special cases, started with a ":" */ + if (ptrctr == ':') { + function_stack_entry *active_fse = xdebug_lib_get_active_stack_entry(); + state = 1; + keyword_end = &ptrctr; + + if (strncmp(keyword, "::", 2) == 0 && active_fse->function.object_class) { /* static class properties */ + zend_class_entry *ce = zend_fetch_class(active_fse->function.object_class, ZEND_FETCH_CLASS_SELF); + + current_classname = estrdup(STR_NAME_VAL(ce->name)); + cc_length = strlen(STR_NAME_VAL(ce->name)); + current_ce = ce; + keyword = &ptrctr + 1; + + type = XF_ST_STATIC_ROOT; + } else { + keyword = NULL; + } + } + break; + + case 11: + if (ptrctr == '\'' || ptrctr == '"') { + state = 12; + keyword = &ptrctr + 1; + quotechar = ptrctr; + type = XF_ST_ESCAPED_OBJ_PROPERTY; + } + break; + + case 12: /* Inside {" */ + if (ptrctr == '\\') { + state = 13; /* Escaped character */ + } else if (ptrctr == quotechar) { + quotechar = 0; + state = 14; + keyword_end = &ptrctr; + fetch_zval_from_symbol_table(retval, keyword, keyword_end - keyword, type, current_classname, cc_length, current_ce); + if (current_classname) { + efree(current_classname); + } + current_classname = NULL; + cc_length = 0; + if (is_objectish(retval)) { + current_classname = fetch_classname_from_zval(retval, &cc_length, ¤t_ce); + } + keyword = NULL; + } + break; + case 13: /* Escaped character */ + state = 12; + break; + case 14: + if (ptrctr == '}') { + state = 1; + } + break; + } + ctr++; + } + } while (found < 0); + if (keyword != NULL) { + fetch_zval_from_symbol_table(retval, keyword, &ptrctr - keyword, type, current_classname, cc_length, current_ce); + } + if (current_classname) { + efree(current_classname); + } +} + + +xdebug_str* xdebug_get_property_type(zval* object, zval *val) +{ + xdebug_str *type_str = NULL; + zend_property_info *info; + + if (Z_TYPE_P(val) != IS_INDIRECT) { + return NULL; + } + val = Z_INDIRECT_P(val); + + info = zend_get_typed_property_info_for_slot(Z_OBJ_P(object), val); + + if (info) { + zend_string *type_info = zend_type_to_string(info->type); + type_str = xdebug_str_new(); + +# if PHP_VERSION_ID >= 80100 + if (info->flags & ZEND_ACC_READONLY) { + xdebug_str_add_literal(type_str, "readonly "); + } +# endif + + xdebug_str_add_zstr(type_str, type_info); + zend_string_release(type_info); + } + + return type_str; +} + +xdebug_str* xdebug_get_property_info(char *mangled_property, int mangled_len, const char **modifier, char **class_name) +{ + const char *cls_name, *tmp_prop_name; + size_t tmp_prop_name_len; + xdebug_str *property_name; + + zend_string *i_mangled = zend_string_init(mangled_property, mangled_len - 1, 0); + zend_unmangle_property_name_ex(i_mangled, &cls_name, &tmp_prop_name, &tmp_prop_name_len); + property_name = xdebug_str_create((char*) tmp_prop_name, tmp_prop_name_len); + *class_name = cls_name ? xdstrdup(cls_name) : NULL; + zend_string_release(i_mangled); + + if (*class_name) { + if (*class_name0 == '*') { + *modifier = "protected"; + } else { + *modifier = "private"; + } + } else { + *modifier = "public"; + } + + return property_name; +} + +#define XDEBUG_MAX_INT 2147483647 + +xdebug_var_export_options* xdebug_var_export_options_from_ini(void) +{ + xdebug_var_export_options *options; + options = xdmalloc(sizeof(xdebug_var_export_options)); + + options->max_children = XINI_LIB(display_max_children); + options->max_data = XINI_LIB(display_max_data); + options->max_depth = XINI_LIB(display_max_depth); + options->show_hidden = 0; + options->show_location = 1; + options->extended_properties = 0; + options->encode_as_extended_property = 0; + + if (options->max_children == -1 || options->max_children > XDEBUG_MAX_INT) { + options->max_children = XDEBUG_MAX_INT; + } else if (options->max_children < 1) { + options->max_children = 0; + } + + if (options->max_data == -1 || options->max_data > XDEBUG_MAX_INT) { + options->max_data = XDEBUG_MAX_INT; + } else if (options->max_data < 1) { + options->max_data = 0; + } + + if (options->max_depth == -1 || options->max_depth > 1023) { + options->max_depth = 1023; + } else if (options->max_depth < 1) { + options->max_depth = 0; + } + + options->runtime = (xdebug_var_runtime_page*) xdmalloc((options->max_depth + 1) * sizeof(xdebug_var_runtime_page)); + options->no_decoration = 0; + + return options; +} + +xdebug_var_export_options xdebug_var_nolimit_options = { XDEBUG_MAX_INT, XDEBUG_MAX_INT, 1023, 1, 0, 0, 0, NULL, 0 }; + +xdebug_var_export_options* xdebug_var_get_nolimit_options(void) +{ + return &xdebug_var_nolimit_options; +} + +/***************************************************************************** +** Normal variable printing routines +*/ + +#define XDEBUG_VAR_ATTR_TEXT 0 +#define XDEBUG_VAR_ATTR_FANCY 1 + +void xdebug_add_variable_attributes(xdebug_str *str, zval *struc, zend_bool html) +{ + if (html) { + xdebug_str_add_literal(str, "<i>("); + } else { + xdebug_str_add_literal(str, "("); + } + + if (Z_TYPE_P(struc) >= IS_STRING && Z_TYPE_P(struc) != IS_INDIRECT) { + if (Z_TYPE_P(struc) == IS_STRING && ZSTR_IS_INTERNED(Z_STR_P(struc))) { + xdebug_str_add_literal(str, "interned"); + } else if (Z_TYPE_P(struc) == IS_ARRAY && (GC_FLAGS(Z_ARRVAL_P(struc)) & IS_ARRAY_IMMUTABLE)) { + xdebug_str_add_literal(str, "immutable"); + } else { + xdebug_str_add_fmt(str, "refcount=%d", Z_REFCOUNT_P(struc)); + } + xdebug_str_add_fmt(str, ", is_ref=%d", Z_TYPE_P(struc) == IS_REFERENCE); + } else { + xdebug_str_add_literal(str, "refcount=0, is_ref=0"); + } + + if (html) { + xdebug_str_add_literal(str, ")</i>"); + } else { + xdebug_str_add_literal(str, ")="); + } +} + + +/***************************************************************************** +** XML encoding function +*/ +static const char xml_encode_count256 = { + 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 1, 5, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 6, 1, 1, 1, 5, 5, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 1, 4, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +}; + +static const char* xml_encode_map64 = { + "�", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, " ", NULL, NULL, " ", NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, """, NULL, NULL, NULL, "&", "'", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "<", NULL, ">", NULL, +}; + +char* xdebug_xmlize(char *s_string, size_t len, size_t *newlen) +{ + int i, w_pos; + int encoded_string_length = 0; + char *new_string; + const unsigned char *string = (unsigned char*) s_string; + + /* Quick bailout for empty strings */ + if (!len) { + *newlen = 0; + return estrdup(""); + } + + /* Calculate new memory requirement */ + for (i = 0; i < len; i++) { + encoded_string_length += xml_encode_countstringi; + } + + /* No characters need to be encoded, so just duplicate and return */ + if (encoded_string_length == len) { + *newlen = len; + return estrdup(s_string); + } + + new_string = emalloc(encoded_string_length + 1); + w_pos = 0; + for (i = 0; i < len; i++) { + int replacement_length = xml_encode_countstringi; + + if (replacement_length != 1) { + int j; + + for (j = 0; j < replacement_length; j++) { + new_stringw_pos = xml_encode_mapstringij; + w_pos++; + } + continue; + } + + new_stringw_pos = stringi; + w_pos++; + } + + new_stringw_pos = '\0'; + *newlen = encoded_string_length; /* remove one for null byte */ + + return new_string; +} + +/***************************************************************************** +** Function name printing function +*/ +static char* xdebug_create_doc_link(xdebug_func f) +{ + char *tmp_target = NULL, *p, *retval; + + switch (f.type) { + case XFUNC_NORMAL: { + tmp_target = xdebug_sprintf("function.%s", f.function); + break; + } + + case XFUNC_STATIC_MEMBER: + case XFUNC_MEMBER: { + if (strcmp(f.function, "__construct") == 0) { + tmp_target = xdebug_sprintf("%s.construct", ZSTR_VAL(f.object_class)); + } else { + tmp_target = xdebug_sprintf("%s.%s", ZSTR_VAL(f.object_class), f.function); + } + break; + } + } + + while ((p = strchr(tmp_target, '_')) != NULL) { + *p = '-'; + } + + retval = xdebug_sprintf("<a href='%s%s%s' target='_new'>%s</a>", + (PG(docref_root) && PG(docref_root)0) ? PG(docref_root) : "http://www.php.net/", + tmp_target, PG(docref_ext), f.function); + + xdfree(tmp_target); + + return retval; +} + +char* xdebug_show_fname(xdebug_func f, int flags) +{ + switch (f.type) { + case XFUNC_NORMAL: { + if (PG(html_errors) && (flags & XDEBUG_SHOW_FNAME_ALLOW_HTML) && f.internal) { + return xdebug_create_doc_link(f); + } else { + return xdstrdup(f.function); + } + break; + } + + case XFUNC_STATIC_MEMBER: + case XFUNC_MEMBER: { + if (PG(html_errors) && (flags & XDEBUG_SHOW_FNAME_ALLOW_HTML) && f.internal) { + return xdebug_create_doc_link(f); + } else { + if (f.scope_class && !(flags & XDEBUG_SHOW_FNAME_IGNORE_SCOPE)) { + return xdebug_sprintf("%s%s%s", + ZSTR_VAL(f.scope_class), + f.type == XFUNC_STATIC_MEMBER ? "::" : "->", + f.function ? f.function : "?" + ); + } + + return xdebug_sprintf("%s%s%s", + f.object_class ? ZSTR_VAL(f.object_class) : "?", + f.type == XFUNC_STATIC_MEMBER ? "::" : "->", + f.function ? f.function : "?" + ); + } + break; + } + + case XFUNC_EVAL: + return xdstrdup("eval"); + break; + + case XFUNC_INCLUDE: + return xdstrdup("include"); + break; + + case XFUNC_INCLUDE_ONCE: + return xdstrdup("include_once"); + break; + + case XFUNC_REQUIRE: + return xdstrdup("require"); + break; + + case XFUNC_REQUIRE_ONCE: + return xdstrdup("require_once"); + break; + + case XFUNC_MAIN: + return xdstrdup("{main}"); + break; + + case XFUNC_ZEND_PASS: + return xdstrdup("{zend_pass}"); + break; + +#if PHP_VERSION_ID >= 80100 + case XFUNC_FIBER: + return xdstrdup(f.function); + break; +#endif + + default: + return xdstrdup("{unknown}"); + } +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/var.h
Added
@@ -0,0 +1,89 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "lib/php-header.h" +#include "php_xdebug.h" + +#include "lib/compat.h" +#include "lib/lib.h" +#include "lib/str.h" +#include "lib/xml.h" + +#ifndef __HAVE_XDEBUG_VAR_H__ +#define __HAVE_XDEBUG_VAR_H__ + +/* Set correct int format to use */ +#include "Zend/zend_long.h" +#if SIZEOF_ZEND_LONG == 4 +# define XDEBUG_INT_FMT "%ld" +#else +# define XDEBUG_INT_FMT "%lld" +#endif + +typedef struct +{ + int page; /* The number of the page to retrieve */ + int current_element_nr; + int start_element_nr; + int end_element_nr; +} xdebug_var_runtime_page; + +typedef struct xdebug_var_export_options { + int max_children; + int max_data; + int max_depth; + int show_hidden; + int extended_properties; /* Whether the feature is enabled */ + int encode_as_extended_property; /* Whether the current node's elements need to be encoded */ + int show_location; + xdebug_var_runtime_page *runtime; + int no_decoration; +} xdebug_var_export_options; + +#define XDEBUG_VAR_TYPE_NORMAL 0x00 +#define XDEBUG_VAR_TYPE_STATIC 0x01 +#define XDEBUG_VAR_TYPE_CONSTANT 0x02 + +void xdebug_get_php_symbol(zval *retval, xdebug_str* name); + +xdebug_var_export_options* xdebug_var_export_options_from_ini(void); +xdebug_var_export_options* xdebug_var_get_nolimit_options(void); + +xdebug_str* xdebug_get_property_type(zval* object, zval *val); +xdebug_str* xdebug_get_property_info(char *mangled_property, int mangled_len, const char **modifier, char **class_name); + +#define XDEBUG_VAR_OBJDEBUG_DEFAULT 0x00 +#define XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO 0x01 +HashTable *xdebug_objdebug_pp(zval **zval_pp, int flags); + + +#define XDEBUG_VAR_ATTR_TEXT 0 +#define XDEBUG_VAR_ATTR_HTML 1 +void xdebug_add_variable_attributes(xdebug_str *str, zval *struc, zend_bool fancy); + + +char* xdebug_xmlize(char *s_string, size_t len, size_t *newlen); +char* xdebug_error_type_simple(int type); +char* xdebug_error_type(int type); +zval *xdebug_get_zval(zend_execute_data *zdata, int node_type, const znode_op *node, int *is_var); +zval *xdebug_get_zval_with_opline(zend_execute_data *zdata, const zend_op *opline, int node_type, const znode_op *node, int *is_var); + +#define XDEBUG_SHOW_FNAME_DEFAULT 0 +#define XDEBUG_SHOW_FNAME_ALLOW_HTML 1<<1 +#define XDEBUG_SHOW_FNAME_IGNORE_SCOPE 1<<2 +char* xdebug_show_fname(xdebug_func t, int flags); + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/var_export_html.c
Added
@@ -0,0 +1,462 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2021 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "var_export_html.h" +#include "lib_private.h" +#include "Zend/zend_closures.h" +#if PHP_VERSION_ID >= 80100 +# include "zend_enum.h" +#endif + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +/***************************************************************************** +** Fancy variable printing routines +*/ + +#define COLOR_POINTER "#888a85" +#define COLOR_BOOL "#75507b" +#define COLOR_LONG "#4e9a06" +#define COLOR_NULL "#3465a4" +#define COLOR_DOUBLE "#f57900" +#define COLOR_STRING "#cc0000" +#define COLOR_EMPTY "#888a85" +#define COLOR_ARRAY "#ce5c00" +#define COLOR_OBJECT "#8f5902" +#define COLOR_RESOURCE "#2e3436" + +static int xdebug_array_element_export_html(zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, xdebug_str *str, int debug_zval, xdebug_var_export_options *options) +{ + zval **zv = &zv_nptr; + size_t newlen; + char *tmp_str; + + if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && + options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) + { + xdebug_str_add_fmt(str, "%*s", (level * 4) - 2, ""); + + if (HASH_KEY_IS_NUMERIC(hash_key)) { /* numeric key */ + xdebug_str_add_fmt(str, XDEBUG_INT_FMT " <font color='%s'>=></font> ", index_key, COLOR_POINTER); + } else { /* string key */ + xdebug_str_addc(str, '\''); + tmp_str = xdebug_xmlize((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key) - 1, &newlen); + xdebug_str_addl(str, tmp_str, newlen, 0); + efree(tmp_str); + xdebug_str_add_fmt(str, "' <font color='%s'>=></font> ", COLOR_POINTER); + } + xdebug_var_export_html(zv, str, level + 1, debug_zval, options); + } + if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { + xdebug_str_add_fmt(str, "%*s", (level * 4) - 2, ""); + xdebug_str_add_literal(str, "<i>more elements...</i>\n"); + } + options->runtimelevel.current_element_nr++; + return 0; +} + +static int xdebug_object_element_export_html(zval *object, zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, xdebug_str *str, int debug_zval, xdebug_var_export_options *options, char *class_name) +{ + zval **zv = &zv_nptr; + + if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && + options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) + { + xdebug_str_add_fmt(str, "%*s", (level * 4) - 2, ""); + + if (!HASH_KEY_IS_NUMERIC(hash_key)) { + char *prop_class_name; + xdebug_str *property_name; + xdebug_str *property_type = NULL; + const char *modifier; + + property_type = xdebug_get_property_type(object, zv_nptr); + property_name = xdebug_get_property_info((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key), &modifier, &prop_class_name); + + xdebug_str_add_fmt(str, "<i>%s</i> ", modifier); + if (property_type) { + xdebug_str_add_fmt(str, "<i>%s</i> ", property_type->d); + } + xdebug_str_addc(str, '\''); + xdebug_str_add_str(str, property_name); + if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) { + xdebug_str_add_fmt(str, "' <font color='%s'>=></font> ", COLOR_POINTER); + } else { + xdebug_str_add_fmt(str, "' <small>(%s)</small> <font color='%s'>=></font> ", prop_class_name, COLOR_POINTER); + } + + if (property_type) { + xdebug_str_free(property_type); + } + xdebug_str_free(property_name); + xdfree(prop_class_name); + } else { + xdebug_str_add_fmt(str, "<i>public</i> " XDEBUG_INT_FMT " <font color='%s'>=></font> ", index_key, COLOR_POINTER); + } + xdebug_var_export_html(zv, str, level + 1, debug_zval, options); + } + if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { + xdebug_str_add_fmt(str, "%*s", (level * 4) - 2, ""); + xdebug_str_add_literal(str, "<i>more elements...</i>\n"); + } + options->runtimelevel.current_element_nr++; + return 0; +} + +static void handle_closure(xdebug_str *str, zval *obj, int level) +{ + const zend_function *closure_function; + + if (Z_TYPE_P(obj) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(obj), zend_ce_closure)) { + return; + } + + closure_function = zend_get_closure_method_def(Z_OBJ_P(obj)); + + xdebug_str_add_fmt(str, "%*s<i>virtual</i> 'closure' <font color='%s'>'", (level * 4) - 2, "", COLOR_STRING); + + if (closure_function->common.scope) { + if (closure_function->common.fn_flags & ZEND_ACC_STATIC) { + xdebug_str_add_zstr(str, closure_function->common.scope->name); + xdebug_str_add_literal(str, "::"); + } else { + xdebug_str_add_literal(str, "$this->"); + } + } + xdebug_str_add_zstr(str, closure_function->common.function_name); + + xdebug_str_add_literal(str, "'</font>\n"); +} + + +void xdebug_var_export_html(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options) +{ + HashTable *myht; + char* tmp_str; + size_t newlen; + zend_ulong num; + zend_string *key; + zval *val; + zval *tmpz; + int z_type; + + z_type = Z_TYPE_P(*struc); + + if (debug_zval) { + xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_HTML); + } + if (z_type == IS_INDIRECT) { + tmpz = Z_INDIRECT_P(*struc); + struc = &tmpz; + z_type = Z_TYPE_P(*struc); + } + if (z_type == IS_REFERENCE) { + tmpz = &((*struc)->value.ref->val); + struc = &tmpz; + z_type = Z_TYPE_P(*struc); + } + + switch (z_type) { + case IS_TRUE: + xdebug_str_add_fmt(str, "<small>boolean</small> <font color='%s'>true</font>", COLOR_BOOL); + break; + + case IS_FALSE: + xdebug_str_add_fmt(str, "<small>boolean</small> <font color='%s'>false</font>", COLOR_BOOL); + break; + + case IS_NULL: + xdebug_str_add_fmt(str, "<font color='%s'>null</font>", COLOR_NULL); + break; + + case IS_LONG: + xdebug_str_add_fmt(str, "<small>int</small> <font color='%s'>" XDEBUG_INT_FMT "</font>", COLOR_LONG, Z_LVAL_P(*struc)); + break; + + case IS_DOUBLE: + xdebug_str_add_fmt(str, "<small>float</small> <font color='%s'>%.*H</font>", COLOR_DOUBLE, (int) EG(precision), Z_DVAL_P(*struc)); + break; + + case IS_STRING: + xdebug_str_add_fmt(str, "<small>string</small> <font color='%s'>'", COLOR_STRING); + if ((size_t) Z_STRLEN_P(*struc) > (size_t) options->max_data) { + tmp_str = xdebug_xmlize(Z_STRVAL_P(*struc), options->max_data, &newlen); + xdebug_str_addl(str, tmp_str, newlen, 0); + efree(tmp_str); + xdebug_str_add_literal(str, "'...</font>"); + } else { + tmp_str = xdebug_xmlize(Z_STRVAL_P(*struc), Z_STRLEN_P(*struc), &newlen); + xdebug_str_addl(str, tmp_str, newlen, 0); + efree(tmp_str); + xdebug_str_add_literal(str, "'</font>"); + } + xdebug_str_add_fmt(str, " <i>(length=%d)</i>", Z_STRLEN_P(*struc)); + break; + + case IS_ARRAY: + myht = Z_ARRVAL_P(*struc); + xdebug_str_add_fmt(str, "\n%*s", (level - 1) * 4, ""); + + if (!xdebug_zend_hash_is_recursive(myht)) { + xdebug_str_add_fmt(str, "<b>array</b> <i>(size=%d)</i>\n", myht->nNumOfElements); + if (level <= options->max_depth) { + if (myht->nNumOfElements) { + options->runtimelevel.current_element_nr = 0; + options->runtimelevel.start_element_nr = 0; + options->runtimelevel.end_element_nr = options->max_children; + + xdebug_zend_hash_apply_protection_begin(myht); + + ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { + xdebug_array_element_export_html(val, num, key, level, str, debug_zval, options); + } ZEND_HASH_FOREACH_END(); + + xdebug_zend_hash_apply_protection_end(myht); + } else { + xdebug_str_add_fmt(str, "%*s", (level * 4) - 2, ""); + xdebug_str_add_fmt(str, "<i><font color='%s'>empty</font></i>\n", COLOR_EMPTY); + } + } else { + xdebug_str_add_fmt(str, "%*s...\n", (level * 4) - 2, ""); + } + } else { + xdebug_str_add_literal(str, "<i>&</i><b>array</b>\n"); + } + break; + + case IS_OBJECT: { +#if PHP_VERSION_ID >= 80100 + zend_class_entry *ce = Z_OBJCE_P(*struc); + if (ce->ce_flags & ZEND_ACC_ENUM) { + zval *case_name_zval = zend_enum_fetch_case_name(Z_OBJ_P(*struc)); + xdebug_str_add_fmt( + str, "<b>enum</b>(<i>%s::%s</i>)", + ZSTR_VAL(ce->name), + Z_STRVAL_P(case_name_zval) + ); + if (ce->enum_backing_type != IS_UNDEF) { + zval *value = zend_enum_fetch_case_value(Z_OBJ_P(*struc)); + + if (ce->enum_backing_type == IS_LONG) { + xdebug_str_add_fmt( + str, " : <small>int</small> <font color='%s'>" XDEBUG_INT_FMT "</font>", + COLOR_LONG, Z_LVAL_P(value) + ); + } + + if (ce->enum_backing_type == IS_STRING) { + xdebug_str_add_fmt( + str, " : <small>string</small> <font color='%s'>'%s'</font> <i>(length=%d)</i>", + COLOR_STRING, Z_STRVAL_P(value), Z_STRLEN_P(value) + ); + } + } + xdebug_str_addc(str, '\n'); + break; + } +#endif + + myht = xdebug_objdebug_pp(struc, XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO); + xdebug_str_add_fmt(str, "\n%*s", (level - 1) * 4, ""); + + if (!myht || !xdebug_zend_hash_is_recursive(myht)) { + xdebug_str_add_literal(str, "<b>object</b>(<i>"); + xdebug_str_add(str, ZSTR_VAL(Z_OBJCE_P(*struc)->name), 0); + xdebug_str_add_literal(str, "</i>)"); + xdebug_str_add_fmt(str, "<i>%d</i>\n", Z_OBJ_HANDLE_P(*struc)); + + handle_closure(str, *struc, level); + + if (myht && (level <= options->max_depth)) { + options->runtimelevel.current_element_nr = 0; + options->runtimelevel.start_element_nr = 0; + options->runtimelevel.end_element_nr = options->max_children; + + xdebug_zend_hash_apply_protection_begin(myht); + + ZEND_HASH_FOREACH_KEY_VAL(myht, num, key, val) { + xdebug_object_element_export_html(*struc, val, num, key, level, str, debug_zval, options, ZSTR_VAL(Z_OBJCE_P(*struc)->name)); + } ZEND_HASH_FOREACH_END(); + + xdebug_zend_hash_apply_protection_end(myht); + } else { + xdebug_str_add_fmt(str, "%*s...\n", (level * 4) - 2, ""); + } + } else { + xdebug_str_add_literal(str, "<i>&</i><b>object</b>(<i>"); + xdebug_str_add(str, ZSTR_VAL(Z_OBJCE_P(*struc)->name), 0); + xdebug_str_add_literal(str, "</i>)"); + xdebug_str_add_fmt(str, "<i>%d</i>\n", Z_OBJ_HANDLE_P(*struc)); + } + zend_release_properties(myht); + break; + } + + case IS_RESOURCE: { + char *type_name; + + type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); + xdebug_str_add_fmt(str, "<b>resource</b>(<i>%ld</i><font color='%s'>,</font> <i>%s</i>)", Z_RES_P(*struc)->handle, COLOR_RESOURCE, type_name ? type_name : "Unknown"); + break; + } + + case IS_UNDEF: + xdebug_str_add_fmt(str, "<font color='%s'>*uninitialized*</font>", COLOR_NULL); + break; + + default: + xdebug_str_add_fmt(str, "<font color='%s'>NFC</font>", COLOR_NULL); + break; + } + if (z_type != IS_ARRAY && z_type != IS_OBJECT) { + xdebug_str_addc(str, '\n'); + } +} + +xdebug_str* xdebug_get_zval_value_html(char *name, zval *val, int debug_zval, xdebug_var_export_options *options) +{ + xdebug_str *str = xdebug_str_new(); + int default_options = 0; + + if (!options) { + options = xdebug_var_export_options_from_ini(); + default_options = 1; + } + + xdebug_str_add_literal(str, "<pre class='xdebug-var-dump' dir='ltr'>"); + if (options->show_location && !debug_zval) { + char *formatted_filename; + xdebug_format_filename(&formatted_filename, "%f", zend_get_executed_filename_ex()); + + if (strlen(XINI_LIB(file_link_format)) > 0 && strcmp(zend_get_executed_filename(), "Unknown") != 0) { + char *file_link; + + xdebug_format_file_link(&file_link, zend_get_executed_filename(), zend_get_executed_lineno()); + xdebug_str_add_fmt(str, "\n<small><a href='%s'>%s:%d</a>:</small>", file_link, formatted_filename, zend_get_executed_lineno()); + xdfree(file_link); + } else { + xdebug_str_add_fmt(str, "\n<small>%s:%d:</small>", formatted_filename, zend_get_executed_lineno()); + } + + xdfree(formatted_filename); + } + xdebug_var_export_html(&val, str, 1, debug_zval, options); + xdebug_str_add_literal(str, "</pre>"); + + if (default_options) { + xdfree(options->runtime); + xdfree(options); + } + + return str; +} + +static void xdebug_var_synopsis_html(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options) +{ + HashTable *myht; + zval *tmpz; + int z_type; + + z_type = Z_TYPE_P(*struc); + + if (debug_zval) { + xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_HTML); + } + if (z_type == IS_REFERENCE) { + tmpz = &((*struc)->value.ref->val); + struc = &tmpz; + } + + switch (z_type) { + case IS_TRUE: + xdebug_str_add_fmt(str, "<font color='%s'>true</font>", COLOR_BOOL); + break; + + case IS_FALSE: + xdebug_str_add_fmt(str, "<font color='%s'>false</font>", COLOR_BOOL); + break; + + case IS_NULL: + xdebug_str_add_fmt(str, "<font color='%s'>null</font>", COLOR_NULL); + break; + + case IS_LONG: + xdebug_str_add_fmt(str, "<font color='%s'>long</font>", COLOR_LONG); + break; + + case IS_DOUBLE: + xdebug_str_add_fmt(str, "<font color='%s'>double</font>", COLOR_DOUBLE); + break; + + case IS_STRING: + xdebug_str_add_fmt(str, "<font color='%s'>string(%d)</font>", COLOR_STRING, Z_STRLEN_P(*struc)); + break; + + case IS_ARRAY: + myht = Z_ARRVAL_P(*struc); + xdebug_str_add_fmt(str, "<font color='%s'>array(%d)</font>", COLOR_ARRAY, myht->nNumOfElements); + break; + + case IS_OBJECT: { +#if PHP_VERSION_ID >= 80100 + zend_class_entry *ce = Z_OBJCE_P(*struc); + if (ce->ce_flags & ZEND_ACC_ENUM) { + zval *case_name_zval = zend_enum_fetch_case_name(Z_OBJ_P(*struc)); + xdebug_str_add_fmt( str, "<font color='%s'>enum(%s::%s)</font>", COLOR_OBJECT, ZSTR_VAL(ce->name), Z_STRVAL_P(case_name_zval)); + break; + } +#endif + + xdebug_str_add_fmt(str, "<font color='%s'>object(%s)%d</font>", COLOR_OBJECT, ZSTR_VAL(Z_OBJCE_P(*struc)->name), Z_OBJ_HANDLE_P(*struc)); + } break; + + case IS_RESOURCE: { + char *type_name; + + type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); + xdebug_str_add_fmt(str, "<font color='%s'>resource(%ld, %s)</font>", COLOR_RESOURCE, Z_RES_P(*struc)->handle, type_name ? type_name : "Unknown"); + break; + } + + case IS_UNDEF: + xdebug_str_add_fmt(str, "<font color='%s'>*uninitialized*</font>", COLOR_NULL); + break; + + default: + xdebug_str_add_fmt(str, "<font color='%s'>NFC</font>", COLOR_NULL); + break; + } +} + +xdebug_str* xdebug_get_zval_synopsis_html(const char *name, zval *val, int debug_zval, xdebug_var_export_options *options) +{ + xdebug_str *str = xdebug_str_new(); + int default_options = 0; + + if (!options) { + options = xdebug_var_export_options_from_ini(); + default_options = 1; + } + + xdebug_var_synopsis_html(&val, str, 1, debug_zval, options); + + if (default_options) { + xdfree(options->runtime); + xdfree(options); + } + + return str; +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/var_export_html.h
Changed
(renamed from xdebug-3.1.5/src/lib/var_export_html.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/var_export_line.c
Added
@@ -0,0 +1,449 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "lib/php-header.h" +#include "ext/standard/php_string.h" +#include "Zend/zend_closures.h" +#if PHP_VERSION_ID >= 80100 +# include "zend_enum.h" +#endif + +#include "var_export_line.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +static int xdebug_array_element_export(zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, xdebug_str *str, int debug_zval, xdebug_var_export_options *options) +{ + zval **zv = &zv_nptr; + + if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && + options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) + { + if (HASH_KEY_IS_NUMERIC(hash_key)) { /* numeric key */ + xdebug_str_add_fmt(str, XDEBUG_INT_FMT " => ", index_key); + } else { /* string key */ + zend_string *tmp, *tmp2; + + tmp = php_str_to_str(ZSTR_VAL(hash_key), ZSTR_LEN(hash_key), (char*) "'", 1, (char*) "\\'", 2); + tmp2 = php_str_to_str(ZSTR_VAL(tmp), ZSTR_LEN(tmp), (char*) "\0", 1, (char*) "\\0", 2); + if (tmp) { + zend_string_release(tmp); + } + xdebug_str_addc(str, '\''); + if (tmp2) { + xdebug_str_add_zstr(str, tmp2); + zend_string_release(tmp2); + } + xdebug_str_add_literal(str, "' => "); + } + xdebug_var_export_line(zv, str, level + 2, debug_zval, options); + xdebug_str_add_literal(str, ", "); + } + if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { + xdebug_str_add_literal(str, "..., "); + } + options->runtimelevel.current_element_nr++; + return 0; +} + +static int xdebug_object_element_export(zval *object, zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, xdebug_str *str, int debug_zval, xdebug_var_export_options *options, char *class_name) +{ + zval **zv = &zv_nptr; + + if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && + options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) + { + if (!HASH_KEY_IS_NUMERIC(hash_key)) { + xdebug_str *property_name; + xdebug_str *property_type = NULL; + char *prop_class_name; + const char *modifier; + + property_type = xdebug_get_property_type(object, zv_nptr); + property_name = xdebug_get_property_info((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key), &modifier, &prop_class_name); + xdebug_str_add(str, modifier, 0); + if (property_type) { + xdebug_str_addc(str, ' '); + xdebug_str_add_str(str, property_type); + } + xdebug_str_add_literal(str, " $"); + if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) { + xdebug_str_add_str(str, property_name); + xdebug_str_add_literal(str, " = "); + } else { + xdebug_str_addc(str, '{'); + xdebug_str_add(str, prop_class_name, 0); + xdebug_str_addc(str, '}'); + xdebug_str_add_str(str, property_name); + xdebug_str_add_literal(str, " = "); + } + + if (property_type) { + xdebug_str_free(property_type); + } + xdebug_str_free(property_name); + xdfree(prop_class_name); + } else { + xdebug_str_add_fmt(str, "public $%d = ", index_key); + } + xdebug_var_export_line(zv, str, level + 2, debug_zval, options); + xdebug_str_add_literal(str, "; "); + } + if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { + xdebug_str_add_literal(str, "...; "); + } + options->runtimelevel.current_element_nr++; + return 0; +} + +#if PHP_VERSION_ID < 80200 +static void handle_closure(xdebug_str *str, zval *obj) +{ + const zend_function *closure_function; + + if (Z_TYPE_P(obj) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(obj), zend_ce_closure)) { + return; + } + + closure_function = zend_get_closure_method_def(Z_OBJ_P(obj)); + + xdebug_str_add_literal(str, "virtual $closure = \""); + + if (closure_function->common.scope) { + if (closure_function->common.fn_flags & ZEND_ACC_STATIC) { + xdebug_str_add(str, ZSTR_VAL(closure_function->common.scope->name), 0); + xdebug_str_add_literal(str, "::"); + } else { + xdebug_str_add_literal(str, "$this->"); + } + } + xdebug_str_add_zstr(str, closure_function->common.function_name); + + xdebug_str_add_literal(str, "\", "); +} +#endif + +void xdebug_var_export_line(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options) +{ + HashTable *myht; + zend_ulong num; + zend_string *key; + zval *val; + zval *tmpz; + int z_type; + + if (!struc || !(*struc)) { + return; + } + + z_type = Z_TYPE_P(*struc); + + if (debug_zval) { + xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_TEXT); + } + if (z_type == IS_INDIRECT) { + tmpz = Z_INDIRECT_P(*struc); + struc = &tmpz; + z_type = Z_TYPE_P(*struc); + } + if (z_type == IS_REFERENCE) { + tmpz = &((*struc)->value.ref->val); + struc = &tmpz; + z_type = Z_TYPE_P(*struc); + } + + switch (z_type) { + case IS_TRUE: + xdebug_str_add_literal(str, "TRUE"); + break; + + case IS_FALSE: + xdebug_str_add_literal(str, "FALSE"); + break; + + case IS_NULL: + xdebug_str_add_literal(str, "NULL"); + break; + + case IS_LONG: + xdebug_str_add_fmt(str, XDEBUG_INT_FMT, Z_LVAL_P(*struc)); + break; + + case IS_DOUBLE: + xdebug_str_add_fmt(str, "%.*H", (int) EG(precision), Z_DVAL_P(*struc)); + break; + + case IS_STRING: { + if (options->no_decoration) { + xdebug_str_add_zstr(str, Z_STR_P(*struc)); + } else if ((size_t) Z_STRLEN_P(*struc) <= (size_t) options->max_data) { + zend_string *tmp_zstr; + + tmp_zstr = php_addcslashes(Z_STR_P(*struc), (char*) "'\\\0..\37", 7); + + xdebug_str_addc(str, '\''); + xdebug_str_add_zstr(str, tmp_zstr); + xdebug_str_addc(str, '\''); + + zend_string_release(tmp_zstr); + } else { + zend_string *tmp_zstr = php_addcslashes_str(ZSTR_VAL(Z_STR_P(*struc)), options->max_data, (char*) "'\\\0..\37", 7); + + xdebug_str_addc(str, '\''); + xdebug_str_add_zstr(str, tmp_zstr); + xdebug_str_add_literal(str, "\'..."); + + zend_string_release(tmp_zstr); + } + } break; + + case IS_ARRAY: + myht = Z_ARRVAL_P(*struc); + + if (!xdebug_zend_hash_is_recursive(myht)) { + if (debug_zval) { + xdebug_str_add_literal(str, "array ("); + } else { + xdebug_str_addc(str, ''); + } + if (level <= options->max_depth) { + options->runtimelevel.current_element_nr = 0; + options->runtimelevel.start_element_nr = 0; + options->runtimelevel.end_element_nr = options->max_children; + + xdebug_zend_hash_apply_protection_begin(myht); + + ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { + xdebug_array_element_export(val, num, key, level, str, debug_zval, options); + } ZEND_HASH_FOREACH_END(); + + xdebug_zend_hash_apply_protection_end(myht); + + /* Remove the ", " at the end of the string */ + if (myht->nNumOfElements > 0) { + xdebug_str_chop(str, 2); + } + } else { + xdebug_str_add_literal(str, "..."); + } + xdebug_str_addc(str, debug_zval ? ')' : ''); + } else { + xdebug_str_add_literal(str, "..."); + } + break; + + case IS_OBJECT: { +#if PHP_VERSION_ID >= 80100 + zend_class_entry *ce = Z_OBJCE_P(*struc); + if (ce->ce_flags & ZEND_ACC_ENUM) { + zval *case_name_zval = zend_enum_fetch_case_name(Z_OBJ_P(*struc)); + xdebug_str_add_fmt(str, "enum %s::%s", ZSTR_VAL(ce->name), Z_STRVAL_P(case_name_zval)); + + if (ce->enum_backing_type != IS_UNDEF) { + zval *value = zend_enum_fetch_case_value(Z_OBJ_P(*struc)); + + if (ce->enum_backing_type == IS_LONG) { + xdebug_str_add_fmt(str, "(" XDEBUG_INT_FMT ")", Z_LVAL_P(value)); + } + + if (ce->enum_backing_type == IS_STRING) { + zend_string *tmp_zstr = php_addcslashes(Z_STR_P(value), (char*) "'\\\0..\37", 7); + + xdebug_str_add_literal(str, "('"); + xdebug_str_add_zstr(str, tmp_zstr); + xdebug_str_add_literal(str, "')"); + + zend_string_release(tmp_zstr); + } + } + + break; + } +#endif + + myht = xdebug_objdebug_pp(struc, XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO); + + if (!myht || !xdebug_zend_hash_is_recursive(myht)) { + xdebug_str_add_literal(str, "class "); + xdebug_str_add(str, ZSTR_VAL(Z_OBJCE_P(*struc)->name), 0); + xdebug_str_add_literal(str, " { "); + +#if PHP_VERSION_ID < 80200 + handle_closure(str, *struc); +#endif + + if (myht && (level <= options->max_depth)) { + options->runtimelevel.current_element_nr = 0; + options->runtimelevel.start_element_nr = 0; + options->runtimelevel.end_element_nr = options->max_children; + + xdebug_zend_hash_apply_protection_begin(myht); + + ZEND_HASH_FOREACH_KEY_VAL(myht, num, key, val) { + xdebug_object_element_export(*struc, val, num, key, level, str, debug_zval, options, ZSTR_VAL(Z_OBJCE_P(*struc)->name)); + } ZEND_HASH_FOREACH_END(); + + xdebug_zend_hash_apply_protection_end(myht); + } else { + xdebug_str_add_literal(str, "..."); + } + /* Remove the ", " and "; " at the end of the string */ + if ( + str->l > 2 && + ((str->dstr->l - 2 == ',') || (str->dstr->l - 2 == ';' )) && + (str->dstr->l - 1 == ' ') + ) { + xdebug_str_chop(str, 2); + } + + xdebug_str_add_literal(str, " }"); + } else { + xdebug_str_add_literal(str, "..."); + } + zend_release_properties(myht); + break; + } + + case IS_RESOURCE: { + char *type_name; + + type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); + xdebug_str_add_fmt(str, "resource(%ld) of type (%s)", Z_RES_P(*struc)->handle, type_name ? type_name : "Unknown"); + break; + } + + case IS_UNDEF: + xdebug_str_add_literal(str, "*uninitialized*"); + break; + + default: + xdebug_str_add_literal(str, "NFC"); + break; + } +} + +xdebug_str* xdebug_get_zval_value_line(zval *val, int debug_zval, xdebug_var_export_options *options) +{ + xdebug_str *str = xdebug_str_new(); + int default_options = 0; + + if (!options) { + options = xdebug_var_export_options_from_ini(); + default_options = 1; + } + + xdebug_var_export_line(&val, str, 1, debug_zval, options); + + if (default_options) { + xdfree(options->runtime); + xdfree(options); + } + + return str; +} + +static void xdebug_var_synopsis(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options) +{ + HashTable *myht; + zval *tmpz; + + if (!struc || !(*struc)) { + return; + } + + if (debug_zval) { + xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_TEXT); + } + if (Z_TYPE_P(*struc) == IS_REFERENCE) { + tmpz = &((*struc)->value.ref->val); + struc = &tmpz; + } + + switch (Z_TYPE_P(*struc)) { + case IS_TRUE: + xdebug_str_add_literal(str, "true"); + break; + + case IS_FALSE: + xdebug_str_add_literal(str, "false"); + break; + + case IS_NULL: + xdebug_str_add_literal(str, "null"); + break; + + case IS_LONG: + xdebug_str_add_literal(str, "long"); + break; + + case IS_DOUBLE: + xdebug_str_add_literal(str, "double"); + break; + + case IS_STRING: + xdebug_str_add_fmt(str, "string(%d)", Z_STRLEN_P(*struc)); + break; + + case IS_ARRAY: + myht = Z_ARRVAL_P(*struc); + xdebug_str_add_fmt(str, "array(%d)", myht->nNumOfElements); + break; + + case IS_OBJECT: { + xdebug_str_add_literal(str, "class "); + xdebug_str_add(str, ZSTR_VAL(Z_OBJCE_P(*struc)->name), 0); + break; + } + + case IS_RESOURCE: { + char *type_name; + + type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); + xdebug_str_add_fmt(str, "resource(%ld) of type (%s)", Z_RES_P(*struc)->handle, type_name ? type_name : "Unknown"); + break; + } + + case IS_UNDEF: + xdebug_str_add_literal(str, "*uninitialized*"); + break; + + default: + xdebug_str_add_literal(str, "NFC"); + break; + + } +} + +xdebug_str* xdebug_get_zval_synopsis_line(zval *val, int debug_zval, xdebug_var_export_options *options) +{ + xdebug_str *str = xdebug_str_new(); + int default_options = 0; + + if (!options) { + options = xdebug_var_export_options_from_ini(); + default_options = 1; + } + + xdebug_var_synopsis(&val, str, 1, debug_zval, options); + + if (default_options) { + xdfree(options->runtime); + xdfree(options); + } + + return str; +} +
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/var_export_line.h
Changed
(renamed from xdebug-3.1.5/src/lib/var_export_line.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/var_export_text.c
Added
@@ -0,0 +1,505 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "lib/php-header.h" +#include "ext/standard/php_string.h" +#include "Zend/zend_closures.h" +#if PHP_VERSION_ID >= 80100 +# include "zend_enum.h" +#endif + + +#include "php_xdebug.h" + +#include "var_export_text.h" + +static void xdebug_var_export_text_ansi(zval **struc, xdebug_str *str, int mode, int level, int debug_zval, xdebug_var_export_options *options); +#define xdebug_var_export_text(struc, str, level, debug_zval, options) xdebug_var_export_text_ansi(struc, str, 0, level, debug_zval, options); +#define xdebug_var_export_ansi(struc, str, level, debug_zval, options) xdebug_var_export_text_ansi(struc, str, 1, level, debug_zval, options); + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + + +/***************************************************************************** +** Plain text/ANSI coloured variable printing routines +*/ + +#define ANSI_COLOR_POINTER (mode == 1 ? "0m" : "") +#define ANSI_COLOR_BOOL (mode == 1 ? "35m" : "") +#define ANSI_COLOR_LONG (mode == 1 ? "32m" : "") +#define ANSI_COLOR_NULL (mode == 1 ? "34m" : "") +#define ANSI_COLOR_DOUBLE (mode == 1 ? "33m" : "") +#define ANSI_COLOR_STRING (mode == 1 ? "31m" : "") +#define ANSI_COLOR_EMPTY (mode == 1 ? "30m" : "") +#define ANSI_COLOR_ARRAY (mode == 1 ? "33m" : "") +#define ANSI_COLOR_OBJECT (mode == 1 ? "31m" : "") +#define ANSI_COLOR_RESOURCE (mode == 1 ? "36m" : "") +#define ANSI_COLOR_MODIFIER (mode == 1 ? "32m" : "") +#define ANSI_COLOR_RESET (mode == 1 ? "0m" : "") +#define ANSI_COLOR_BOLD (mode == 1 ? "1m" : "") +#define ANSI_COLOR_BOLD_OFF (mode == 1 ? "22m" : "") + +static int xdebug_array_element_export_text_ansi(zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, int mode, xdebug_str *str, int debug_zval, xdebug_var_export_options *options) +{ + zval **zv = &zv_nptr; + + if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && + options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) + { + xdebug_str_add_fmt(str, "%*s", (level * 2), ""); + + if (HASH_KEY_IS_NUMERIC(hash_key)) { /* numeric key */ + xdebug_str_add_fmt(str, "" XDEBUG_INT_FMT " %s=>%s\n", index_key, ANSI_COLOR_POINTER, ANSI_COLOR_RESET); + } else { /* string key */ + zend_string *tmp, *tmp2; + + tmp = php_str_to_str(ZSTR_VAL(hash_key), ZSTR_LEN(hash_key), (char*) "'", 1, (char*) "\\'", 2); + tmp2 = php_str_to_str(ZSTR_VAL(tmp), ZSTR_LEN(tmp), (char*) "\0", 1, (char*) "\\0", 2); + if (tmp) { + zend_string_release(tmp); + } + xdebug_str_addc(str, '\''); + if (tmp2) { + xdebug_str_add_zstr(str, tmp2); + zend_string_release(tmp2); + } + xdebug_str_add_literal(str, "' =>\n"); + } + xdebug_var_export_text_ansi(zv, str, mode, level + 1, debug_zval, options); + } + if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { + xdebug_str_add_fmt(str, "\n%*s(more elements)...\n", (level * 2), ""); + } + options->runtimelevel.current_element_nr++; + return 0; +} + +static int xdebug_object_element_export_text_ansi(zval *object, zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, int mode, xdebug_str *str, int debug_zval, xdebug_var_export_options *options) +{ + zval **zv = &zv_nptr; + + if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && + options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) + { + xdebug_str_add_fmt(str, "%*s", (level * 2), ""); + + if (!HASH_KEY_IS_NUMERIC(hash_key)) { + char *class_name; + xdebug_str *property_name; + const char *modifier; + xdebug_str *property_type = NULL; + + property_type = xdebug_get_property_type(object, zv_nptr); + + property_name = xdebug_get_property_info((char*) HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key), &modifier, &class_name); + xdebug_str_add_fmt( + str, "%s%s%s%s%s%s%s $", + ANSI_COLOR_MODIFIER, ANSI_COLOR_BOLD, modifier, ANSI_COLOR_BOLD_OFF, property_type ? " " : "", property_type ? property_type->d : "", ANSI_COLOR_RESET + ); + xdebug_str_add_str(str, property_name); + xdebug_str_add_fmt(str, " %s=>%s\n", ANSI_COLOR_POINTER, ANSI_COLOR_RESET); + + if (property_type) { + xdebug_str_free(property_type); + } + xdebug_str_free(property_name); + xdfree(class_name); + } else { + xdebug_str_add_fmt(str, "%s%spublic%s%s ${" XDEBUG_INT_FMT "} %s=>%s\n", + ANSI_COLOR_MODIFIER, ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_RESET, + index_key, ANSI_COLOR_POINTER, ANSI_COLOR_RESET + ); + } + xdebug_var_export_text_ansi(zv, str, mode, level + 1, debug_zval, options); + } + if (options->runtimelevel.current_element_nr == options->runtimelevel.end_element_nr) { + xdebug_str_add_fmt(str, "\n%*s(more elements)...\n", (level * 2), ""); + } + options->runtimelevel.current_element_nr++; + return 0; +} + +#if PHP_VERSION_ID < 80200 +static void handle_closure(xdebug_str *str, zval *obj, int level, int mode) +{ + const zend_function *closure_function; + + if (Z_TYPE_P(obj) != IS_OBJECT || !instanceof_function(Z_OBJCE_P(obj), zend_ce_closure)) { + return; + } + + closure_function = zend_get_closure_method_def(Z_OBJ_P(obj)); + + xdebug_str_add_fmt( + str, "%*s%s%svirtual%s $closure =>\n%*s\"", + (level * 4) - 2, "", + ANSI_COLOR_MODIFIER, ANSI_COLOR_BOLD, ANSI_COLOR_RESET, + (level * 4) - 2, "" + ); + + if (closure_function->common.scope) { + if (closure_function->common.fn_flags & ZEND_ACC_STATIC) { + xdebug_str_add_fmt(str, "%s", ANSI_COLOR_OBJECT); + xdebug_str_add_zstr(str, closure_function->common.scope->name); + xdebug_str_add_fmt(str, "%s::", ANSI_COLOR_RESET); + } else { + xdebug_str_add_fmt(str, "%s$this%s->", ANSI_COLOR_OBJECT, ANSI_COLOR_RESET); + } + } + + xdebug_str_add_fmt(str, "%s", ANSI_COLOR_STRING); + xdebug_str_add_zstr(str, closure_function->common.function_name); + xdebug_str_add_fmt(str, "%s\"\n", ANSI_COLOR_RESET); +} +#endif + +static void xdebug_var_export_text_ansi(zval **struc, xdebug_str *str, int mode, int level, int debug_zval, xdebug_var_export_options *options) +{ + HashTable *myht; + char* tmp_str; + int tmp_len; + zend_ulong num; + zend_string *key; + zval *val; + zval *tmpz; + int z_type; + + if (!struc || !(*struc)) { + return; + } + + xdebug_str_add_fmt(str, "%*s", (level * 2) - 2, ""); + + z_type = Z_TYPE_P(*struc); + + if (debug_zval) { + xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_TEXT); + } + if (z_type == IS_INDIRECT) { + tmpz = Z_INDIRECT_P(*struc); + struc = &tmpz; + z_type = Z_TYPE_P(*struc); + } + if (z_type == IS_REFERENCE) { + tmpz = &((*struc)->value.ref->val); + struc = &tmpz; + z_type = Z_TYPE_P(*struc); + } + + switch (z_type) { + case IS_TRUE: + xdebug_str_add_fmt(str, "%sbool%s(%s%s%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_BOOL, "true", ANSI_COLOR_RESET); + break; + + case IS_FALSE: + xdebug_str_add_fmt(str, "%sbool%s(%s%s%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_BOOL, "false", ANSI_COLOR_RESET); + break; + + case IS_NULL: + xdebug_str_add_fmt(str, "%s%sNULL%s%s", ANSI_COLOR_BOLD, ANSI_COLOR_NULL, ANSI_COLOR_RESET, ANSI_COLOR_BOLD_OFF); + break; + + case IS_LONG: + xdebug_str_add_fmt(str, "%sint%s(%s" XDEBUG_INT_FMT "%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_LONG, Z_LVAL_P(*struc), ANSI_COLOR_RESET); + break; + + case IS_DOUBLE: + xdebug_str_add_fmt(str, "%sdouble%s(%s%.*H%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_DOUBLE, (int) EG(precision), Z_DVAL_P(*struc), ANSI_COLOR_RESET); + break; + + case IS_STRING: { + const char *pattern = (mode == 1) ? "'\\\0..\37" : "\0"; + size_t pattern_len = (mode == 1) ? 7 : 1; + + zend_string *i_string = zend_string_init(Z_STRVAL_P(*struc), Z_STRLEN_P(*struc), 0); + zend_string *tmp_zstr; + + tmp_zstr = php_addcslashes(i_string, (char*) pattern, pattern_len); + + tmp_str = estrndup(tmp_zstr->val, tmp_zstr->len); + tmp_len = tmp_zstr->len; + zend_string_release(tmp_zstr); + zend_string_release(i_string); + + if (options->no_decoration) { + xdebug_str_addl(str, tmp_str, tmp_len, 0); + } else if ((size_t) Z_STRLEN_P(*struc) <= (size_t) options->max_data) { + xdebug_str_add_fmt( + str, "%sstring%s(%s%ld%s) \"%s%s%s\"", + ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, + ANSI_COLOR_LONG, Z_STRLEN_P(*struc), ANSI_COLOR_RESET, + ANSI_COLOR_STRING, tmp_str, ANSI_COLOR_RESET + ); + } else { + xdebug_str_add_fmt( + str, "%sstring%s(%s%ld%s) \"%s", + ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, + ANSI_COLOR_LONG, Z_STRLEN_P(*struc), ANSI_COLOR_RESET, ANSI_COLOR_STRING + ); + xdebug_str_addl(str, tmp_str, options->max_data, 0); + xdebug_str_add_fmt(str, "%s\"...", ANSI_COLOR_RESET); + } + efree(tmp_str); + } break; + + case IS_ARRAY: + myht = Z_ARRVAL_P(*struc); + + if (!xdebug_zend_hash_is_recursive(myht)) { + xdebug_str_add_fmt(str, "%sarray%s(%s%d%s) {\n", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_LONG, myht->nNumOfElements, ANSI_COLOR_RESET); + if (level <= options->max_depth) { + options->runtimelevel.current_element_nr = 0; + options->runtimelevel.start_element_nr = 0; + options->runtimelevel.end_element_nr = options->max_children; + + xdebug_zend_hash_apply_protection_begin(myht); + + ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) { + xdebug_array_element_export_text_ansi(val, num, key, level, mode, str, debug_zval, options); + } ZEND_HASH_FOREACH_END(); + + xdebug_zend_hash_apply_protection_end(myht); + } else { + xdebug_str_add_fmt(str, "%*s...\n", (level * 2), ""); + } + xdebug_str_add_fmt(str, "%*s}", (level * 2) - 2 , ""); + } else { + xdebug_str_add_fmt(str, "&%sarray%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); + } + break; + + case IS_OBJECT: { +#if PHP_VERSION_ID >= 80100 + zend_class_entry *ce = Z_OBJCE_P(*struc); + if (ce->ce_flags & ZEND_ACC_ENUM) { + zval *case_name_zval = zend_enum_fetch_case_name(Z_OBJ_P(*struc)); + xdebug_str_add_fmt( + str, "%senum%s %s%s%s::%s%s%s", + ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, + ANSI_COLOR_OBJECT, ZSTR_VAL(ce->name), ANSI_COLOR_RESET, + ANSI_COLOR_STRING, Z_STRVAL_P(case_name_zval), ANSI_COLOR_RESET + ); + if (ce->enum_backing_type != IS_UNDEF) { + zval *value = zend_enum_fetch_case_value(Z_OBJ_P(*struc)); + + if (ce->enum_backing_type == IS_LONG) { + xdebug_str_add_fmt( + str, " : %s%s%s(%s%d%s)", + ANSI_COLOR_BOLD, "int", ANSI_COLOR_RESET, + ANSI_COLOR_LONG, Z_LVAL_P(value), ANSI_COLOR_RESET + ); + } + + if (ce->enum_backing_type == IS_STRING) { + xdebug_str_add_fmt( + str, " : %s%s%s(%s\"%s\"%s)", + ANSI_COLOR_BOLD, "string", ANSI_COLOR_RESET, + ANSI_COLOR_STRING, Z_STRVAL_P(value), ANSI_COLOR_RESET + ); + } + } + xdebug_str_addc(str, ';'); + break; + } +#endif + + myht = xdebug_objdebug_pp(struc, XDEBUG_VAR_OBJDEBUG_USE_DEBUGINFO); + + if (!myht || !xdebug_zend_hash_is_recursive(myht)) { + xdebug_str_add_fmt( + str, "%sclass%s %s%s%s#%d (%s%d%s) {\n", + ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, + ANSI_COLOR_OBJECT, STR_NAME_VAL(Z_OBJCE_P(*struc)->name), ANSI_COLOR_RESET, + Z_OBJ_HANDLE_P(*struc), + ANSI_COLOR_LONG, myht ? myht->nNumOfElements : 0, ANSI_COLOR_RESET + ); + +#if PHP_VERSION_ID < 80200 + handle_closure(str, *struc, level, mode); +#endif + + if (myht && (level <= options->max_depth)) { + options->runtimelevel.current_element_nr = 0; + options->runtimelevel.start_element_nr = 0; + options->runtimelevel.end_element_nr = options->max_children; + + xdebug_zend_hash_apply_protection_begin(myht); + + ZEND_HASH_FOREACH_KEY_VAL(myht, num, key, val) { + xdebug_object_element_export_text_ansi(*struc, val, num, key, level, mode, str, debug_zval, options); + } ZEND_HASH_FOREACH_END(); + + xdebug_zend_hash_apply_protection_end(myht); + } else { + xdebug_str_add_fmt(str, "%*s...\n", (level * 2), ""); + } + xdebug_str_add_fmt(str, "%*s}", (level * 2) - 2, ""); + } else { + xdebug_str_add_fmt(str, "%*s...\n", (level * 2), ""); + } + zend_release_properties(myht); + break; + } + + case IS_RESOURCE: { + char *type_name; + + type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); + xdebug_str_add_fmt( + str, "%sresource%s(%s%ld%s) of type (%s)", + ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, + ANSI_COLOR_RESOURCE, Z_RES_P(*struc)->handle, ANSI_COLOR_RESET, type_name ? type_name : "Unknown" + ); + break; + } + + case IS_UNDEF: + xdebug_str_add_fmt(str, "%s*uninitialized*%s", ANSI_COLOR_NULL, ANSI_COLOR_RESET); + break; + + default: + xdebug_str_add_fmt(str, "%sNFC%s", ANSI_COLOR_NULL, ANSI_COLOR_RESET); + break; + } + + xdebug_str_addc(str, '\n'); +} + +xdebug_str* xdebug_get_zval_value_text_ansi(zval *val, int mode, int debug_zval, xdebug_var_export_options *options) +{ + xdebug_str *str = xdebug_str_new(); + int default_options = 0; + + if (!options) { + options = xdebug_var_export_options_from_ini(); + default_options = 1; + } + + if (options->show_location && !debug_zval) { + char *formatted_filename; + + xdebug_format_filename(&formatted_filename, "%f", zend_get_executed_filename_ex()); + xdebug_str_add_fmt(str, "%s%s%s:%s%d%s:\n", ANSI_COLOR_BOLD, formatted_filename, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_BOLD, zend_get_executed_lineno(), ANSI_COLOR_BOLD_OFF); + xdfree(formatted_filename); + } + + xdebug_var_export_text_ansi(&val, str, mode, 1, debug_zval, options); + + if (default_options) { + xdfree(options->runtime); + xdfree(options); + } + + return str; +} + +static void xdebug_var_synopsis_text_ansi(zval **struc, xdebug_str *str, int mode, int level, int debug_zval, xdebug_var_export_options *options) +{ + HashTable *myht; + zval *tmpz; + int z_type; + + if (!struc || !(*struc)) { + return; + } + + z_type = Z_TYPE_P(*struc); + + if (debug_zval) { + xdebug_add_variable_attributes(str, *struc, XDEBUG_VAR_ATTR_TEXT); + } + if (z_type == IS_REFERENCE) { + tmpz = &((*struc)->value.ref->val); + struc = &tmpz; + z_type = Z_TYPE_P(*struc); + } + + switch (z_type) { + case IS_TRUE: + xdebug_str_add_fmt(str, "%strue%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); + break; + + case IS_FALSE: + xdebug_str_add_fmt(str, "%sfalse%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); + break; + + case IS_NULL: + xdebug_str_add_fmt(str, "%snull%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); + break; + + case IS_LONG: + xdebug_str_add_fmt(str, "%sint%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); + break; + + case IS_DOUBLE: + xdebug_str_add_fmt(str, "%sdouble%s", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF); + break; + + case IS_STRING: + xdebug_str_add_fmt(str, "%sstring%s(%s%d%s)", ANSI_COLOR_BOLD, ANSI_COLOR_BOLD_OFF, ANSI_COLOR_LONG, Z_STRLEN_P(*struc), ANSI_COLOR_RESET); + break; + + case IS_ARRAY: + myht = Z_ARRVAL_P(*struc); + xdebug_str_add_fmt(str, "array(%s%d%s)", ANSI_COLOR_LONG, myht->nNumOfElements, ANSI_COLOR_RESET); + break; + + case IS_OBJECT: + xdebug_str_add_fmt(str, "class %s", ZSTR_VAL(Z_OBJCE_P(*struc)->name)); + break; + + case IS_RESOURCE: { + char *type_name; + + type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); + xdebug_str_add_fmt(str, "resource(%s%ld%s) of type (%s)", ANSI_COLOR_LONG, Z_RES_P(*struc)->handle, ANSI_COLOR_RESET, type_name ? type_name : "Unknown"); + break; + } + + case IS_UNDEF: + xdebug_str_add_fmt(str, "%s*uninitialized*%s", ANSI_COLOR_NULL, ANSI_COLOR_RESET); + break; + + default: + xdebug_str_add_fmt(str, "%sNFC%s", ANSI_COLOR_NULL, ANSI_COLOR_RESET); + break; + } +} + +xdebug_str* xdebug_get_zval_synopsis_text_ansi(zval *val, int mode, int debug_zval, xdebug_var_export_options *options) +{ + xdebug_str *str = xdebug_str_new(); + int default_options = 0; + + if (!options) { + options = xdebug_var_export_options_from_ini(); + default_options = 1; + } + + if (options->show_location && !debug_zval) { + xdebug_str_add_fmt(str, "%s%s: %d%s\n", ANSI_COLOR_BOLD, zend_get_executed_filename(), zend_get_executed_lineno(), ANSI_COLOR_BOLD_OFF); + } + + xdebug_var_synopsis_text_ansi(&val, str, mode, 1, debug_zval, options); + + if (default_options) { + xdfree(options->runtime); + xdfree(options); + } + + return str; +} +
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/var_export_text.h
Changed
(renamed from xdebug-3.1.5/src/lib/var_export_text.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/var_export_xml.c
Added
@@ -0,0 +1,827 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2021 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#include "var_export_xml.h" +#include "Zend/zend_closures.h" + +static xdebug_str *prepare_variable_name(xdebug_str *name) +{ + xdebug_str *tmp_name; + + if (name->d0 == '$' || name->d0 == ':') { + tmp_name = xdebug_str_copy(name); + } else { + tmp_name = xdebug_str_new(); + xdebug_str_addc(tmp_name, '$'); + xdebug_str_add_str(tmp_name, name); + } + if (tmp_name->dtmp_name->l - 2 == ':' && tmp_name->dtmp_name->l - 1 == ':') { + xdebug_str_chop(tmp_name, 2); + } + return tmp_name; +} + +/* + * Returns whether we should attempt to encode name, fullname, and value as XML + * elements instead of attribute values, because XML doesn't support nearly all + * characters under ASCII 0x32. + */ +static int encoding_requested(char *value, size_t value_len) +{ + size_t i; + + for (i = 0; i < value_len; i++) { + if (valuei < 0x20) { + return 1; + } + } + return 0; +} + +static void check_if_extended_properties_are_needed(xdebug_var_export_options *options, xdebug_str *name, xdebug_str *fullname, zval *value) +{ + if (!options->extended_properties || options->encode_as_extended_property) { + return; + } + + /* Checking name */ + if (name && encoding_requested(name->d, name->l)) { + options->encode_as_extended_property = 1; + return; + } + + /* Checking full name */ + if (fullname && encoding_requested(fullname->d, fullname->l)) { + options->encode_as_extended_property = 1; + return; + } + + /* Checking for the value portion */ + if (!value) { + return; + } + if (Z_TYPE_P(value) == IS_STRING) { + if (encoding_requested(Z_STRVAL_P(value), Z_STRLEN_P(value))) { + options->encode_as_extended_property = 1; + return; + } + } + if (Z_TYPE_P(value) == IS_OBJECT) { + if (encoding_requested(STR_NAME_VAL(Z_OBJCE_P(value)->name), STR_NAME_LEN(Z_OBJCE_P(value)->name))) { + options->encode_as_extended_property = 1; + return; + } + } +} + +static void add_xml_attribute_or_element(xdebug_var_export_options *options, xdebug_xml_node *node, const char *field, int field_len, xdebug_str *value) +{ + if (options->encode_as_extended_property || (encoding_requested(value->d, value->l) && options->extended_properties)) { + xdebug_xml_node *element; + unsigned char *tmp_base64; + size_t new_len; + + options->encode_as_extended_property = 1; + + element = xdebug_xml_node_init(field); + xdebug_xml_add_attribute(element, "encoding", "base64"); + + tmp_base64 = xdebug_base64_encode((unsigned char*) value->d, value->l, &new_len); + xdebug_xml_add_text_ex(element, (char*) tmp_base64, new_len, 1, 0); + + xdebug_xml_add_child(node, element); + } else { + xdebug_xml_add_attribute_exl(node, field, field_len, xdstrndup(value->d, value->l), value->l, 0, 1); + } +} + +void xdebug_var_xml_attach_uninitialized_var(xdebug_var_export_options *options, xdebug_xml_node *node, xdebug_str *name) +{ + xdebug_xml_node *contents = NULL; + xdebug_str *tmp_name; + + contents = xdebug_xml_node_init("property"); + options->encode_as_extended_property = 0; + + tmp_name = prepare_variable_name(name); + add_xml_attribute_or_element(options, contents, "name", 4, tmp_name); + add_xml_attribute_or_element(options, contents, "fullname", 8, tmp_name); + xdebug_str_free(tmp_name); + + xdebug_xml_add_attribute(contents, "type", "uninitialized"); + xdebug_xml_add_child(node, contents); +} + +/***************************************************************************** +** XML node printing routines +*/ + +#define XDEBUG_OBJECT_ITEM_TYPE_PROPERTY 0 +#define XDEBUG_OBJECT_ITEM_TYPE_STATIC_PROPERTY 1<<0 +#define XDEBUG_OBJECT_ITEM_TYPE_READONLY 1<<1 + + +typedef struct +{ + char type; + char *name; + int name_len; + unsigned long index_key; + zval *zv; +} xdebug_object_item; + +static void merged_hash_object_item_dtor(zval *data) +{ + xdebug_object_item *item = Z_PTR_P(data); + + xdfree(item); +} + +static int object_item_add_to_merged_hash(zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, HashTable *merged, int object_type) +{ + zval **zv = &zv_nptr; + xdebug_object_item *item; + + item = xdcalloc(1, sizeof(xdebug_object_item)); + item->type = object_type; + item->zv = *zv; + + if (hash_key) { + item->name = (char*) HASH_APPLY_KEY_VAL(hash_key); + item->name_len = HASH_APPLY_KEY_LEN(hash_key) - 1; + item->index_key = hash_key->h; + } else { + item->name = xdebug_sprintf(XDEBUG_INT_FMT, index_key); + item->name_len = strlen(item->name); + } + + zend_hash_next_index_insert_ptr(merged, item); + + return 0; +} + +static int object_item_add_zend_prop_to_merged_hash(zend_property_info *zpp, HashTable *merged, int object_type, zend_class_entry *ce) +{ + xdebug_object_item *item; + + if ((zpp->flags & ZEND_ACC_STATIC) == 0) { + return 0; + } + + item = xdmalloc(sizeof(xdebug_object_item)); + item->type = object_type; + item->zv = &CE_STATIC_MEMBERS(ce)zpp->offset; + item->name = (char*) STR_NAME_VAL(zpp->name); + item->name_len = STR_NAME_LEN(zpp->name); + + zend_hash_next_index_insert_ptr(merged, item); + + return 0; +} + +static void add_unencoded_text_value_attribute_or_element(xdebug_var_export_options *options, xdebug_xml_node *node, char *value) +{ + if (options->encode_as_extended_property) { + xdebug_xml_node *element; + unsigned char *tmp_base64; + size_t new_len; + + element = xdebug_xml_node_init("value"); + xdebug_xml_add_attribute(element, "encoding", "base64"); + + tmp_base64 = xdebug_base64_encode((unsigned char*) value, strlen(value), &new_len); + xdebug_xml_add_text_ex(element, (char*) tmp_base64, new_len, 1, 0); + + xdebug_xml_add_child(node, element); + } else { + xdebug_xml_add_text(node, value); + } +} + +static void add_encoded_text_value_attribute_or_element(xdebug_var_export_options *options, xdebug_xml_node *node, char *value, size_t value_len) +{ + if (options->encode_as_extended_property) { + xdebug_xml_node *element; + unsigned char *tmp_base64; + size_t new_len; + + element = xdebug_xml_node_init("value"); + xdebug_xml_add_attribute(element, "encoding", "base64"); + + tmp_base64 = xdebug_base64_encode((unsigned char*) value, value_len, &new_len); + xdebug_xml_add_text_ex(element, (char*) tmp_base64, new_len, 1, 0); + + xdebug_xml_add_child(node, element); + + xdfree(value); + } else { + xdebug_xml_add_text_encodel(node, value, value_len); + } +} + + +static int xdebug_array_element_export_xml_node(zval *zv_nptr, zend_ulong index_key, zend_string *hash_key, int level, xdebug_xml_node *parent, xdebug_str *parent_name, xdebug_var_export_options *options) +{ + zval **zv = &zv_nptr; + xdebug_xml_node *node; + xdebug_str *name; + xdebug_str full_name = XDEBUG_STR_INITIALIZER; + + if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && + options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) + { + node = xdebug_xml_node_init("property"); + options->encode_as_extended_property = 0; + + if (!HASH_KEY_IS_NUMERIC(hash_key)) { /* string key */ + zend_string *i_string = zend_string_init(HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key) - 1, 0); + zend_string *tmp_fullname_zstr; + + tmp_fullname_zstr = xdebug_addslashes(i_string); + + name = xdebug_str_create(HASH_APPLY_KEY_VAL(hash_key), HASH_APPLY_KEY_LEN(hash_key) - 1); + + if (parent_name) { + xdebug_str_add_str(&full_name, parent_name); + xdebug_str_add_literal(&full_name, "\""); + xdebug_str_addl(&full_name, tmp_fullname_zstr->val, tmp_fullname_zstr->len, 0); + xdebug_str_add_literal(&full_name, "\""); + } + + zend_string_release(tmp_fullname_zstr); + zend_string_release(i_string); + } else { + char *tmp_idx = xdebug_sprintf(XDEBUG_INT_FMT, index_key); + + name = xdebug_str_create(tmp_idx, strlen(tmp_idx)); + if (parent_name) { + xdebug_str_add_str(&full_name, parent_name); + xdebug_str_addc(&full_name, ''); + xdebug_str_add_str(&full_name, name); + xdebug_str_addc(&full_name, ''); + } + + xdfree(tmp_idx); + } + + check_if_extended_properties_are_needed(options, name, full_name.l ? &full_name : NULL, *zv); + add_xml_attribute_or_element(options, node, "name", 4, name); + if (full_name.l) { + add_xml_attribute_or_element(options, node, "fullname", 8, &full_name); + } + + xdebug_xml_add_child(parent, node); + xdebug_var_export_xml_node(zv, &full_name, node, options, level + 1); + + xdebug_str_destroy(&full_name); + xdebug_str_free(name); + } + options->runtimelevel.current_element_nr++; + return 0; +} + +static int xdebug_object_element_export_xml_node(xdebug_object_item *item_nptr, int level, xdebug_xml_node *parent, xdebug_str *parent_name, xdebug_var_export_options *options, char *class_name) +{ + xdebug_object_item **item = &item_nptr; + xdebug_xml_node *node; + + if (options->runtimelevel.current_element_nr >= options->runtimelevel.start_element_nr && + options->runtimelevel.current_element_nr < options->runtimelevel.end_element_nr) + { + const char *modifier; + xdebug_str *tmp_name = NULL; + xdebug_str *tmp_fullname = NULL; + + node = xdebug_xml_node_init("property"); + options->encode_as_extended_property = 0; + + if ((*item)->name != NULL) { + char *prop_class_name; + xdebug_str *property_name; + + property_name = xdebug_get_property_info((*item)->name, (*item)->name_len + 1, &modifier, &prop_class_name); + + if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) { + tmp_name = xdebug_str_copy(property_name); + } else { + tmp_name = xdebug_str_new(); + + xdebug_str_addc(tmp_name, '*'); + xdebug_str_add(tmp_name, prop_class_name, 0); + xdebug_str_addc(tmp_name, '*'); + xdebug_str_add_str(tmp_name, property_name); + } + + if (parent_name) { + tmp_fullname = xdebug_str_new(); + + xdebug_str_add_str(tmp_fullname, parent_name); + if ((*item)->type & XDEBUG_OBJECT_ITEM_TYPE_STATIC_PROPERTY) { + xdebug_str_add_literal(tmp_fullname, "::"); + } else { + xdebug_str_add_literal(tmp_fullname, "->"); + } + + /* Only in dynamic and *public* properties can we have non-standard characters */ + if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) { + if (property_name->l == 0) { + xdebug_str_add_literal(tmp_fullname, "{\"\"}"); + } else { + if (memchr(property_name->d, '-', property_name->l) == NULL && memchr(property_name->d, '', property_name->l) == NULL && memchr(property_name->d, '{', property_name->l) == NULL) { + xdebug_str_add_str(tmp_fullname, property_name); + } else { + zend_string *tmp_string = zend_string_init(property_name->d, property_name->l, 0); + zend_string *tmp_slashed_string; + + tmp_slashed_string = xdebug_addslashes(tmp_string); + + xdebug_str_add_literal(tmp_fullname, "{\""); + xdebug_str_add_zstr(tmp_fullname, tmp_slashed_string); + xdebug_str_add_literal(tmp_fullname, "\"}"); + + zend_string_release(tmp_slashed_string); + zend_string_release(tmp_string); + } + } + } else { + xdebug_str_addc(tmp_fullname, '*'); + xdebug_str_add(tmp_fullname, prop_class_name, 0); + xdebug_str_addc(tmp_fullname, '*'); + xdebug_str_add_str(tmp_fullname, property_name); + } + } + + xdebug_str_free(property_name); + xdfree(prop_class_name); + } else { /* Numerical property name */ + modifier = "public"; + + { + char *tmp_formatted_prop; + + tmp_formatted_prop = xdebug_sprintf(XDEBUG_INT_FMT, (*item)->index_key); + tmp_name = xdebug_str_create_from_char(tmp_formatted_prop); + + add_xml_attribute_or_element(options, node, "name", 4, tmp_name); + + xdfree(tmp_formatted_prop); + } + + if (parent_name) { + char *tmp_formatted_prop; + + tmp_formatted_prop = xdebug_sprintf("%s%s" XDEBUG_INT_FMT, parent_name, (*item)->type & XDEBUG_OBJECT_ITEM_TYPE_STATIC_PROPERTY ? "::" : "->", (*item)->index_key); + tmp_fullname = xdebug_str_create_from_char(tmp_formatted_prop); + + xdfree(tmp_formatted_prop); + } + } + + check_if_extended_properties_are_needed(options, tmp_name, tmp_fullname, (*item)->zv); + add_xml_attribute_or_element(options, node, "name", 4, tmp_name); + if (tmp_fullname) { + add_xml_attribute_or_element(options, node, "fullname", 8, tmp_fullname); + } + + + if ((*item)->type & XDEBUG_OBJECT_ITEM_TYPE_STATIC_PROPERTY) { + xdebug_xml_expand_attribute_value(node, "facet", "static"); + } + xdebug_xml_expand_attribute_value(node, "facet", modifier); + if ((*item)->type & XDEBUG_OBJECT_ITEM_TYPE_READONLY) { + xdebug_xml_expand_attribute_value(node, "facet", "readonly"); + } + + xdebug_xml_add_child(parent, node); + xdebug_var_export_xml_node(&((*item)->zv), tmp_fullname ? tmp_fullname : NULL, node, options, level + 1); + + if (tmp_name) { + xdebug_str_free(tmp_name); + } + if (tmp_fullname) { + xdebug_str_free(tmp_fullname); + } + } + options->runtimelevel.current_element_nr++; + return 0; +} + +static void xdebug_var_xml_attach_property_with_contents(zend_property_info *prop_info, xdebug_xml_node *node, xdebug_var_export_options *options, zend_class_entry *class_entry, char *class_name, int *children_count) +{ + const char *modifier; + xdebug_xml_node *contents = NULL; + char *prop_class_name; + xdebug_str *property_name; + + if ((prop_info->flags & ZEND_ACC_STATIC) == 0) { + return; + } + + (*children_count)++; + property_name = xdebug_get_property_info(STR_NAME_VAL(prop_info->name), STR_NAME_LEN(prop_info->name) + 1, &modifier, &prop_class_name); + + if (strcmp(modifier, "private") != 0 || strcmp(class_name, prop_class_name) == 0) { + contents = xdebug_get_zval_value_xml_node_ex(property_name, &CE_STATIC_MEMBERS(class_entry)prop_info->offset, XDEBUG_VAR_TYPE_STATIC, options); + } else{ + xdebug_str *priv_name = xdebug_str_new(); + + xdebug_str_addc(priv_name, '*'); + xdebug_str_add(priv_name, prop_class_name, 0); + xdebug_str_addc(priv_name, '*'); + xdebug_str_add_str(priv_name, property_name); + + contents = xdebug_get_zval_value_xml_node_ex(priv_name, &CE_STATIC_MEMBERS(class_entry)prop_info->offset, XDEBUG_VAR_TYPE_STATIC, options); + + xdebug_str_free(priv_name); + } + + xdebug_str_free(property_name); + xdfree(prop_class_name); + + if (contents) { + xdebug_xml_expand_attribute_value(contents, "facet", "static"); + xdebug_xml_expand_attribute_value(contents, "facet", modifier); + xdebug_xml_add_child(node, contents); + } else { + xdebug_var_xml_attach_uninitialized_var(options, node, xdebug_str_create(ZSTR_VAL(prop_info->name), ZSTR_LEN(prop_info->name))); + } +} + +void xdebug_var_xml_attach_static_vars(xdebug_xml_node *node, xdebug_var_export_options *options, zend_class_entry *ce) +{ + HashTable *static_members = &ce->properties_info; + int children = 0; + xdebug_xml_node *static_container; + zend_property_info *zpi; + + static_container = xdebug_xml_node_init("property"); + options->encode_as_extended_property = 0; + + xdebug_xml_add_attribute(static_container, "name", "::"); + xdebug_xml_add_attribute(static_container, "fullname", "::"); + xdebug_xml_add_attribute(static_container, "type", "object"); + xdebug_xml_add_attribute_ex(static_container, "classname", xdstrdup(STR_NAME_VAL(ce->name)), 0, 1); + + xdebug_zend_hash_apply_protection_begin(static_members); + +#if PHP_VERSION_ID >= 80100 + if (ce->default_static_members_count && !CE_STATIC_MEMBERS(ce)) { + zend_class_init_statics(ce); + } +#endif + + ZEND_HASH_FOREACH_PTR(static_members, zpi) { + xdebug_var_xml_attach_property_with_contents(zpi, static_container, options, ce, STR_NAME_VAL(ce->name), &children); + } ZEND_HASH_FOREACH_END(); + + xdebug_zend_hash_apply_protection_end(static_members); + + xdebug_xml_add_attribute(static_container, "children", children > 0 ? "1" : "0"); + xdebug_xml_add_attribute_ex(static_container, "numchildren", xdebug_sprintf("%d", children), 0, 1); + + xdebug_xml_add_child(node, static_container); +} + +void xdebug_var_export_xml_node(zval **struc, xdebug_str *name, xdebug_xml_node *node, xdebug_var_export_options *options, int level) +{ + HashTable *myht; + zend_ulong num; + zend_string *key; + zval *z_val; + xdebug_object_item *xoi_val; + zval *tmpz; + + if (!*struc) { + xdebug_xml_add_attribute(node, "type", "uninitialized"); + return; + } + + if (Z_TYPE_P(*struc) == IS_INDIRECT) { + tmpz = ((*struc)->value.zv); + struc = &tmpz; + } + if (Z_TYPE_P(*struc) == IS_REFERENCE) { + tmpz = &((*struc)->value.ref->val); + struc = &tmpz; + } + + switch (Z_TYPE_P(*struc)) { + case IS_TRUE: + case IS_FALSE: + xdebug_xml_add_attribute(node, "type", "bool"); + add_unencoded_text_value_attribute_or_element(options, node, xdebug_sprintf("%d", Z_TYPE_P(*struc) == IS_TRUE ? 1 : 0)); + break; + + case IS_NULL: + xdebug_xml_add_attribute(node, "type", "null"); + break; + + case IS_LONG: + xdebug_xml_add_attribute(node, "type", "int"); + add_unencoded_text_value_attribute_or_element(options, node, xdebug_sprintf(XDEBUG_INT_FMT, Z_LVAL_P(*struc))); + break; + + case IS_DOUBLE: + xdebug_xml_add_attribute(node, "type", "float"); + add_unencoded_text_value_attribute_or_element(options, node, xdebug_sprintf("%.*H", (int) EG(precision), Z_DVAL_P(*struc))); + break; + + case IS_STRING: + xdebug_xml_add_attribute(node, "type", "string"); + if (options->max_data == 0 || (size_t) Z_STRLEN_P(*struc) <= (size_t) options->max_data) { + add_encoded_text_value_attribute_or_element(options, node, xdstrndup(Z_STRVAL_P(*struc), Z_STRLEN_P(*struc)), Z_STRLEN_P(*struc)); + } else { + add_encoded_text_value_attribute_or_element(options, node, xdstrndup(Z_STRVAL_P(*struc), options->max_data), options->max_data); + } + xdebug_xml_add_attribute_ex(node, "size", xdebug_sprintf("%d", Z_STRLEN_P(*struc)), 0, 1); + break; + + case IS_ARRAY: + myht = Z_ARRVAL_P(*struc); + xdebug_xml_add_attribute(node, "type", "array"); + xdebug_xml_add_attribute(node, "children", myht->nNumOfElements > 0?"1":"0"); + + if (!xdebug_zend_hash_is_recursive(myht)) { + xdebug_xml_add_attribute_ex(node, "numchildren", xdebug_sprintf("%d", myht->nNumOfElements), 0, 1); + if (level < options->max_depth) { + xdebug_xml_add_attribute_ex(node, "page", xdebug_sprintf("%d", options->runtimelevel.page), 0, 1); + xdebug_xml_add_attribute_ex(node, "pagesize", xdebug_sprintf("%d", options->max_children), 0, 1); + options->runtimelevel.current_element_nr = 0; + if (level == 0) { + options->runtimelevel.start_element_nr = options->max_children * options->runtimelevel.page; + options->runtimelevel.end_element_nr = options->max_children * (options->runtimelevel.page + 1); + } else { + options->runtimelevel.start_element_nr = 0; + options->runtimelevel.end_element_nr = options->max_children; + } + + xdebug_zend_hash_apply_protection_begin(myht); + + ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, z_val) { + xdebug_array_element_export_xml_node(z_val, num, key, level, node, name, options); + } ZEND_HASH_FOREACH_END(); + + xdebug_zend_hash_apply_protection_end(myht); + } + } else { + xdebug_xml_add_attribute(node, "recursive", "1"); + } + break; + + case IS_OBJECT: { + HashTable *merged_hash; + zend_string *class_name; + zend_class_entry *ce; + int extra_children = 0; + zend_property_info *zpi_val; + + ALLOC_HASHTABLE(merged_hash); + zend_hash_init(merged_hash, 128, NULL, merged_hash_object_item_dtor, 0); + + class_name = Z_OBJCE_P(*struc)->name; + ce = zend_fetch_class(class_name, ZEND_FETCH_CLASS_DEFAULT); + + /* Adding static properties */ + xdebug_zend_hash_apply_protection_begin(&ce->properties_info); + +#if PHP_VERSION_ID >= 80100 + zend_class_init_statics(ce); +#else + if (ce->type == ZEND_INTERNAL_CLASS || (ce->ce_flags & ZEND_ACC_IMMUTABLE)) { + zend_class_init_statics(ce); + } +#endif + + ZEND_HASH_FOREACH_PTR(&ce->properties_info, zpi_val) { + object_item_add_zend_prop_to_merged_hash(zpi_val, merged_hash, (int) XDEBUG_OBJECT_ITEM_TYPE_STATIC_PROPERTY, ce); + } ZEND_HASH_FOREACH_END(); + + xdebug_zend_hash_apply_protection_end(&ce->properties_info); + + /* Adding normal properties */ + myht = xdebug_objdebug_pp(struc, XDEBUG_VAR_OBJDEBUG_DEFAULT); + + if (myht) { + zval *tmp_val; + + xdebug_zend_hash_apply_protection_begin(myht); + + ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, tmp_val) { + int flags = XDEBUG_OBJECT_ITEM_TYPE_PROPERTY; + +#if PHP_VERSION_ID >= 80100 + if (ce->type != ZEND_INTERNAL_CLASS) { + const char *cls_name, *tmp_prop_name; + size_t tmp_prop_name_len; + zend_string *unmangled; + zend_property_info *info; + + zend_unmangle_property_name_ex(key, &cls_name, &tmp_prop_name, &tmp_prop_name_len); + unmangled = zend_string_init_interned(tmp_prop_name, tmp_prop_name_len, 0); + + info = zend_get_property_info(Z_OBJCE_P(*struc), unmangled, 1); + + zend_string_release(unmangled); + + if (info && info != ZEND_WRONG_PROPERTY_INFO && info->flags & ZEND_ACC_READONLY) { + flags |= XDEBUG_OBJECT_ITEM_TYPE_READONLY; + } + } +#endif + object_item_add_to_merged_hash(tmp_val, num, key, merged_hash, flags); + } ZEND_HASH_FOREACH_END(); + + xdebug_zend_hash_apply_protection_end(myht); + } + + xdebug_xml_add_attribute(node, "type", "object"); + +#if PHP_VERSION_ID >= 80100 // Enums + { + zend_class_entry *ce = Z_OBJCE_P(*struc); + if (ce->ce_flags & ZEND_ACC_ENUM) { + xdebug_xml_expand_attribute_value(node, "facet", "enum"); + } + } +#endif + + if (instanceof_function(Z_OBJCE_P(*struc), zend_ce_closure)) { +#if PHP_VERSION_ID < 80200 + xdebug_xml_node *closure_cont, *closure_func; + const zend_function *closure_function = zend_get_closure_method_def(Z_OBJ_P(*struc)); + + closure_cont = xdebug_xml_node_init("property"); + xdebug_xml_add_attribute(closure_cont, "facet", "virtual readonly"); + xdebug_xml_add_attribute(closure_cont, "name", "{closure}"); + xdebug_xml_add_attribute(closure_cont, "type", "array"); + xdebug_xml_add_attribute(closure_cont, "children", "1"); + xdebug_xml_add_attribute(closure_cont, "page", "0"); + xdebug_xml_add_attribute(closure_cont, "pagesize", "2"); + + if (closure_function->common.scope) { + xdebug_xml_node *closure_scope = xdebug_xml_node_init("property"); + xdebug_xml_add_attribute(closure_scope, "facet", "readonly"); + xdebug_xml_add_attribute(closure_scope, "name", "scope"); + xdebug_xml_add_attribute(closure_scope, "type", "string"); + + if (closure_function->common.fn_flags & ZEND_ACC_STATIC) { + xdebug_xml_add_text_ex( + closure_scope, + ZSTR_VAL(closure_function->common.scope->name), + ZSTR_LEN(closure_function->common.scope->name), + 0, 0 + ); + } else { + xdebug_xml_add_text_ex(closure_scope, (char*) "$this", 6, 0, 0); + } + + xdebug_xml_add_child(closure_cont, closure_scope); + xdebug_xml_add_attribute(closure_cont, "numchildren", "2"); + } else { + xdebug_xml_add_attribute(closure_cont, "numchildren", "1"); + } + + closure_func = xdebug_xml_node_init("property"); + xdebug_xml_add_attribute(closure_func, "facet", "readonly"); + xdebug_xml_add_attribute(closure_func, "name", "function"); + xdebug_xml_add_attribute(closure_func, "type", "string"); + xdebug_xml_add_text_ex( + closure_func, + ZSTR_VAL(closure_function->common.function_name), + ZSTR_LEN(closure_function->common.function_name), + 0, 0 + ); + xdebug_xml_add_child(closure_cont, closure_func); + + xdebug_xml_add_child(node, closure_cont); + extra_children = 1; +#endif + + xdebug_xml_expand_attribute_value(node, "facet", "closure"); + } + + { + xdebug_str tmp_str; + tmp_str.d = ZSTR_VAL(class_name); + tmp_str.l = ZSTR_LEN(class_name); + add_xml_attribute_or_element(options, node, "classname", 9, &tmp_str); + } + xdebug_xml_add_attribute(node, "children", (merged_hash->nNumOfElements || extra_children) ? "1" : "0"); + + + if (!myht || !xdebug_zend_hash_is_recursive(myht)) { + xdebug_xml_add_attribute_ex( + node, "numchildren", + xdebug_sprintf("%d", zend_hash_num_elements(merged_hash) + extra_children), + 0, 1 + ); + if (level < options->max_depth) { + xdebug_xml_add_attribute_ex(node, "page", xdebug_sprintf("%d", options->runtimelevel.page), 0, 1); + xdebug_xml_add_attribute_ex(node, "pagesize", xdebug_sprintf("%d", options->max_children), 0, 1); + options->runtimelevel.current_element_nr = 0; + if (level == 0) { + options->runtimelevel.start_element_nr = options->max_children * options->runtimelevel.page; + options->runtimelevel.end_element_nr = options->max_children * (options->runtimelevel.page + 1); + } else { + options->runtimelevel.start_element_nr = 0; + options->runtimelevel.end_element_nr = options->max_children; + } + + xdebug_zend_hash_apply_protection_begin(merged_hash); + + ZEND_HASH_FOREACH_KEY_PTR(merged_hash, num, key, xoi_val) { + xdebug_object_element_export_xml_node(xoi_val, level, node, name, options, ZSTR_VAL(class_name)); + } ZEND_HASH_FOREACH_END(); + + xdebug_zend_hash_apply_protection_end(merged_hash); + } + } + + zend_hash_destroy(merged_hash); + FREE_HASHTABLE(merged_hash); + zend_release_properties(myht); + + break; + } + + case IS_RESOURCE: { + char *type_name; + + xdebug_xml_add_attribute(node, "type", "resource"); + type_name = (char *) zend_rsrc_list_get_rsrc_type(Z_RES_P(*struc)); + xdebug_xml_add_text(node, xdebug_sprintf("resource id='%ld' type='%s'", Z_RES_P(*struc)->handle, type_name ? type_name : "Unknown")); + break; + } + + case IS_UNDEF: + xdebug_xml_add_attribute(node, "type", "uninitialized"); + break; + + default: + xdebug_xml_add_attribute(node, "type", "null"); + break; + } +} + +xdebug_xml_node* xdebug_get_zval_value_xml_node_ex(xdebug_str *name, zval *val, int var_type, xdebug_var_export_options *options) +{ + xdebug_xml_node *node; + xdebug_str *short_name = NULL; + xdebug_str *full_name = NULL; + + node = xdebug_xml_node_init("property"); + options->encode_as_extended_property = 0; + + if (name) { + switch (var_type) { + case XDEBUG_VAR_TYPE_NORMAL: { + short_name = prepare_variable_name(name); + full_name = xdebug_str_copy(short_name); + } break; + + case XDEBUG_VAR_TYPE_STATIC: { + xdebug_str tmp_formatted_name = XDEBUG_STR_INITIALIZER; + + xdebug_str_add_literal(&tmp_formatted_name, "::"); + xdebug_str_add_str(&tmp_formatted_name, name); + + short_name = xdebug_str_copy(&tmp_formatted_name); + full_name = xdebug_str_copy(&tmp_formatted_name); + + xdebug_str_destroy(&tmp_formatted_name); + } break; + + case XDEBUG_VAR_TYPE_CONSTANT: + short_name = xdebug_str_copy(name); + full_name = xdebug_str_copy(name); + break; + } + + check_if_extended_properties_are_needed(options, short_name, full_name, val); + add_xml_attribute_or_element(options, node, "name", 4, short_name); + add_xml_attribute_or_element(options, node, "fullname", 8, full_name); + } + xdebug_var_export_xml_node(&val, full_name ? full_name : NULL, node, options, 0); + + if (short_name) { + xdebug_str_free(short_name); + } + if (full_name) { + xdebug_str_free(full_name); + } + + return node; +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/var_export_xml.h
Changed
(renamed from xdebug-3.1.5/src/lib/var_export_xml.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/vector.h
Changed
(renamed from xdebug-3.1.5/src/lib/vector.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/xml.c
Changed
(renamed from xdebug-3.1.5/src/lib/xml.c)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/lib/xml.h
Changed
(renamed from xdebug-3.1.5/src/lib/xml.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/profiler/profiler.c
Added
@@ -0,0 +1,554 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifdef PHP_WIN32 +#include <process.h> +#endif + +#include "lib/php-header.h" +#include "TSRM.h" +#include "php_globals.h" +#include "Zend/zend_alloc.h" + +#include "php_xdebug.h" +#include "profiler.h" +#include "profiler_private.h" + +#include "lib/log.h" +#include "lib/mm.h" +#include "lib/str.h" +#include "lib/var.h" +#include "lib/usefulstuff.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +int xdebug_profiler_exit_handler(XDEBUG_OPCODE_HANDLER_ARGS); + +void xdebug_init_profiler_globals(xdebug_profiler_globals_t *xg) +{ + xg->active = 0; +} + +void xdebug_profiler_minit(void) +{ + /* Overload the "exit" opcode */ + xdebug_set_opcode_handler(ZEND_EXIT, xdebug_profiler_exit_handler); +} + +void xdebug_profiler_mshutdown(void) +{ +} + +void xdebug_profiler_rinit(void) +{ + xdebug_file_init(&XG_PROF(profile_file)); + XG_PROF(profile_filename_refs) = NULL; + XG_PROF(profile_functionname_refs) = NULL; + XG_PROF(profile_last_filename_ref) = 0; + XG_PROF(php_internal_seen_before) = 0; + XG_PROF(profile_last_functionname_ref) = 0; + XG_PROF(active) = 0; +} + +static void deinit_if_active(void) +{ + if (!XG_PROF(active)) { + return; + } + + xdebug_profiler_deinit(); +} + +void xdebug_profiler_post_deactivate(void) +{ + deinit_if_active(); +} + +void xdebug_profiler_pcntl_exec_handler(void) +{ + deinit_if_active(); +} + +int xdebug_profiler_exit_handler(XDEBUG_OPCODE_HANDLER_ARGS) +{ + const zend_op *cur_opcode = execute_data->opline; + + deinit_if_active(); + + return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); +} + + +void xdebug_profiler_init_if_requested(zend_op_array *op_array) +{ + if (XG_PROF(active)) { + return; + } + + if (EG(flags) & EG_FLAGS_IN_SHUTDOWN) { + return; + } + + if (xdebug_lib_start_with_request(XDEBUG_MODE_PROFILING) || xdebug_lib_start_with_trigger(XDEBUG_MODE_PROFILING, NULL)) { + xdebug_profiler_init((char*) STR_NAME_VAL(op_array->filename)); + } +} + +void xdebug_profiler_execute_ex(function_stack_entry *fse, zend_op_array *op_array) +{ + if (!XG_PROF(active)) { + return; + } + + /* Calculate all elements for profile entries */ + xdebug_profiler_add_function_details_user(fse, op_array); + xdebug_profiler_function_begin(fse); +} + +void xdebug_profiler_execute_ex_end(function_stack_entry *fse) +{ + xdebug_profiler_function_end(fse); + xdebug_profiler_free_function_details(fse); +} + +void xdebug_profiler_execute_internal(function_stack_entry *fse) +{ + if (!XG_PROF(active)) { + return; + } + + xdebug_profiler_add_function_details_internal(fse); + xdebug_profiler_function_begin(fse); +} + +void xdebug_profiler_execute_internal_end(function_stack_entry *fse) +{ + if (!XG_PROF(active)) { + return; + } + + xdebug_profiler_function_end(fse); + xdebug_profiler_free_function_details(fse); +} + +void xdebug_profile_call_entry_dtor(void *dummy, void *elem) +{ + xdebug_call_entry *ce = elem; + + if (ce->function) { + xdfree(ce->function); + } + if (ce->filename) { + zend_string_release(ce->filename); + } + xdfree(ce); +} + +static void profiler_write_header(xdebug_file *file, char *script_name) +{ + if (XINI_PROF(profiler_append)) { + xdebug_file_printf(file, "\n==== NEW PROFILING FILE ==============================================\n"); + } + xdebug_file_printf(file, "version: 1\ncreator: xdebug %s (PHP %s)\n", XDEBUG_VERSION, XG_BASE(php_version_run_time)); + xdebug_file_printf(file, "cmd: %s\npart: 1\npositions: line\n\n", script_name); + xdebug_file_printf(file, "events: Time_(10ns) Memory_(bytes)\n\n"); + xdebug_file_flush(file); +} + +#define NANOTIME_SCALE_10NS(nanotime) ((unsigned long)(((nanotime) + 5) / 10)) + +void xdebug_profiler_init(char *script_name) +{ + char *filename = NULL, *fname = NULL; + char *output_dir = NULL; + + if (XG_PROF(active)) { + return; + } + + if (!strlen(XINI_PROF(profiler_output_name)) || + xdebug_format_output_filename(&fname, XINI_PROF(profiler_output_name), script_name) <= 0 + ) { + /* Invalid or empty xdebug.profiler_output_name */ + return; + } + + /* Add a slash if none is present in the output_dir setting */ + output_dir = xdebug_lib_get_output_dir(); /* not duplicated */ + + if (IS_SLASH(output_dirstrlen(output_dir) - 1)) { + filename = xdebug_sprintf("%s%s", output_dir, fname); + } else { + filename = xdebug_sprintf("%s%c%s", output_dir, DEFAULT_SLASH, fname); + } + + if (!xdebug_file_open(&XG_PROF(profile_file), filename, NULL, XINI_PROF(profiler_append) ? "ab" : "wb")) { + xdebug_log_diagnose_permissions(XLOG_CHAN_PROFILE, output_dir, fname); + goto return_and_free_names; + } + + profiler_write_header(&XG_PROF(profile_file), script_name); + + if (!SG(headers_sent)) { + sapi_header_line ctr = {0}; + + ctr.line = xdebug_sprintf("X-Xdebug-Profile-Filename: %s", XG_PROF(profile_file).name); + ctr.line_len = strlen(ctr.line); + sapi_header_op(SAPI_HEADER_REPLACE, &ctr); + xdfree((void*) ctr.line); + } + + XG_PROF(profiler_start_nanotime) = xdebug_get_nanotime(); + + XG_PROF(active) = 1; + XG_PROF(profile_filename_refs) = xdebug_hash_alloc(128, xdfree); + XG_PROF(profile_functionname_refs) = xdebug_hash_alloc(128, xdfree); + XG_PROF(profile_last_filename_ref) = 1; + XG_PROF(profile_last_functionname_ref) = 0; + +return_and_free_names: + xdfree(filename); + xdfree(fname); +} + +void xdebug_profiler_deinit() +{ + function_stack_entry *fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + int i; + + for (i = 0; i < XDEBUG_VECTOR_COUNT(XG_BASE(stack)); i++, fse--) { + xdebug_profiler_function_end(fse); + } + + xdebug_file_printf( + &XG_PROF(profile_file), + "summary: %lu %zd\n\n", + NANOTIME_SCALE_10NS(xdebug_get_nanotime() - XG_PROF(profiler_start_nanotime)), + zend_memory_peak_usage(0) + ); + + XG_PROF(active) = 0; + + xdebug_file_flush(&XG_PROF(profile_file)); + + if (XG_PROF(profile_file).type != XDEBUG_FILE_TYPE_NULL) { + xdebug_file_close(&XG_PROF(profile_file)); + xdebug_file_deinit(&XG_PROF(profile_file)); + } + + xdebug_hash_destroy(XG_PROF(profile_filename_refs)); + xdebug_hash_destroy(XG_PROF(profile_functionname_refs)); + XG_PROF(profile_filename_refs) = NULL; + XG_PROF(profile_functionname_refs) = NULL; +} + +static inline void xdebug_profiler_function_push(function_stack_entry *fse) +{ + fse->profile.nanotime += (xdebug_get_nanotime() - fse->profile.nanotime_mark); + fse->profile.nanotime_mark = 0; + fse->profile.memory += (zend_memory_usage(0) - fse->profile.mem_mark); + fse->profile.mem_mark = 0; +} + +void xdebug_profiler_function_continue(function_stack_entry *fse) +{ + fse->profile.nanotime_mark = xdebug_get_nanotime(); +} + +void xdebug_profiler_function_pause(function_stack_entry *fse) +{ + xdebug_profiler_function_push(fse); +} + +static inline void add_filename_ref(xdebug_str *buffer, char *name) +{ + char *ref; + + if (xdebug_hash_find(XG_PROF(profile_filename_refs), name, strlen(name), (void*) &ref)) { + xdebug_str_add(buffer, ref, 0); + } else { + XG_PROF(profile_last_filename_ref)++; + ref = xdebug_sprintf("(%d)", XG_PROF(profile_last_filename_ref)); + + xdebug_hash_add(XG_PROF(profile_filename_refs), name, strlen(name), (void*) ref); + + xdebug_str_add(buffer, ref, 0); + xdebug_str_addc(buffer, ' '); + xdebug_str_add(buffer, name, 0); + } +} + +static inline void add_functionname_ref(xdebug_str *buffer, char *name) +{ + char *ref; + + if (xdebug_hash_find(XG_PROF(profile_functionname_refs), name, strlen(name), (void*) &ref)) { + xdebug_str_add(buffer, ref, 0); + } else { + XG_PROF(profile_last_functionname_ref)++; + ref = xdebug_sprintf("(%d)", XG_PROF(profile_last_functionname_ref)); + + xdebug_hash_add(XG_PROF(profile_functionname_refs), name, strlen(name), (void*) ref); + + xdebug_str_add(buffer, ref, 0); + xdebug_str_addc(buffer, ' '); + xdebug_str_add(buffer, name, 0); + } +} + +void xdebug_profiler_add_function_details_user(function_stack_entry *fse, zend_op_array *op_array) +{ + char *tmp_fname, *tmp_name; + + tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); + switch (fse->function.type) { + case XFUNC_INCLUDE: + case XFUNC_INCLUDE_ONCE: + case XFUNC_REQUIRE: + case XFUNC_REQUIRE_ONCE: + tmp_fname = xdebug_sprintf("%s::%s", tmp_name, ZSTR_VAL(fse->include_filename)); + xdfree(tmp_name); + tmp_name = tmp_fname; + fse->profiler.lineno = 1; + break; + + default: + if (op_array/* && op_array->function_name*/) { + fse->profiler.lineno = fse->op_array->line_start; + } else { + fse->profiler.lineno = fse->lineno; + } + break; + } + if (fse->profiler.lineno == 0) { + fse->profiler.lineno = 1; + } + + if (op_array && op_array->filename) { + fse->profiler.filename = zend_string_copy(op_array->filename); + } else { + fse->profiler.filename = zend_string_copy(fse->filename); + } + fse->profiler.funcname = xdstrdup(tmp_name); + xdfree(tmp_name); +} + +void xdebug_profiler_add_function_details_internal(function_stack_entry *fse) +{ + char *tmp_fname, *tmp_name; + + tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); + switch (fse->function.type) { + case XFUNC_INCLUDE: + case XFUNC_INCLUDE_ONCE: + case XFUNC_REQUIRE: + case XFUNC_REQUIRE_ONCE: + tmp_fname = xdebug_sprintf("%s::%s", tmp_name, fse->include_filename); + xdfree(tmp_name); + tmp_name = tmp_fname; + fse->profiler.lineno = 1; + break; + + default: + fse->profiler.lineno = fse->lineno; + break; + } + if (fse->profiler.lineno == 0) { + fse->profiler.lineno = 1; + } + + fse->profiler.filename = zend_string_copy(fse->filename); + fse->profiler.funcname = xdstrdup(tmp_name); + + xdfree(tmp_name); +} + +void xdebug_profiler_function_begin(function_stack_entry *fse) +{ + fse->profile.nanotime = 0; + fse->profile.nanotime_mark = xdebug_get_nanotime(); + fse->profile.memory = 0; + fse->profile.mem_mark = zend_memory_usage(0); +} + +#define TMP_KEY_BUFFER_LEN 1024 +#define TMP_KEY_PREFIX "php::" +#define TMP_KEY_PREFIX_LEN (sizeof(TMP_KEY_PREFIX)-1) +#define TMP_KEY_MAX_LEN (TMP_KEY_BUFFER_LEN-TMP_KEY_PREFIX_LEN-1) + +void xdebug_profiler_function_end(function_stack_entry *fse) +{ + xdebug_llist_element *le; + xdebug_str file_buffer = XDEBUG_STR_INITIALIZER; + char tmp_keyTMP_KEY_BUFFER_LEN; + + if (!XG_PROF(active)) { + return; + } + + /* The temporary key always starts with 'php::' */ + memcpy(tmp_key, TMP_KEY_PREFIX, TMP_KEY_PREFIX_LEN); + + if (xdebug_vector_element_is_valid(XG_BASE(stack), fse - 1) && !(fse - 1)->profile.call_list) { + (fse - 1)->profile.call_list = xdebug_llist_alloc(xdebug_profile_call_entry_dtor); + } + if (!fse->profile.call_list) { + fse->profile.call_list = xdebug_llist_alloc(xdebug_profile_call_entry_dtor); + } + xdebug_profiler_function_push(fse); + + if (xdebug_vector_element_is_valid(XG_BASE(stack), fse - 1)) { + xdebug_call_entry *ce = xdmalloc(sizeof(xdebug_call_entry)); + + ce->filename = zend_string_copy(fse->profiler.filename); + ce->function = xdstrdup(fse->profiler.funcname); + ce->nanotime_taken = fse->profile.nanotime; + ce->lineno = fse->lineno; + ce->user_defined = fse->user_defined; + ce->mem_used = fse->profile.memory; + + xdebug_llist_insert_next((fse - 1)->profile.call_list, NULL, ce); + } + + /* use previously created filename and funcname (or a reference to them) to show + * time spend */ + if (fse->user_defined == XDEBUG_BUILT_IN) { + size_t tmp_key_funcname_len = strlen(fse->profiler.funcname); + + memcpy(tmp_key + TMP_KEY_PREFIX_LEN, + fse->profiler.funcname, + tmp_key_funcname_len > TMP_KEY_MAX_LEN ? TMP_KEY_MAX_LEN : tmp_key_funcname_len + 1 + ); + tmp_keyTMP_KEY_BUFFER_LEN - 1 = '\0'; + + if (XG_PROF(php_internal_seen_before)) { + xdebug_str_add_literal(&file_buffer, "fl=(1)\n"); + } else { + xdebug_str_add_literal(&file_buffer, "fl=(1) php:internal\n"); + XG_PROF(php_internal_seen_before) = 1; + } + xdebug_str_add_literal(&file_buffer, "fn="); + add_functionname_ref(&file_buffer, tmp_key); + xdebug_str_addc(&file_buffer, '\n'); + } else { + + xdebug_str_add_literal(&file_buffer, "fl="); + add_filename_ref(&file_buffer, ZSTR_VAL(fse->profiler.filename)); + + xdebug_str_add_literal(&file_buffer, "\nfn="); + add_functionname_ref(&file_buffer, fse->profiler.funcname); + xdebug_str_addc(&file_buffer, '\n'); + } + + + /* Subtract time in calledfunction from time here */ + for (le = XDEBUG_LLIST_HEAD(fse->profile.call_list); le != NULL; le = XDEBUG_LLIST_NEXT(le)) + { + xdebug_call_entry *call_entry = XDEBUG_LLIST_VALP(le); + fse->profile.nanotime -= call_entry->nanotime_taken; + fse->profile.memory -= call_entry->mem_used; + } + + /* Adds %d %lu %lu, with lineno, time, and memory */ + xdebug_str_add_uint64(&file_buffer, fse->profiler.lineno); + xdebug_str_addc(&file_buffer, ' '); + xdebug_str_add_uint64(&file_buffer, NANOTIME_SCALE_10NS(fse->profile.nanotime)); + xdebug_str_addc(&file_buffer, ' '); + xdebug_str_add_uint64(&file_buffer, fse->profile.memory >= 0 ? fse->profile.memory : 0); + xdebug_str_addc(&file_buffer, '\n'); + + /* dump call list */ + for (le = XDEBUG_LLIST_HEAD(fse->profile.call_list); le != NULL; le = XDEBUG_LLIST_NEXT(le)) + { + xdebug_call_entry *call_entry = XDEBUG_LLIST_VALP(le); + + if (call_entry->user_defined == XDEBUG_BUILT_IN) { + size_t tmp_key_funcname_len = strlen(call_entry->function); + + memcpy(tmp_key + TMP_KEY_PREFIX_LEN, + call_entry->function, + tmp_key_funcname_len > TMP_KEY_MAX_LEN ? TMP_KEY_MAX_LEN : tmp_key_funcname_len + 1 + ); + tmp_keyTMP_KEY_BUFFER_LEN - 1 = '\0'; + + if (XG_PROF(php_internal_seen_before)) { + xdebug_str_add_literal(&file_buffer, "cfl=(1)\n"); + } else { + xdebug_str_add_literal(&file_buffer, "cfl=(1) php:internal\n"); + XG_PROF(php_internal_seen_before) = 1; + } + + xdebug_str_add_literal(&file_buffer, "cfn="); + add_functionname_ref(&file_buffer, tmp_key); + xdebug_str_addc(&file_buffer, '\n'); + } else { + xdebug_str_add_literal(&file_buffer, "cfl="); + add_filename_ref(&file_buffer, ZSTR_VAL(call_entry->filename)); + + xdebug_str_add_literal(&file_buffer, "\ncfn="); + add_functionname_ref(&file_buffer, call_entry->function); + xdebug_str_addc(&file_buffer, '\n'); + } + + xdebug_str_add_literal(&file_buffer, "calls=1 0 0\n"); + + /* Adds %d %lu %lu, with lineno, time, and memory */ + xdebug_str_add_uint64(&file_buffer, call_entry->lineno); + xdebug_str_addc(&file_buffer, ' '); + xdebug_str_add_uint64(&file_buffer, NANOTIME_SCALE_10NS(call_entry->nanotime_taken)); + xdebug_str_addc(&file_buffer, ' '); + xdebug_str_add_uint64(&file_buffer, call_entry->mem_used >= 0 ? call_entry->mem_used : 0); + xdebug_str_addc(&file_buffer, '\n'); + } + xdebug_str_addc(&file_buffer, '\n'); + + xdebug_file_write(file_buffer.d, sizeof(char), file_buffer.l, &XG_PROF(profile_file)); + xdebug_str_dtor(file_buffer); +} + +void xdebug_profiler_free_function_details(function_stack_entry *fse) +{ + if (fse->profiler.funcname) { + xdfree(fse->profiler.funcname); + fse->profiler.funcname = NULL; + } + if (fse->profiler.filename) { + zend_string_release(fse->profiler.filename); + fse->profiler.filename = NULL; + } +} + +/* Returns a *pointer* to the current profile filename, if active. NULL + * otherwise. Calling function is responsible for duplicating immediately */ +char *xdebug_get_profiler_filename() +{ + if (!XG_PROF(active)) { + return NULL; + } + + return XG_PROF(profile_file).name; +} + +PHP_FUNCTION(xdebug_get_profiler_filename) +{ + char *filename = xdebug_get_profiler_filename(); + + if (!filename) { + RETURN_FALSE; + } + + RETURN_STRING(filename); +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/profiler/profiler.h
Added
@@ -0,0 +1,72 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifndef __XDEBUG_PROFILER_H__ +#define __XDEBUG_PROFILER_H__ + +#include "lib/php-header.h" +#include "TSRM.h" +#include "lib/file.h" +#include "lib/lib.h" + +#include "php_xdebug.h" + +typedef struct _xdebug_profiler_globals_t { + zend_bool active; + uint64_t profiler_start_nanotime; + xdebug_file profile_file; + xdebug_hash *profile_filename_refs; + int profile_last_filename_ref; + int php_internal_seen_before; + xdebug_hash *profile_functionname_refs; + int profile_last_functionname_ref; +} xdebug_profiler_globals_t; + +typedef struct _xdebug_profiler_settings_t { + char *profiler_output_name; /* "pid" or "crc32" */ + zend_bool profiler_append; +} xdebug_profiler_settings_t; + +void xdebug_init_profiler_globals(xdebug_profiler_globals_t *xg); +void xdebug_profiler_minit(void); +void xdebug_profiler_mshutdown(void); +void xdebug_profiler_rinit(void); +void xdebug_profiler_post_deactivate(void); + +void xdebug_profiler_pcntl_exec_handler(void); + +void xdebug_profiler_init_if_requested(zend_op_array *op_array); +void xdebug_profiler_execute_ex(function_stack_entry *fse, zend_op_array *op_array); +void xdebug_profiler_execute_ex_end(function_stack_entry *fse); +void xdebug_profiler_execute_internal(function_stack_entry *fse); +void xdebug_profiler_execute_internal_end(function_stack_entry *fse); + +void xdebug_profiler_init(char *script_name); +void xdebug_profiler_deinit(); + +void xdebug_profiler_add_function_details_user(function_stack_entry *fse, zend_op_array *op_array); +void xdebug_profiler_add_function_details_internal(function_stack_entry *fse); +void xdebug_profiler_free_function_details(function_stack_entry *fse); + +void xdebug_profiler_function_begin(function_stack_entry *fse); +void xdebug_profiler_function_end(function_stack_entry *fse); + +void xdebug_profile_call_entry_dtor(void *dummy, void *elem); + +char *xdebug_get_profiler_filename(void); + +PHP_FUNCTION(xdebug_get_profiler_filename); +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/profiler/profiler_private.h
Changed
(renamed from xdebug-3.1.5/src/profiler/profiler_private.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/tracing/trace_computerized.c
Added
@@ -0,0 +1,272 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#include "lib/php-header.h" +#include "ext/standard/php_string.h" + +#include "php_xdebug.h" +#include "tracing_private.h" +#include "trace_computerized.h" + +#include "lib/lib_private.h" +#include "lib/var_export_line.h" + +extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); + +void *xdebug_trace_computerized_init(char *fname, zend_string *script_filename, long options) +{ + xdebug_trace_computerized_context *tmp_computerized_context; + + tmp_computerized_context = xdmalloc(sizeof(xdebug_trace_computerized_context)); + tmp_computerized_context->trace_file = xdebug_trace_open_file(fname, script_filename, options); + + if (!tmp_computerized_context->trace_file) { + xdfree(tmp_computerized_context); + return NULL; + } + + return tmp_computerized_context; +} + +void xdebug_trace_computerized_deinit(void *ctxt) +{ + xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; + + xdebug_file_close(context->trace_file); + xdebug_file_dtor(context->trace_file); + context->trace_file = NULL; + + xdfree(context); +} + +void xdebug_trace_computerized_write_header(void *ctxt) +{ + xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; + char *str_time; + + xdebug_file_printf(context->trace_file, "Version: %s\n", XDEBUG_VERSION); + xdebug_file_printf(context->trace_file, "File format: 4\n"); + + str_time = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6); + xdebug_file_printf(context->trace_file, "TRACE START %s\n", str_time); + xdfree(str_time); + + xdebug_file_flush(context->trace_file); +} + +void xdebug_trace_computerized_write_footer(void *ctxt) +{ + xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; + char *str_time; + uint64_t nanotime; + + nanotime = xdebug_get_nanotime(); + + xdebug_file_printf(context->trace_file, "\t\t\t%F\t", XDEBUG_SECONDS_SINCE_START(nanotime)); + xdebug_file_printf(context->trace_file, "%zu", zend_memory_usage(0)); + xdebug_file_printf(context->trace_file, "\n"); + + str_time = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6); + xdebug_file_printf(context->trace_file, "TRACE END %s\n\n", str_time); + xdfree(str_time); + + xdebug_file_flush(context->trace_file); +} + +char *xdebug_trace_computerized_get_filename(void *ctxt) +{ + xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; + + return context->trace_file->name; +} + +static void add_single_value(xdebug_str *str, zval *zv) +{ + xdebug_str *tmp_value = NULL; + + tmp_value = xdebug_get_zval_value_line(zv, 0, NULL); + + if (tmp_value) { + xdebug_str_add_str(str, tmp_value); + xdebug_str_free(tmp_value); + } else { + xdebug_str_add_literal(str, "???"); + } +} + +static void add_arguments(xdebug_str *line_entry, function_stack_entry *fse) +{ + unsigned int j = 0; /* Counter */ + int sent_variables = fse->varc; + + if (sent_variables > 0 && fse->varsent_variables-1.is_variadic && Z_ISUNDEF(fse->varsent_variables-1.data)) { + sent_variables--; + } + + /* Nr of arguments (11) */ + xdebug_str_add_fmt(line_entry, "\t%d", sent_variables); + + /* Arguments (12-...) */ + for (j = 0; j < sent_variables; j++) { + xdebug_str_addc(line_entry, '\t'); + + if (!Z_ISUNDEF(fse->varj.data)) { + add_single_value(line_entry, &(fse->varj.data)); + } else { + xdebug_str_add_literal(line_entry, "???"); + } + } +} + +void xdebug_trace_computerized_function_entry(void *ctxt, function_stack_entry *fse, int function_nr) +{ + xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; + char *tmp_name; + xdebug_str str = XDEBUG_STR_INITIALIZER; + + xdebug_str_add_fmt(&str, "%d\t", fse->level); + xdebug_str_add_fmt(&str, "%d\t", function_nr); + + tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); + + xdebug_str_add_literal(&str, "0\t"); + xdebug_str_add_fmt(&str, "%F\t", XDEBUG_SECONDS_SINCE_START(fse->nanotime)); + xdebug_str_add_fmt(&str, "%lu\t", fse->memory); + xdebug_str_add_fmt(&str, "%s\t", tmp_name); + if (fse->user_defined == XDEBUG_USER_DEFINED) { + xdebug_str_add_literal(&str, "1\t"); + } else { + xdebug_str_add_literal(&str, "0\t"); + } + xdfree(tmp_name); + + if (fse->include_filename) { + if (fse->function.type == XFUNC_EVAL) { + zend_string *escaped; + + escaped = php_addcslashes(fse->include_filename, (char*) "'\\\0..\37", 6); + + xdebug_str_addc(&str, '\''); + xdebug_str_add_zstr(&str, escaped); + xdebug_str_addc(&str, '\''); + zend_string_release(escaped); + } else { + xdebug_str_add_zstr(&str, fse->include_filename); + } + } + + /* Filename and Lineno (9, 10) */ + xdebug_str_add_fmt(&str, "\t%s\t%d", ZSTR_VAL(fse->filename), fse->lineno); + + add_arguments(&str, fse); + + /* Trailing \n */ + xdebug_str_addc(&str, '\n'); + + xdebug_file_printf(context->trace_file, "%s", str.d); + xdebug_file_flush(context->trace_file); + xdfree(str.d); +} + +void xdebug_trace_computerized_function_exit(void *ctxt, function_stack_entry *fse, int function_nr) +{ + xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; + xdebug_str str = XDEBUG_STR_INITIALIZER; + + xdebug_str_add_fmt(&str, "%d\t", fse->level); + xdebug_str_add_fmt(&str, "%d\t", function_nr); + + xdebug_str_add_literal(&str, "1\t"); + xdebug_str_add_fmt(&str, "%F\t", XDEBUG_SECONDS_SINCE_START(xdebug_get_nanotime())); + xdebug_str_add_fmt(&str, "%lu\n", zend_memory_usage(0)); + + xdebug_file_printf(context->trace_file, "%s", str.d); + xdebug_file_flush(context->trace_file); + xdfree(str.d); +} + +void xdebug_trace_computerized_function_return_value(void *ctxt, function_stack_entry *fse, int function_nr, zval *return_value) +{ + xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; + xdebug_str str = XDEBUG_STR_INITIALIZER; + + xdebug_str_add_fmt(&str, "%d\t", fse->level); + xdebug_str_add_fmt(&str, "%d\t", function_nr); + xdebug_str_add_literal(&str, "R\t\t\t"); + + add_single_value(&str, return_value); + + xdebug_str_add_literal(&str, "\n"); + + xdebug_file_printf(context->trace_file, "%s", str.d); + xdebug_file_flush(context->trace_file); + xdfree(str.d); +} + +void xdebug_trace_computerized_assignment(void *ctxt, function_stack_entry *fse, char *full_varname, zval *retval, char *right_full_varname, const char *op, char *filename, int lineno) +{ + xdebug_trace_computerized_context *context = (xdebug_trace_computerized_context*) ctxt; + xdebug_str str = XDEBUG_STR_INITIALIZER; + xdebug_str *tmp_value; + + xdebug_str_add_fmt(&str, "%d\t", fse->level); + /* no function_nr */ + xdebug_str_add_literal(&str, "\t"); + + xdebug_str_add_literal(&str, "A\t"); + /* skip time index, memory usage, function name, user defined */ + xdebug_str_add_literal(&str, "\t\t\t\t"); + + /* Filename and Lineno (9, 10) */ + xdebug_str_add_fmt(&str, "\t%s\t%d", filename, lineno); + xdebug_str_add_fmt(&str, "\t%s", full_varname); + + if (op0 != '\0' ) { /* pre/post inc/dec ops are special */ + xdebug_str_addc(&str, ' '); + xdebug_str_add(&str, op, 0); + xdebug_str_addc(&str, ' '); + + tmp_value = xdebug_get_zval_value_line(retval, 0, NULL); + + if (tmp_value) { + xdebug_str_add_str(&str, tmp_value); + xdebug_str_free(tmp_value); + } else { + xdebug_str_add_literal(&str, "NULL"); + } + } + + /* Trailing \n */ + xdebug_str_add_literal(&str, "\n"); + + xdebug_file_printf(context->trace_file, "%s", str.d); + xdebug_file_flush(context->trace_file); + + xdfree(str.d); +} + +xdebug_trace_handler_t xdebug_trace_handler_computerized = +{ + xdebug_trace_computerized_init, + xdebug_trace_computerized_deinit, + xdebug_trace_computerized_write_header, + xdebug_trace_computerized_write_footer, + xdebug_trace_computerized_get_filename, + xdebug_trace_computerized_function_entry, + xdebug_trace_computerized_function_exit, + xdebug_trace_computerized_function_return_value, + NULL /* xdebug_trace_computerized_generator_return_value */, + xdebug_trace_computerized_assignment +};
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/tracing/trace_computerized.h
Changed
(renamed from xdebug-3.1.5/src/tracing/trace_computerized.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/tracing/trace_html.c
Added
@@ -0,0 +1,136 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#include "lib/php-header.h" + +#include "php_xdebug.h" +#include "tracing_private.h" +#include "trace_html.h" + +#include "lib/var.h" + +extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); + +void *xdebug_trace_html_init(char *fname, zend_string *script_filename, long options) +{ + xdebug_trace_html_context *tmp_html_context; + + tmp_html_context = xdmalloc(sizeof(xdebug_trace_html_context)); + tmp_html_context->trace_file = xdebug_trace_open_file(fname, script_filename, options); + + if (!tmp_html_context->trace_file) { + xdfree(tmp_html_context); + return NULL; + } + + return tmp_html_context; +} + +void xdebug_trace_html_deinit(void *ctxt) +{ + xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt; + + xdebug_file_close(context->trace_file); + xdebug_file_dtor(context->trace_file); + context->trace_file = NULL; + + xdfree(context); +} + +void xdebug_trace_html_write_header(void *ctxt) +{ + xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt; + + xdebug_file_printf(context->trace_file, "<table style='hyphens: auto; -webkit-hyphens: auto; -ms-hyphens: auto;' class='xdebug-trace' dir='ltr' border='1' cellspacing='0'>\n"); + xdebug_file_printf(context->trace_file, "\t<tr><th>#</th><th>Time</th>"); + xdebug_file_printf(context->trace_file, "<th>Mem</th>"); + xdebug_file_printf(context->trace_file, "<th colspan='2'>Function</th><th>Location</th></tr>\n"); + xdebug_file_flush(context->trace_file); +} + +void xdebug_trace_html_write_footer(void *ctxt) +{ + xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt; + + xdebug_file_printf(context->trace_file, "</table>\n"); + xdebug_file_flush(context->trace_file); +} + +char *xdebug_trace_html_get_filename(void *ctxt) +{ + xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt; + + return context->trace_file->name; +} + +void xdebug_trace_html_function_entry(void *ctxt, function_stack_entry *fse, int function_nr) +{ + xdebug_trace_html_context *context = (xdebug_trace_html_context*) ctxt; + char *tmp_name; + unsigned int j; + xdebug_str str = XDEBUG_STR_INITIALIZER; + + xdebug_str_add_literal(&str, "\t<tr>"); + xdebug_str_add_fmt(&str, "<td>%d</td>", function_nr); + xdebug_str_add_fmt(&str, "<td>%0.6F</td>", XDEBUG_SECONDS_SINCE_START(fse->nanotime)); + xdebug_str_add_fmt(&str, "<td align='right'>%lu</td>", fse->memory); + xdebug_str_add_literal(&str, "<td align='left'>"); + for (j = 0; j < fse->level - 1; j++) { + xdebug_str_add_literal(&str, " "); + } + xdebug_str_add_literal(&str, "-></td>"); + + tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); + xdebug_str_add_fmt(&str, "<td>%s(", tmp_name); + xdfree(tmp_name); + + if (fse->include_filename) { + if (fse->function.type == XFUNC_EVAL) { + xdebug_str *joined; + xdebug_arg *parts; + + parts = xdebug_arg_ctor(); + xdebug_explode("\n", ZSTR_VAL(fse->include_filename), parts, 99999); + joined = xdebug_join("<br />", parts, 0, 99999); + xdebug_arg_dtor(parts); + + xdebug_str_add_fmt(&str, "'%s'", joined->d); + xdebug_str_free(joined); + } else { + xdebug_str_add_zstr(&str, fse->include_filename); + } + } + + xdebug_str_add_fmt(&str, ")</td><td>%s:%d</td>", ZSTR_VAL(fse->filename), fse->lineno); + xdebug_str_add_literal(&str, "</tr>\n"); + + xdebug_file_printf(context->trace_file, "%s", str.d); + xdebug_file_flush(context->trace_file); + xdfree(str.d); +} + +xdebug_trace_handler_t xdebug_trace_handler_html = +{ + xdebug_trace_html_init, + xdebug_trace_html_deinit, + xdebug_trace_html_write_header, + xdebug_trace_html_write_footer, + xdebug_trace_html_get_filename, + xdebug_trace_html_function_entry, + NULL /* xdebug_trace_html_function_exit */, + NULL /* xdebug_trace_html_function_return_value */, + NULL /* xdebug_trace_html_generator_return_value */, + NULL /* xdebug_trace_html_assignment */ +};
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/tracing/trace_html.h
Changed
(renamed from xdebug-3.1.5/src/tracing/trace_html.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/tracing/trace_textual.c
Added
@@ -0,0 +1,340 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#include "lib/php-header.h" +#include "ext/standard/php_string.h" + +#include "php_xdebug.h" +#include "tracing_private.h" +#include "trace_textual.h" + +#include "lib/lib_private.h" +#include "lib/var_export_line.h" + +extern ZEND_DECLARE_MODULE_GLOBALS(xdebug); + +void *xdebug_trace_textual_init(char *fname, zend_string *script_filename, long options) +{ + xdebug_trace_textual_context *tmp_textual_context; + + tmp_textual_context = xdmalloc(sizeof(xdebug_trace_textual_context)); + tmp_textual_context->trace_file = xdebug_trace_open_file(fname, script_filename, options); + + if (!tmp_textual_context->trace_file) { + xdfree(tmp_textual_context); + return NULL; + } + + return tmp_textual_context; +} + +void xdebug_trace_textual_deinit(void *ctxt) +{ + xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; + + xdebug_file_close(context->trace_file); + xdebug_file_dtor(context->trace_file); + context->trace_file = NULL; + + xdfree(context); +} + +void xdebug_trace_textual_write_header(void *ctxt) +{ + xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; + char *str_time; + + str_time = xdebug_nanotime_to_chars(xdebug_get_nanotime(), 6); + xdebug_file_printf(context->trace_file, "TRACE START %s\n", str_time); + xdfree(str_time); + + xdebug_file_flush(context->trace_file); +} + +void xdebug_trace_textual_write_footer(void *ctxt) +{ + xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; + char *str_time; + uint64_t nanotime; + char *tmp; + + nanotime = xdebug_get_nanotime(); + tmp = xdebug_sprintf("%10.4F ", XDEBUG_SECONDS_SINCE_START(nanotime)); + xdebug_file_printf(context->trace_file, "%s", tmp); + xdfree(tmp); + xdebug_file_printf(context->trace_file, "%10zu", zend_memory_usage(0)); + xdebug_file_printf(context->trace_file, "\n"); + + str_time = xdebug_nanotime_to_chars(nanotime, 6); + xdebug_file_printf(context->trace_file, "TRACE END %s\n\n", str_time); + xdfree(str_time); + + xdebug_file_flush(context->trace_file); +} + +char *xdebug_trace_textual_get_filename(void *ctxt) +{ + xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; + + return context->trace_file->name; +} + +static void add_single_value(xdebug_str *str, zval *zv) +{ + xdebug_str *tmp_value = NULL; + + tmp_value = xdebug_get_zval_value_line(zv, 0, NULL); + + if (tmp_value) { + xdebug_str_add_str(str, tmp_value); + xdebug_str_free(tmp_value); + } else { + xdebug_str_add_literal(str, "???"); + } +} + +static void add_arguments(xdebug_str *line_entry, function_stack_entry *fse) +{ + unsigned int j = 0; /* Counter */ + int c = 0; /* Comma flag */ + int variadic_opened = 0; + int variadic_count = 0; + int sent_variables = fse->varc; + + if (sent_variables > 0 && fse->varsent_variables-1.is_variadic && Z_ISUNDEF(fse->varsent_variables-1.data)) { + sent_variables--; + } + + for (j = 0; j < sent_variables; j++) { + if (c) { + xdebug_str_add_literal(line_entry, ", "); + } else { + c = 1; + } + + if (fse->varj.is_variadic) { + xdebug_str_add_literal(line_entry, "..."); + variadic_opened = 1; + c = 0; + } + + if (fse->varj.name) { + xdebug_str_addc(line_entry, '$'); + xdebug_str_add_zstr(line_entry, fse->varj.name); + if (variadic_opened && !fse->varj.is_variadic) { + xdebug_str_add_literal(line_entry, " => "); + } else { + xdebug_str_add_literal(line_entry, " = "); + } + } + + if (fse->varj.is_variadic) { + xdebug_str_add_literal(line_entry, "variadic("); + if (Z_ISUNDEF(fse->varj.data)) { + continue; + } + c = 1; + } + + if (variadic_opened && (!fse->varj.name || fse->varj.is_variadic)) { + xdebug_str_add_fmt(line_entry, "%d => ", variadic_count++); + } + + if (!Z_ISUNDEF(fse->varj.data)) { + add_single_value(line_entry, &fse->varj.data); + } else { + xdebug_str_add_literal(line_entry, "???"); + } + } + + if (variadic_opened) { + xdebug_str_addc(line_entry, ')'); + } +} + +void xdebug_trace_textual_function_entry(void *ctxt, function_stack_entry *fse, int function_nr) +{ + xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; + unsigned int j = 0; /* Counter */ + char *tmp_name; + xdebug_str str = XDEBUG_STR_INITIALIZER; + + tmp_name = xdebug_show_fname(fse->function, XDEBUG_SHOW_FNAME_DEFAULT); + + xdebug_str_add_fmt(&str, "%10.4F ", XDEBUG_SECONDS_SINCE_START(fse->nanotime)); + xdebug_str_add_fmt(&str, "%10lu ", fse->memory); + for (j = 0; j < fse->level; j++) { + xdebug_str_add_literal(&str, " "); + } + xdebug_str_add_fmt(&str, "-> %s(", tmp_name); + + xdfree(tmp_name); + + add_arguments(&str, fse); + + if (fse->include_filename) { + if (fse->function.type == XFUNC_EVAL) { + zend_string *escaped; + + escaped = php_addcslashes(fse->include_filename, (char*) "'\\\0..\37", 6); + + xdebug_str_addc(&str, '\''); + xdebug_str_add_zstr(&str, escaped); + xdebug_str_addc(&str, '\''); + zend_string_release(escaped); + } else { + xdebug_str_add_zstr(&str, fse->include_filename); + } + } + + xdebug_str_add_fmt(&str, ") %s:%d\n", ZSTR_VAL(fse->filename), fse->lineno); + + xdebug_file_printf(context->trace_file, "%s", str.d); + xdebug_file_flush(context->trace_file); + + xdfree(str.d); +} + +/* Used for normal return values, and generator return values */ +static void xdebug_return_trace_stack_common(xdebug_str *str, function_stack_entry *fse) +{ + unsigned int j = 0; /* Counter */ + + xdebug_str_add_fmt(str, "%10.4F ", XDEBUG_SECONDS_SINCE_START(xdebug_get_nanotime())); + xdebug_str_add_fmt(str, "%10lu ", zend_memory_usage(0)); + + for (j = 0; j < fse->level; j++) { + xdebug_str_add_literal(str, " "); + } + xdebug_str_add_literal(str, " >=> "); +} + + +void xdebug_trace_textual_function_return_value(void *ctxt, function_stack_entry *fse, int function_nr, zval *return_value) +{ + xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; + xdebug_str str = XDEBUG_STR_INITIALIZER; + xdebug_str *tmp_value; + + xdebug_return_trace_stack_common(&str, fse); + + tmp_value = xdebug_get_zval_value_line(return_value, 0, NULL); + if (tmp_value) { + xdebug_str_add_str(&str, tmp_value); + xdebug_str_free(tmp_value); + } + xdebug_str_addc(&str, '\n'); + + xdebug_file_printf(context->trace_file, "%s", str.d); + xdebug_file_flush(context->trace_file); + + xdebug_str_destroy(&str); +} + +void xdebug_trace_textual_generator_return_value(void *ctxt, function_stack_entry *fse, int function_nr, zend_generator *generator) +{ + xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; + xdebug_str str = XDEBUG_STR_INITIALIZER; + xdebug_str *tmp_value = NULL; + + if (! (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING)) { + return; + } + + if (generator->execute_data == NULL) { + return; + } + + /* Generator key */ + tmp_value = xdebug_get_zval_value_line(&generator->key, 0, NULL); + if (!tmp_value) { + return; + } + + xdebug_return_trace_stack_common(&str, fse); + + xdebug_str_addc(&str, '('); + xdebug_str_add_str(&str, tmp_value); + xdebug_str_add_literal(&str, " => "); + + tmp_value = xdebug_get_zval_value_line(&generator->value, 0, NULL); + if (tmp_value) { + xdebug_str_add_str(&str, tmp_value); + xdebug_str_free(tmp_value); + } + + xdebug_str_add_literal(&str, ")\n"); + + xdebug_file_printf(context->trace_file, "%s", str.d); + xdebug_file_flush(context->trace_file); + + xdebug_str_destroy(&str); +} + +void xdebug_trace_textual_assignment(void *ctxt, function_stack_entry *fse, char *full_varname, zval *retval, char *right_full_varname, const char *op, char *filename, int lineno) +{ + xdebug_trace_textual_context *context = (xdebug_trace_textual_context*) ctxt; + unsigned int j = 0; + xdebug_str str = XDEBUG_STR_INITIALIZER; + xdebug_str *tmp_value; + + xdebug_str_add_literal(&str, " "); + for (j = 0; j <= fse->level; j++) { + xdebug_str_add_literal(&str, " "); + } + xdebug_str_add_literal(&str, " => "); + + xdebug_str_add(&str, full_varname, 0); + + if (op0 != '\0' ) { /* pre/post inc/dec ops are special */ + xdebug_str_addc(&str, ' '); + xdebug_str_add(&str, op, 0); + xdebug_str_addc(&str, ' '); + + if (right_full_varname) { + xdebug_str_add(&str, right_full_varname, 0); + } else { + tmp_value = xdebug_get_zval_value_line(retval, 0, NULL); + + if (tmp_value) { + xdebug_str_add_str(&str, tmp_value); + xdebug_str_free(tmp_value); + } else { + xdebug_str_add_literal(&str, "NULL"); + } + } + + } + xdebug_str_add_fmt(&str, " %s:%d\n", filename, lineno); + + xdebug_file_printf(context->trace_file, "%s", str.d); + xdebug_file_flush(context->trace_file); + + xdfree(str.d); +} + +xdebug_trace_handler_t xdebug_trace_handler_textual = +{ + xdebug_trace_textual_init, + xdebug_trace_textual_deinit, + xdebug_trace_textual_write_header, + xdebug_trace_textual_write_footer, + xdebug_trace_textual_get_filename, + xdebug_trace_textual_function_entry, + NULL /*xdebug_trace_textual_function_exit */, + xdebug_trace_textual_function_return_value, + xdebug_trace_textual_generator_return_value, + xdebug_trace_textual_assignment +};
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/tracing/trace_textual.h
Changed
(renamed from xdebug-3.1.5/src/tracing/trace_textual.h)
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/tracing/tracing.c
Added
@@ -0,0 +1,770 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#include "lib/php-header.h" +#include "ext/standard/php_string.h" + +#include "php_xdebug.h" +#include "tracing_private.h" +#include "trace_textual.h" +#include "trace_computerized.h" +#include "trace_html.h" + +#include "lib/compat.h" +#include "lib/log.h" +#include "lib/str.h" +#include "lib/var_export_line.h" + +ZEND_EXTERN_MODULE_GLOBALS(xdebug) + +static xdebug_trace_handler_t *xdebug_select_trace_handler(int options) +{ + xdebug_trace_handler_t *tmp; + + switch (XINI_TRACE(trace_format)) { + case 0: tmp = &xdebug_trace_handler_textual; break; + case 1: tmp = &xdebug_trace_handler_computerized; break; + case 2: tmp = &xdebug_trace_handler_html; break; + default: + php_error(E_NOTICE, "A wrong value for xdebug.trace_format was selected (%d), defaulting to the textual format", (int) XINI_TRACE(trace_format)); + tmp = &xdebug_trace_handler_textual; break; + } + + if (options & XDEBUG_TRACE_OPTION_COMPUTERIZED) { + tmp = &xdebug_trace_handler_computerized; + } + if (options & XDEBUG_TRACE_OPTION_HTML) { + tmp = &xdebug_trace_handler_html; + } + + if (!tmp->init || !tmp->deinit || !tmp->get_filename) { + xdebug_log_ex(XLOG_CHAN_TRACE, XLOG_CRIT, "HNDLR", "Broken trace handler for format '%d', missing 'init', 'deinit', or 'get_filename' handler", options); + } + + return tmp; +} + +xdebug_file *xdebug_trace_open_file(char *requested_filename, zend_string *script_filename, long options) +{ + xdebug_file *file = xdebug_file_ctor(); + char *filename_to_use; + char *generated_filename = NULL; + char *output_dir = xdebug_lib_get_output_dir(); /* not duplicated */ + + if (requested_filename && strlen(requested_filename)) { + filename_to_use = xdstrdup(requested_filename); + } else { + + if (!strlen(XINI_TRACE(trace_output_name)) || + xdebug_format_output_filename(&generated_filename, XINI_TRACE(trace_output_name), ZSTR_VAL(script_filename)) <= 0 + ) { + /* Invalid or empty xdebug.trace_output_name */ + xdebug_file_dtor(file); + return NULL; + } + + /* Add a slash if none is present in the output_dir setting */ + output_dir = xdebug_lib_get_output_dir(); /* not duplicated */ + + if (IS_SLASH(output_dirstrlen(output_dir) - 1)) { + filename_to_use = xdebug_sprintf("%s%s", output_dir, generated_filename); + } else { + filename_to_use = xdebug_sprintf("%s%c%s", output_dir, DEFAULT_SLASH, generated_filename); + } + } + + if (!xdebug_file_open( + file, + filename_to_use, + (options & XDEBUG_TRACE_OPTION_NAKED_FILENAME) ? NULL : "xt", + (options & XDEBUG_TRACE_OPTION_APPEND) ? "ab" : "wb" + )) { + xdebug_log_diagnose_permissions(XLOG_CHAN_TRACE, output_dir, generated_filename); + } + + if (generated_filename) { + xdfree(generated_filename); + } + xdfree(filename_to_use); + + return file; +} + +static char* xdebug_start_trace(char* fname, zend_string *script_filename, long options) +{ + if (XG_TRACE(trace_context)) { + return NULL; + } + + XG_TRACE(trace_handler) = xdebug_select_trace_handler(options); + if (!XG_TRACE(trace_handler)) { + return NULL; + } + + XG_TRACE(trace_context) = (void*) XG_TRACE(trace_handler)->init(fname, script_filename, options); + if (!XG_TRACE(trace_context)) { + return NULL; + } + + if (XG_TRACE(trace_handler)->write_header) { + XG_TRACE(trace_handler)->write_header(XG_TRACE(trace_context)); + } + + return xdstrdup(XG_TRACE(trace_handler)->get_filename(XG_TRACE(trace_context))); +} + +static void xdebug_stop_trace(void) +{ + if (!XG_TRACE(trace_context)) { + return; + } + + if (XG_TRACE(trace_handler)->write_footer) { + XG_TRACE(trace_handler)->write_footer(XG_TRACE(trace_context)); + } + XG_TRACE(trace_handler)->deinit(XG_TRACE(trace_context)); + XG_TRACE(trace_context) = NULL; +} + +char *xdebug_get_trace_filename(void) +{ + if (!(XG_TRACE(trace_context) && XG_TRACE(trace_handler) && XG_TRACE(trace_handler)->get_filename)) { + return NULL; + } + + return XG_TRACE(trace_handler)->get_filename(XG_TRACE(trace_context)); +} + +PHP_FUNCTION(xdebug_start_trace) +{ + char *fname = NULL; + size_t fname_len = 0; + char *trace_fname; + zend_long options = XINI_TRACE(trace_options); + function_stack_entry *fse; + + WARN_AND_RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_TRACING); + + if (XG_TRACE(trace_context)) { + php_error(E_NOTICE, "Function trace already started"); + RETURN_FALSE; + } + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "|sl", &fname, &fname_len, &options) == FAILURE) { + return; + } + + fse = xdebug_get_stack_frame(0); + + if ((trace_fname = xdebug_start_trace(fname, fse->filename, options)) != NULL) { + RETVAL_STRING(trace_fname); + xdfree(trace_fname); + return; + } else { + php_error(E_NOTICE, "Trace could not be started"); + } + + RETURN_FALSE; +} + +PHP_FUNCTION(xdebug_stop_trace) +{ + WARN_AND_RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_TRACING); + + if (!XG_TRACE(trace_context)) { + php_error(E_NOTICE, "Function trace was not started"); + RETURN_FALSE; + } + + RETVAL_STRING(XG_TRACE(trace_handler)->get_filename(XG_TRACE(trace_context))); + xdebug_stop_trace(); +} + +PHP_FUNCTION(xdebug_get_tracefile_name) +{ + char *filename; + + WARN_AND_RETURN_IF_MODE_IS_NOT(XDEBUG_MODE_TRACING); + + filename = xdebug_get_trace_filename(); + if (!filename) { + RETURN_FALSE; + } + + RETVAL_STRING(filename); +} + +static const char *get_assign_operation(uint32_t extended_value) +{ + switch (extended_value) { + case ZEND_ADD: return "+="; + case ZEND_SUB: return "-="; + case ZEND_MUL: return "*="; + case ZEND_DIV: return "/="; + case ZEND_MOD: return "%="; + case ZEND_SL: return "<<="; + case ZEND_SR: return ">>="; + case ZEND_CONCAT: return ".="; + case ZEND_BW_OR: return "|="; + case ZEND_BW_AND: return "&="; + case ZEND_BW_XOR: return "^="; + case ZEND_POW: return "**="; + default: + return ""; + } +} + +static int xdebug_is_static_call(const zend_op *first_opcode, const zend_op *cur_opcode, const zend_op *prev_opcode, const zend_op **found_opcode) +{ + const zend_op *opcode_ptr; + + opcode_ptr = cur_opcode; + + if ( + (opcode_ptr->opcode == ZEND_ASSIGN_STATIC_PROP) || (opcode_ptr->opcode == ZEND_ASSIGN_STATIC_PROP_REF) || + (opcode_ptr->opcode == ZEND_PRE_INC_STATIC_PROP) || (opcode_ptr->opcode == ZEND_PRE_DEC_STATIC_PROP) || + (opcode_ptr->opcode == ZEND_POST_INC_STATIC_PROP) || (opcode_ptr->opcode == ZEND_POST_DEC_STATIC_PROP) + ) { + *found_opcode = opcode_ptr; + return 1; + } + + while (!(opcode_ptr->opcode == ZEND_EXT_STMT) && !((opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_W) || (opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_RW))) { + opcode_ptr = opcode_ptr - 1; + if (opcode_ptr < first_opcode) { + return 0; + } + } + if ((opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_W) || (opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_RW)) { + *found_opcode = opcode_ptr; + return 1; + } + return 0; +} + +static const zend_op *xdebug_find_referenced_opline(zend_execute_data *execute_data, const zend_op *cur_opcode, int op1_or_op2) +{ + size_t variable_number; + const zend_op *scan_opcode; + int found; + int op_type = (op1_or_op2 == 1) ? cur_opcode->op1_type : cur_opcode->op2_type; + + if (op_type != IS_VAR) { + return NULL; + } + + variable_number = (op1_or_op2 == 1) ? cur_opcode->op1.var : cur_opcode->op2.var; + scan_opcode = cur_opcode; + found = 0; + + /* Scroll up until we find a RES of IS_VAR with the right value */ + do { + scan_opcode--; + if (scan_opcode->result_type == IS_VAR && scan_opcode->result.var == variable_number) { + found = 1; + } + } while (!found); + + return scan_opcode; +} + +static int is_fetch_op(const zend_op *op) +{ + return ( + op->opcode == ZEND_FETCH_DIM_W || op->opcode == ZEND_FETCH_DIM_RW || + op->opcode == ZEND_FETCH_OBJ_W || op->opcode == ZEND_FETCH_OBJ_RW || + op->opcode == ZEND_FETCH_W || op->opcode == ZEND_FETCH_RW + ); +} + +static char *xdebug_find_var_name(zend_execute_data *execute_data, const zend_op *cur_opcode, const zend_op *lower_bound) +{ + const zend_op *next_opcode, *prev_opcode = NULL, *opcode_ptr; + zval *dimval; + int is_var; + zend_op_array *op_array = &execute_data->func->op_array; + xdebug_str name = XDEBUG_STR_INITIALIZER; + int gohungfound = 0, is_static = 0; + xdebug_str *zval_value = NULL; + xdebug_var_export_options *options; + const zend_op *static_opcode_ptr = NULL; + + next_opcode = cur_opcode + 1; + prev_opcode = cur_opcode - 1; + + if (cur_opcode->opcode == ZEND_QM_ASSIGN) { + xdebug_str_addc(&name, '$'); + xdebug_str_add(&name, zend_get_compiled_variable_name(op_array, cur_opcode->result.var)->val, 0); + + return name.d; + } + + is_static = xdebug_is_static_call(op_array->opcodes, cur_opcode, prev_opcode, &static_opcode_ptr); + options = xdebug_var_export_options_from_ini(); + options->no_decoration = 1; + + if (cur_opcode->op1_type == IS_CV) { + if (!lower_bound) { + xdebug_str_addc(&name, '$'); + xdebug_str_add(&name, zend_get_compiled_variable_name(op_array, cur_opcode->op1.var)->val, 0); + } + } else if (cur_opcode->op1_type == IS_VAR && cur_opcode->opcode == ZEND_ASSIGN && (prev_opcode->opcode == ZEND_FETCH_W || prev_opcode->opcode == ZEND_FETCH_RW)) { + if (is_static) { + xdebug_str_add_literal(&name, "self::"); + } else { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, prev_opcode, prev_opcode->op1_type, &prev_opcode->op1, &is_var), 0, options); + xdebug_str_addc(&name, '$'); + xdebug_str_add_str(&name, zval_value); + xdebug_str_free(zval_value); + } + } else if (is_static) { /* todo : see if you can change this and the previous cases around */ + xdebug_str_add_literal(&name, "self::"); + } + if (cur_opcode->opcode >= ZEND_PRE_INC_OBJ && cur_opcode->opcode <= ZEND_POST_DEC_OBJ) { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var), 0, options); + xdebug_str_add_literal(&name, "$this->"); + xdebug_str_add_str(&name, zval_value); + xdebug_str_free(zval_value); + } + + if (cur_opcode->opcode >= ZEND_PRE_INC_STATIC_PROP && cur_opcode->opcode <= ZEND_POST_DEC_STATIC_PROP) { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var), 0, options); + xdebug_str_add_str(&name, zval_value); + xdebug_str_free(zval_value); + } + + /* Scroll back to start of FETCHES */ + /* FIXME: See whether we can do this unroll looping only once - in is_static() */ + gohungfound = 0; + if (!is_static) { + if (cur_opcode == lower_bound) { + gohungfound = 1; + } + opcode_ptr = prev_opcode; + while ((opcode_ptr >= lower_bound) && is_fetch_op(opcode_ptr)) { + opcode_ptr = opcode_ptr - 1; + gohungfound = 1; + } + opcode_ptr = opcode_ptr + 1; + } else { /* if we have a static method, we should already have found the first fetch */ + opcode_ptr = static_opcode_ptr; + gohungfound = 1; + } + + if (gohungfound) { + int cv_found = 0; + + do + { + if ( + opcode_ptr->op1_type == IS_UNUSED && + (opcode_ptr->opcode == ZEND_FETCH_OBJ_W || opcode_ptr->opcode == ZEND_FETCH_OBJ_RW) + ) { + xdebug_str_add_literal(&name, "$this"); + } + if (opcode_ptr->op1_type == IS_CV) { + xdebug_str_addc(&name, '$'); + xdebug_str_add(&name, zend_get_compiled_variable_name(op_array, opcode_ptr->op1.var)->val, 0); + } + if (opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_W || opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_R || opcode_ptr->opcode == ZEND_FETCH_STATIC_PROP_RW) { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op1_type, &opcode_ptr->op1, &is_var), 0, options); + xdebug_str_add_str(&name, zval_value); + xdebug_str_free(zval_value); + } + if (opcode_ptr->opcode == ZEND_FETCH_W) { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op1_type, &opcode_ptr->op1, &is_var), 0, options); + xdebug_str_add_str(&name, zval_value); + xdebug_str_free(zval_value); + } + if (is_static && opcode_ptr->opcode == ZEND_FETCH_RW) { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op1_type, &opcode_ptr->op1, &is_var), 0, options); + xdebug_str_add_str(&name, zval_value); + xdebug_str_free(zval_value); + } + if (opcode_ptr->opcode == ZEND_FETCH_DIM_W || opcode_ptr->opcode == ZEND_FETCH_DIM_RW) { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op2_type, &opcode_ptr->op2, &is_var), 0, NULL); + xdebug_str_addc(&name, ''); + if (zval_value) { + xdebug_str_add_str(&name, zval_value); + } + xdebug_str_addc(&name, ''); + xdebug_str_free(zval_value); + } else if (opcode_ptr->opcode == ZEND_FETCH_OBJ_W || opcode_ptr->opcode == ZEND_FETCH_OBJ_RW) { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op2_type, &opcode_ptr->op2, &is_var), 0, options); + xdebug_str_add_literal(&name, "->"); + xdebug_str_add_str(&name, zval_value); + xdebug_str_free(zval_value); + } + opcode_ptr = opcode_ptr + 1; + if (opcode_ptr->op1_type == IS_CV) { + cv_found = 1; + } + } while (!cv_found && is_fetch_op(opcode_ptr)); + } + + if ( + (cur_opcode->opcode == ZEND_ASSIGN_OBJ) || + (cur_opcode->opcode == ZEND_ASSIGN_OBJ_REF) + ) { + if (cur_opcode->op1_type == IS_UNUSED) { + xdebug_str_add_literal(&name, "$this"); + } + dimval = xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var); + xdebug_str_add_literal(&name, "->"); + xdebug_str_add(&name, Z_STRVAL_P(dimval), 0); + } + + if (cur_opcode->opcode == ZEND_ASSIGN_STATIC_PROP_REF) { + dimval = xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var); + xdebug_str_add(&name, Z_STRVAL_P(dimval), 0); + } + if (cur_opcode->opcode == ZEND_ASSIGN_DIM_OP) { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var), 0, NULL); + xdebug_str_addc(&name, ''); + xdebug_str_add_str(&name, zval_value); + xdebug_str_addc(&name, ''); + xdebug_str_free(zval_value); + } + if (cur_opcode->opcode == ZEND_ASSIGN_OBJ_OP) { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var), 0, options); + if (cur_opcode->op1_type == IS_UNUSED) { + xdebug_str_add_literal(&name, "$this->"); + } else { + xdebug_str_add_literal(&name, "->"); + } + xdebug_str_add_str(&name, zval_value); + xdebug_str_free(zval_value); + } + if (cur_opcode->opcode == ZEND_ASSIGN_STATIC_PROP_OP) { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var), 0, options); + xdebug_str_add_literal(&name, "self::"); + xdebug_str_add_str(&name, zval_value); + xdebug_str_free(zval_value); + } + + if (cur_opcode->opcode == ZEND_ASSIGN_DIM) { + if (next_opcode->opcode == ZEND_OP_DATA && cur_opcode->op2_type == IS_UNUSED) { + xdebug_str_add_literal(&name, ""); + } else { + zval_value = xdebug_get_zval_value_line(xdebug_get_zval_with_opline(execute_data, opcode_ptr, opcode_ptr->op2_type, &opcode_ptr->op2, &is_var), 0, NULL); + xdebug_str_addc(&name, ''); + xdebug_str_add_str(&name, zval_value); + xdebug_str_addc(&name, ''); + xdebug_str_free(zval_value); + } + } + + if (cur_opcode->opcode == ZEND_ASSIGN_STATIC_PROP) { + dimval = xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var); + xdebug_str_add(&name, Z_STRVAL_P(dimval), 0); + } + + xdfree(options->runtime); + xdfree(options); + + return name.d; +} + +static int xdebug_common_assign_dim_handler(const char *op, XDEBUG_OPCODE_HANDLER_ARGS) +{ + char *file; + zend_op_array *op_array = &execute_data->func->op_array; + int lineno; + const zend_op *cur_opcode, *next_opcode; + zval *val = NULL; + char *right_full_varname = NULL; + int is_var; + function_stack_entry *fse; + + cur_opcode = execute_data->opline; + next_opcode = cur_opcode + 1; + file = (char*) STR_NAME_VAL(op_array->filename); + lineno = cur_opcode->lineno; + + /* TODO TEST FOR ASSIGNMENTS IN FILTERING */ +// if (xdebug_is_top_stack_frame_filtered(XDEBUG_FILTER_CODE_COVERAGE)) { +// return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); +// } + + if (XG_TRACE(trace_context) && XINI_TRACE(collect_assignments)) { + char *full_varname; + + if (cur_opcode->opcode == ZEND_QM_ASSIGN && cur_opcode->result_type != IS_CV) { + return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); + } + full_varname = xdebug_find_var_name(execute_data, execute_data->opline, NULL); + + if (cur_opcode->opcode >= ZEND_PRE_INC && cur_opcode->opcode <= ZEND_POST_DEC) { + char *tmp_varname; + + switch (cur_opcode->opcode) { + case ZEND_PRE_INC: tmp_varname = xdebug_sprintf("++%s", full_varname); break; + case ZEND_POST_INC: tmp_varname = xdebug_sprintf("%s++", full_varname); break; + case ZEND_PRE_DEC: tmp_varname = xdebug_sprintf("--%s", full_varname); break; + case ZEND_POST_DEC: tmp_varname = xdebug_sprintf("%s--", full_varname); break; + } + xdfree(full_varname); + full_varname = tmp_varname; + + val = xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var); + } else if (cur_opcode->opcode >= ZEND_PRE_INC_OBJ && cur_opcode->opcode <= ZEND_POST_DEC_OBJ) { + char *tmp_varname; + + switch (cur_opcode->opcode) { + case ZEND_PRE_INC_OBJ: tmp_varname = xdebug_sprintf("++%s", full_varname); break; + case ZEND_POST_INC_OBJ: tmp_varname = xdebug_sprintf("%s++", full_varname); break; + case ZEND_PRE_DEC_OBJ: tmp_varname = xdebug_sprintf("--%s", full_varname); break; + case ZEND_POST_DEC_OBJ: tmp_varname = xdebug_sprintf("%s--", full_varname); break; + } + xdfree(full_varname); + full_varname = tmp_varname; + + val = xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var); + } else if (cur_opcode->opcode >= ZEND_PRE_INC_STATIC_PROP && cur_opcode->opcode <= ZEND_POST_DEC_STATIC_PROP) { + char *tmp_varname; + + switch (cur_opcode->opcode) { + case ZEND_PRE_INC_STATIC_PROP: tmp_varname = xdebug_sprintf("++%s", full_varname); break; + case ZEND_POST_INC_STATIC_PROP: tmp_varname = xdebug_sprintf("%s++", full_varname); break; + case ZEND_PRE_DEC_STATIC_PROP: tmp_varname = xdebug_sprintf("--%s", full_varname); break; + case ZEND_POST_DEC_STATIC_PROP: tmp_varname = xdebug_sprintf("%s--", full_varname); break; + } + xdfree(full_varname); + full_varname = tmp_varname; + + val = xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var); + } else if ( + (next_opcode->opcode == ZEND_OP_DATA) && + (cur_opcode->opcode != ZEND_ASSIGN_OBJ_REF) && + (cur_opcode->opcode != ZEND_ASSIGN_STATIC_PROP_REF) + ) { + val = xdebug_get_zval_with_opline(execute_data, next_opcode, next_opcode->op1_type, &next_opcode->op1, &is_var); + } else if (cur_opcode->opcode == ZEND_QM_ASSIGN) { + val = xdebug_get_zval(execute_data, cur_opcode->op1_type, &cur_opcode->op1, &is_var); + } else if (cur_opcode->opcode == ZEND_ASSIGN_REF) { + if (cur_opcode->op2_type == IS_CV) { + right_full_varname = xdebug_sprintf("$%s", zend_get_compiled_variable_name(op_array, cur_opcode->op2.var)->val); + } else { + const zend_op *referenced_opline = xdebug_find_referenced_opline(execute_data, cur_opcode, 2); + right_full_varname = xdebug_find_var_name(execute_data, referenced_opline, NULL); + } + } else if (cur_opcode->opcode == ZEND_ASSIGN_OBJ_REF) { + if (next_opcode->op1_type == IS_CV) { + right_full_varname = xdebug_sprintf("$%s", zend_get_compiled_variable_name(op_array, next_opcode->op1.var)->val); + } else { + const zend_op *referenced_opline = xdebug_find_referenced_opline(execute_data, next_opcode, 1); + right_full_varname = xdebug_find_var_name(execute_data, referenced_opline, NULL); + } + } else if (cur_opcode->opcode == ZEND_ASSIGN_STATIC_PROP_REF) { + if (next_opcode->op1_type == IS_CV) { + right_full_varname = xdebug_sprintf("$%s", zend_get_compiled_variable_name(op_array, next_opcode->op1.var)->val); + } else { + const zend_op *referenced_opline = xdebug_find_referenced_opline(execute_data, next_opcode, 1); + right_full_varname = xdebug_find_var_name(execute_data, referenced_opline, NULL); + } + } else { + val = xdebug_get_zval(execute_data, cur_opcode->op2_type, &cur_opcode->op2, &is_var); + } + + fse = XDEBUG_VECTOR_TAIL(XG_BASE(stack)); + if (XG_TRACE(trace_context) && XINI_TRACE(collect_assignments) && XG_TRACE(trace_handler)->assignment) { + XG_TRACE(trace_handler)->assignment(XG_TRACE(trace_context), fse, full_varname, val, right_full_varname, op, file, lineno); + } + xdfree(full_varname); + xdfree(right_full_varname); + } + + return xdebug_call_original_opcode_handler_if_set(cur_opcode->opcode, XDEBUG_OPCODE_HANDLER_ARGS_PASSTHRU); +} + +XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign, "="); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(qm_assign, "="); +XDEBUG_OPCODE_OVERRIDE_ASSIGN_OP(assign_op); +XDEBUG_OPCODE_OVERRIDE_ASSIGN_OP(assign_dim_op); +XDEBUG_OPCODE_OVERRIDE_ASSIGN_OP(assign_obj_op); +XDEBUG_OPCODE_OVERRIDE_ASSIGN_OP(assign_static_prop_op); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_inc, ""); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_inc, ""); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_dec, ""); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_dec, ""); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_inc_obj, ""); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_inc_obj, ""); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_dec_obj, ""); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_dec_obj, ""); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_concat, ".="); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_dim, "="); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_obj, "="); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_ref, "=&"); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_obj_ref, "=&"); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_static_prop, "="); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(assign_static_prop_ref, "=&"); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_inc_static_prop, ""); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(pre_dec_static_prop, ""); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_inc_static_prop, ""); +XDEBUG_OPCODE_OVERRIDE_ASSIGN(post_dec_static_prop, ""); + +void xdebug_init_tracing_globals(xdebug_tracing_globals_t *xg) +{ + xg->trace_handler = NULL; + xg->trace_context = NULL; +} + +void xdebug_tracing_minit(INIT_FUNC_ARGS) +{ + /* Override opcodes for variable assignments in traces */ + xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN, xdebug_assign_handler); + xdebug_register_with_opcode_multi_handler(ZEND_QM_ASSIGN, xdebug_qm_assign_handler); + + xdebug_set_opcode_handler(ZEND_ASSIGN_OP, xdebug_assign_op_handler); + xdebug_set_opcode_handler(ZEND_ASSIGN_DIM_OP, xdebug_assign_dim_op_handler); + xdebug_set_opcode_handler(ZEND_ASSIGN_OBJ_OP, xdebug_assign_obj_op_handler); + xdebug_set_opcode_handler(ZEND_ASSIGN_STATIC_PROP_OP, xdebug_assign_static_prop_op_handler); + xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_DIM, xdebug_assign_dim_handler); + xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_OBJ, xdebug_assign_obj_handler); + xdebug_set_opcode_handler(ZEND_ASSIGN_REF, xdebug_assign_ref_handler); + xdebug_set_opcode_handler(ZEND_PRE_INC, xdebug_pre_inc_handler); + xdebug_set_opcode_handler(ZEND_POST_INC, xdebug_post_inc_handler); + xdebug_set_opcode_handler(ZEND_PRE_DEC, xdebug_pre_dec_handler); + xdebug_set_opcode_handler(ZEND_POST_DEC, xdebug_post_dec_handler); + xdebug_set_opcode_handler(ZEND_PRE_INC_OBJ, xdebug_pre_inc_obj_handler); + xdebug_set_opcode_handler(ZEND_POST_INC_OBJ, xdebug_post_inc_obj_handler); + xdebug_set_opcode_handler(ZEND_PRE_DEC_OBJ, xdebug_pre_dec_obj_handler); + xdebug_set_opcode_handler(ZEND_POST_DEC_OBJ, xdebug_post_dec_obj_handler); + xdebug_set_opcode_handler(ZEND_ASSIGN_OBJ_REF, xdebug_assign_obj_ref_handler); + xdebug_register_with_opcode_multi_handler(ZEND_ASSIGN_STATIC_PROP, xdebug_assign_static_prop_handler); + xdebug_set_opcode_handler(ZEND_ASSIGN_STATIC_PROP_REF, xdebug_assign_static_prop_ref_handler); + xdebug_set_opcode_handler(ZEND_PRE_INC_STATIC_PROP, xdebug_pre_inc_static_prop_handler); + xdebug_set_opcode_handler(ZEND_PRE_DEC_STATIC_PROP, xdebug_pre_dec_static_prop_handler); + xdebug_set_opcode_handler(ZEND_POST_INC_STATIC_PROP, xdebug_post_inc_static_prop_handler); + xdebug_set_opcode_handler(ZEND_POST_DEC_STATIC_PROP, xdebug_post_dec_static_prop_handler); +} + +void xdebug_tracing_register_constants(INIT_FUNC_ARGS) +{ + REGISTER_LONG_CONSTANT("XDEBUG_TRACE_APPEND", XDEBUG_TRACE_OPTION_APPEND, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XDEBUG_TRACE_COMPUTERIZED", XDEBUG_TRACE_OPTION_COMPUTERIZED, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XDEBUG_TRACE_HTML", XDEBUG_TRACE_OPTION_HTML, CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT("XDEBUG_TRACE_NAKED_FILENAME", XDEBUG_TRACE_OPTION_NAKED_FILENAME, CONST_CS | CONST_PERSISTENT); +} + +void xdebug_tracing_rinit(void) +{ + XG_TRACE(trace_handler) = NULL; + XG_TRACE(trace_context) = NULL; +} + +void xdebug_tracing_post_deactivate(void) +{ + if (XG_TRACE(trace_context)) { + xdebug_stop_trace(); + } + + XG_TRACE(trace_context) = NULL; +} + +void xdebug_tracing_init_if_requested(zend_op_array *op_array) +{ + if (xdebug_lib_start_with_request(XDEBUG_MODE_TRACING) || xdebug_lib_start_with_trigger(XDEBUG_MODE_TRACING, NULL)) { + /* In case we do an auto-trace we are not interested in the return + * value, but we still have to free it. */ + xdfree(xdebug_start_trace(NULL, op_array->filename, XINI_TRACE(trace_options))); + } +} + +void xdebug_tracing_execute_ex(int function_nr, function_stack_entry *fse) +{ + if (fse->filtered_tracing || !XG_TRACE(trace_context)) { + return; + } + + if (XG_TRACE(trace_handler)->function_entry) { + XG_TRACE(trace_handler)->function_entry(XG_TRACE(trace_context), fse, function_nr); + } +} + +void xdebug_tracing_execute_ex_end(int function_nr, function_stack_entry *fse, zend_execute_data *execute_data) +{ + zend_op_array *op_array; + + if (fse->filtered_tracing || !XG_TRACE(trace_context)) { + return; + } + + if ((XG_TRACE(trace_handler)->function_exit)) { + XG_TRACE(trace_handler)->function_exit(XG_TRACE(trace_context), fse, function_nr); + } + + /* Store return value in the trace file */ + if (!XINI_TRACE(collect_return)) { + return; + } + + op_array = &(execute_data->func->op_array); + + if (!execute_data || !execute_data->return_value) { + return; + } + + if (op_array->fn_flags & ZEND_ACC_GENERATOR) { + if (XG_TRACE(trace_handler)->generator_return_value) { + XG_TRACE(trace_handler)->generator_return_value(XG_TRACE(trace_context), fse, function_nr, (zend_generator*) execute_data->return_value); + } + } else { + if (XG_TRACE(trace_handler)->return_value) { + XG_TRACE(trace_handler)->return_value(XG_TRACE(trace_context), fse, function_nr, execute_data->return_value); + } + } +} + +int xdebug_tracing_execute_internal(int function_nr, function_stack_entry *fse) +{ + if (fse->filtered_tracing || !XG_TRACE(trace_context)) { + return 0; + } + + if (fse->function.type != XFUNC_ZEND_PASS && (XG_TRACE(trace_handler)->function_entry)) { + XG_TRACE(trace_handler)->function_entry(XG_TRACE(trace_context), fse, function_nr); + return 1; + } + + return 0; +} + +void xdebug_tracing_execute_internal_end(int function_nr, function_stack_entry *fse, zval *return_value) +{ + if (fse->filtered_tracing || !XG_TRACE(trace_context)) { + return; + } + + if (fse->function.type != XFUNC_ZEND_PASS && (XG_TRACE(trace_handler)->function_exit)) { + XG_TRACE(trace_handler)->function_exit(XG_TRACE(trace_context), fse, function_nr); + } + + /* Store return value in the trace file */ + if (XINI_TRACE(collect_return) && fse->function.type != XFUNC_ZEND_PASS && return_value && XG_TRACE(trace_handler)->return_value) { + XG_TRACE(trace_handler)->return_value(XG_TRACE(trace_context), fse, function_nr, return_value); + } +} + +void xdebug_tracing_save_trace_context(void **original_trace_context) +{ + *original_trace_context = XG_TRACE(trace_context); + XG_TRACE(trace_context) = NULL; +} + +void xdebug_tracing_restore_trace_context(void *original_trace_context) +{ + XG_TRACE(trace_context) = original_trace_context; +}
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/tracing/tracing.h
Added
@@ -0,0 +1,77 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#ifndef XDEBUG_TRACING_H +#define XDEBUG_TRACING_H + +#include "lib/php-header.h" + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeclaration-after-statement" +#include "zend_generators.h" +#pragma GCC diagnostic pop + +typedef struct +{ + void *(*init)(char *fname, zend_string *script_filename, long options); + void (*deinit)(void *ctxt); + void (*write_header)(void *ctxt); + void (*write_footer)(void *ctxt); + char *(*get_filename)(void *ctxt); + void (*function_entry)(void *ctxt, function_stack_entry *fse, int function_nr); + void (*function_exit)(void *ctxt, function_stack_entry *fse, int function_nr); + void (*return_value)(void *ctxt, function_stack_entry *fse, int function_nr, zval *return_value); + void (*generator_return_value)(void *ctxt, function_stack_entry *fse, int function_nr, zend_generator *generator); + void (*assignment)(void *ctxt, function_stack_entry *fse, char *full_varname, zval *value, char *right_full_varname, const char *op, char *file, int lineno); +} xdebug_trace_handler_t; + +typedef struct _xdebug_tracing_globals_t { + xdebug_trace_handler_t *trace_handler; + void *trace_context; +} xdebug_tracing_globals_t; + +typedef struct _xdebug_tracing_settings_t { + char *trace_output_name; + zend_long trace_options; + zend_long trace_format; + + zend_bool collect_assignments; + zend_bool collect_return; +} xdebug_tracing_settings_t; + +void xdebug_init_tracing_globals(xdebug_tracing_globals_t *xg); +void xdebug_tracing_minit(INIT_FUNC_ARGS); +void xdebug_tracing_rinit(void); +void xdebug_tracing_post_deactivate(void); +void xdebug_tracing_register_constants(INIT_FUNC_ARGS); + +void xdebug_tracing_init_if_requested(zend_op_array *op_array); +void xdebug_tracing_execute_ex(int function_nr, function_stack_entry *fse); +void xdebug_tracing_execute_ex_end(int function_nr, function_stack_entry *fse, zend_execute_data *execute_data); +int xdebug_tracing_execute_internal(int function_nr, function_stack_entry *fse); +void xdebug_tracing_execute_internal_end(int function_nr, function_stack_entry *fse, zval *return_value); + +void xdebug_tracing_save_trace_context(void **old_trace_context); +void xdebug_tracing_restore_trace_context(void *old_trace_context); + +char* xdebug_return_trace_stack_retval(function_stack_entry* i, int fnr, zval* retval); +char* xdebug_return_trace_stack_generator_retval(function_stack_entry* i, zend_generator* generator); +char* xdebug_return_trace_assignment(function_stack_entry *i, char *varname, zval *retval, char *op, char *file, int fileno); + +void xdebug_trace_function_begin(function_stack_entry *fse, int function_nr); +void xdebug_trace_function_end(function_stack_entry *fse, int function_nr); + +char *xdebug_get_trace_filename(void); +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/src/tracing/tracing_private.h
Added
@@ -0,0 +1,65 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2020 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ +#ifndef __XDEBUG_TRACING_PRIVATE_H__ +#define __XDEBUG_TRACING_PRIVATE_H__ + +#include "tracing.h" + +#define XG_TRACE(v) (XG(globals.tracing.v)) +#define XINI_TRACE(v) (XG(settings.tracing.v)) + +#define XDEBUG_OPCODE_OVERRIDE_ASSIGN(f,o) \ + int xdebug_##f##_handler(zend_execute_data *execute_data) \ + { \ + return xdebug_common_assign_dim_handler((o), execute_data); \ + } + +#define XDEBUG_OPCODE_OVERRIDE_ASSIGN_OP(f) \ + int xdebug_##f##_handler(zend_execute_data *execute_data) \ + { \ + const char *op = get_assign_operation(execute_data->opline->extended_value); \ + return xdebug_common_assign_dim_handler(op, execute_data); \ + } + +int xdebug_assign_handler(zend_execute_data *execute_data); +int xdebug_qm_assign_handler(zend_execute_data *execute_data); +int xdebug_assign_op_handler(zend_execute_data *execute_data); +int xdebug_assign_dim_op_handler(zend_execute_data *execute_data); +int xdebug_assign_obj_op_handler(zend_execute_data *execute_data); +int xdebug_assign_static_prop_op_handler(zend_execute_data *execute_data); +int xdebug_pre_inc_handler(zend_execute_data *execute_data); +int xdebug_post_inc_handler(zend_execute_data *execute_data); +int xdebug_pre_dec_handler(zend_execute_data *execute_data); +int xdebug_post_dec_handler(zend_execute_data *execute_data); +int xdebug_pre_inc_obj_handler(zend_execute_data *execute_data); +int xdebug_post_inc_obj_handler(zend_execute_data *execute_data); +int xdebug_pre_dec_obj_handler(zend_execute_data *execute_data); +int xdebug_post_dec_obj_handler(zend_execute_data *execute_data); +int xdebug_assign_concat_handler(zend_execute_data *execute_data); +int xdebug_assign_dim_handler(zend_execute_data *execute_data); +int xdebug_assign_obj_handler(zend_execute_data *execute_data); +int xdebug_assign_ref_handler(zend_execute_data *execute_data); +int xdebug_assign_obj_ref_handler(zend_execute_data *execute_data); +int xdebug_assign_static_prop_handler(zend_execute_data *execute_data); +int xdebug_assign_static_prop_ref_handler(zend_execute_data *execute_data); +int xdebug_pre_inc_static_prop_handler(zend_execute_data *execute_data); +int xdebug_pre_dec_static_prop_handler(zend_execute_data *execute_data); +int xdebug_post_inc_static_prop_handler(zend_execute_data *execute_data); +int xdebug_post_dec_static_prop_handler(zend_execute_data *execute_data); + +xdebug_file *xdebug_trace_open_file(char *fname, zend_string *script_filename, long options); + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/xdebug.c
Added
@@ -0,0 +1,802 @@ +/* + +----------------------------------------------------------------------+ + | Xdebug | + +----------------------------------------------------------------------+ + | Copyright (c) 2002-2022 Derick Rethans | + +----------------------------------------------------------------------+ + | This source file is subject to version 1.01 of the Xdebug license, | + | that is bundled with this package in the file LICENSE, and is | + | available at through the world-wide-web at | + | https://xdebug.org/license.php | + | If you did not receive a copy of the Xdebug license and are unable | + | to obtain it through the world-wide-web, please send a note to | + | derick@xdebug.org so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "lib/php-header.h" +#include "main/php_version.h" +#include "lib/compat.h" + +#if HAVE_XDEBUG + +#ifndef PHP_WIN32 +#include <sys/time.h> +#include <unistd.h> +#else +#include "win32/time.h" +#include <process.h> +#endif + +#include "TSRM.h" +#include "SAPI.h" +#include "zend_extensions.h" +#include "main/php_ini.h" +#include "ext/standard/head.h" +#include "ext/standard/html.h" +#include "ext/standard/info.h" +#include "ext/standard/php_string.h" +#include "php_globals.h" +#include "main/php_output.h" +#include "ext/standard/php_var.h" + +#include "php_xdebug.h" +#include "php_xdebug_arginfo.h" + +#include "base/base.h" +#include "base/filter.h" +#include "coverage/code_coverage.h" +#include "develop/monitor.h" +#include "develop/stack.h" +#include "develop/superglobals.h" +#include "gcstats/gc_stats.h" +#include "lib/usefulstuff.h" +#include "lib/lib.h" +#include "lib/llist.h" +#include "lib/log.h" +#include "lib/mm.h" +#include "lib/var_export_html.h" +#include "lib/var_export_line.h" +#include "lib/var_export_text.h" +#include "profiler/profiler.h" +#include "tracing/tracing.h" + +static zend_result (*xdebug_orig_post_startup_cb)(void); +static zend_result xdebug_post_startup(void); + +int xdebug_include_or_eval_handler(zend_execute_data *execute_data); + +int zend_xdebug_initialised = 0; + +zend_module_entry xdebug_module_entry = { + STANDARD_MODULE_HEADER, + "xdebug", + ext_functions, + PHP_MINIT(xdebug), + PHP_MSHUTDOWN(xdebug), + PHP_RINIT(xdebug), + PHP_RSHUTDOWN(xdebug), + PHP_MINFO(xdebug), + XDEBUG_VERSION, + NO_MODULE_GLOBALS, + ZEND_MODULE_POST_ZEND_DEACTIVATE_N(xdebug), + STANDARD_MODULE_PROPERTIES_EX +}; + +ZEND_DECLARE_MODULE_GLOBALS(xdebug) + +#if COMPILE_DL_XDEBUG +ZEND_GET_MODULE(xdebug) +# ifdef ZTS +ZEND_TSRMLS_CACHE_DEFINE(); +# endif +#endif + +static PHP_INI_MH(OnUpdateServer) +{ + DUMP_TOK(server); +} + +static PHP_INI_MH(OnUpdateGet) +{ + DUMP_TOK(get); +} + +static PHP_INI_MH(OnUpdatePost) +{ + DUMP_TOK(post); +} + +static PHP_INI_MH(OnUpdateCookie) +{ + DUMP_TOK(cookie); +} + +static PHP_INI_MH(OnUpdateFiles) +{ + DUMP_TOK(files); +} + +static PHP_INI_MH(OnUpdateEnv) +{ + DUMP_TOK(env); +} + +static PHP_INI_MH(OnUpdateRequest) +{ + DUMP_TOK(request); +} + +static PHP_INI_MH(OnUpdateSession) +{ + DUMP_TOK(session); +} + +static PHP_INI_MH(OnUpdateStartWithRequest) +{ + if (!new_value) { + return FAILURE; + } + + if (!xdebug_lib_set_start_with_request(ZSTR_VAL(new_value))) { + return FAILURE; + } + + return SUCCESS; +} + +static PHP_INI_MH(OnUpdateStartUponError) +{ + if (!new_value) { + return FAILURE; + } + + if (!xdebug_lib_set_start_upon_error(ZSTR_VAL(new_value))) { + return FAILURE; + } + + return SUCCESS; +} + +static PHP_INI_MH(OnUpdateRemovedSetting) +{ + if (! (EG(error_reporting) & E_DEPRECATED)) { + return SUCCESS; + } + if (new_value && ZSTR_LEN(new_value) > 0 && strncmp("This setting", ZSTR_VAL(new_value), 11) != 0) { + xdebug_log_ex( + XLOG_CHAN_CONFIG, XLOG_CRIT, "REMOVED", + "The setting '%s' has been removed, see the upgrading guide at %supgrade_guide#changed-%s", + ZSTR_VAL(entry->name), xdebug_lib_docs_base(), ZSTR_VAL(entry->name) + ); + } + return FAILURE; +} + +static PHP_INI_MH(OnUpdateChangedSetting) +{ + if (! (EG(error_reporting) & E_DEPRECATED)) { + return SUCCESS; + } + if (new_value && ZSTR_LEN(new_value) > 0 && strncmp("This setting", ZSTR_VAL(new_value), 11) != 0) { + xdebug_log_ex( + XLOG_CHAN_CONFIG, XLOG_CRIT, "CHANGED", + "The setting '%s' has been renamed, see the upgrading guide at %supgrade_guide#changed-%s", + ZSTR_VAL(entry->name), xdebug_lib_docs_base(), ZSTR_VAL(entry->name) + ); + } + return FAILURE; +} + + +#ifdef P_tmpdir +# define XDEBUG_TEMP_DIR P_tmpdir +#else +# ifdef PHP_WIN32 +# define XDEBUG_TEMP_DIR "C:\\Windows\\Temp" +# else +# define XDEBUG_TEMP_DIR "/tmp" +# endif +#endif + +ZEND_INI_DISP(display_removed_setting) +{ + ZEND_PUTS("(setting removed in Xdebug 3)"); +} + +ZEND_INI_DISP(display_changed_setting) +{ + ZEND_PUTS("(setting renamed in Xdebug 3)"); +} + +#define XDEBUG_REMOVED_INI_ENTRY(n) PHP_INI_ENTRY_EX(("" # n), "This setting has been removed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#removed-" # n, PHP_INI_ALL, OnUpdateRemovedSetting, display_removed_setting) +#define XDEBUG_CHANGED_INI_ENTRY(n) PHP_INI_ENTRY_EX(("" # n), "This setting has been changed, see the upgrading guide at https://xdebug.org/docs/upgrade_guide#changed-" # n, PHP_INI_ALL, OnUpdateChangedSetting, display_changed_setting) + +static const char *xdebug_start_with_request_types5 = { "", "default", "yes", "no", "trigger" }; + +ZEND_INI_DISP(display_start_with_request) +{ + char *value; + + if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { + value = ZSTR_VAL(ini_entry->orig_value); + } else if (ini_entry->value) { + value = ZSTR_VAL(ini_entry->value); + } else { + value = NULL; + } + if (value) { + ZEND_PUTS(xdebug_start_with_request_typesxdebug_lib_get_start_with_request()); + } else { + ZEND_PUTS("?"); + } +} + + +static const char *xdebug_start_upon_error_types4 = { "", "default", "yes", "no" }; + +ZEND_INI_DISP(display_start_upon_error) +{ + char *value; + + if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { + value = ZSTR_VAL(ini_entry->orig_value); + } else if (ini_entry->value) { + value = ZSTR_VAL(ini_entry->value); + } else { + value = NULL; + } + if (value) { + ZEND_PUTS(xdebug_start_upon_error_typesxdebug_lib_get_start_upon_error()); + } else { + ZEND_PUTS("?"); + } +} + + +#if HAVE_XDEBUG_ZLIB +# define USE_COMPRESSION_DEFAULT "1" +#else +# define USE_COMPRESSION_DEFAULT "0" +#endif + +PHP_INI_BEGIN() + /* Library settings */ + STD_PHP_INI_ENTRY("xdebug.mode", "develop", PHP_INI_SYSTEM, OnUpdateString, settings.library.requested_mode, zend_xdebug_globals, xdebug_globals) + PHP_INI_ENTRY_EX( "xdebug.start_with_request", "default", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStartWithRequest, display_start_with_request) + PHP_INI_ENTRY_EX( "xdebug.start_upon_error", "default", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateStartUponError, display_start_upon_error) + STD_PHP_INI_ENTRY("xdebug.output_dir", XDEBUG_TEMP_DIR, PHP_INI_ALL, OnUpdateString, settings.library.output_dir, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.use_compression", USE_COMPRESSION_DEFAULT, PHP_INI_ALL, OnUpdateBool, settings.library.use_compression, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.trigger_value", "", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, settings.library.trigger_value, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.file_link_format", "", PHP_INI_ALL, OnUpdateString, settings.library.file_link_format, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.filename_format", "", PHP_INI_ALL, OnUpdateString, settings.library.filename_format, zend_xdebug_globals, xdebug_globals) + + STD_PHP_INI_ENTRY("xdebug.log", "", PHP_INI_ALL, OnUpdateString, settings.library.log, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.log_level", XLOG_DEFAULT, PHP_INI_ALL, OnUpdateLong, settings.library.log_level, zend_xdebug_globals, xdebug_globals) + + /* Variable display settings */ + STD_PHP_INI_ENTRY("xdebug.var_display_max_children", "128", PHP_INI_ALL, OnUpdateLong, settings.library.display_max_children, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.var_display_max_data", "512", PHP_INI_ALL, OnUpdateLong, settings.library.display_max_data, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.var_display_max_depth", "3", PHP_INI_ALL, OnUpdateLong, settings.library.display_max_depth, zend_xdebug_globals, xdebug_globals) + + /* Base settings */ + STD_PHP_INI_ENTRY("xdebug.max_nesting_level", "256", PHP_INI_ALL, OnUpdateLong, settings.base.max_nesting_level, zend_xdebug_globals, xdebug_globals) + + /* Develop settings */ + STD_PHP_INI_ENTRY("xdebug.cli_color", "0", PHP_INI_ALL, OnUpdateLong, settings.develop.cli_color, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_BOOLEAN("xdebug.force_display_errors", "0", PHP_INI_SYSTEM, OnUpdateBool, settings.develop.force_display_errors, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.force_error_reporting", "0", PHP_INI_SYSTEM, OnUpdateLong, settings.develop.force_error_reporting, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.halt_level", "0", PHP_INI_ALL, OnUpdateLong, settings.develop.halt_level, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.max_stack_frames", "-1", PHP_INI_ALL, OnUpdateLong, settings.develop.max_stack_frames, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_BOOLEAN("xdebug.show_error_trace", "0", PHP_INI_ALL, OnUpdateBool, settings.develop.show_error_trace, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_BOOLEAN("xdebug.show_exception_trace", "0", PHP_INI_ALL, OnUpdateBool, settings.develop.show_ex_trace, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_BOOLEAN("xdebug.show_local_vars", "0", PHP_INI_ALL, OnUpdateBool, settings.develop.show_local_vars, zend_xdebug_globals, xdebug_globals) + + /* Dump superglobals settings */ + PHP_INI_ENTRY("xdebug.dump.COOKIE", NULL, PHP_INI_ALL, OnUpdateCookie) + PHP_INI_ENTRY("xdebug.dump.ENV", NULL, PHP_INI_ALL, OnUpdateEnv) + PHP_INI_ENTRY("xdebug.dump.FILES", NULL, PHP_INI_ALL, OnUpdateFiles) + PHP_INI_ENTRY("xdebug.dump.GET", NULL, PHP_INI_ALL, OnUpdateGet) + PHP_INI_ENTRY("xdebug.dump.POST", NULL, PHP_INI_ALL, OnUpdatePost) + PHP_INI_ENTRY("xdebug.dump.REQUEST", NULL, PHP_INI_ALL, OnUpdateRequest) + PHP_INI_ENTRY("xdebug.dump.SERVER", NULL, PHP_INI_ALL, OnUpdateServer) + PHP_INI_ENTRY("xdebug.dump.SESSION", NULL, PHP_INI_ALL, OnUpdateSession) + STD_PHP_INI_BOOLEAN("xdebug.dump_globals", "1", PHP_INI_ALL, OnUpdateBool, settings.develop.dump_globals, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_BOOLEAN("xdebug.dump_once", "1", PHP_INI_ALL, OnUpdateBool, settings.develop.dump_once, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_BOOLEAN("xdebug.dump_undefined", "0", PHP_INI_ALL, OnUpdateBool, settings.develop.dump_undefined, zend_xdebug_globals, xdebug_globals) + + /* Profiler settings */ + STD_PHP_INI_ENTRY("xdebug.profiler_output_name", "cachegrind.out.%p", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, settings.profiler.profiler_output_name, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_BOOLEAN("xdebug.profiler_append", "0", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateBool, settings.profiler.profiler_append, zend_xdebug_globals, xdebug_globals) + + /* Xdebug Cloud */ + STD_PHP_INI_ENTRY("xdebug.cloud_id", "", PHP_INI_SYSTEM, OnUpdateString, settings.debugger.cloud_id, zend_xdebug_globals, xdebug_globals) + + /* Remote debugger settings */ + STD_PHP_INI_ENTRY("xdebug.client_host", "localhost", PHP_INI_ALL, OnUpdateString, settings.debugger.client_host, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.client_port", "9003", PHP_INI_ALL, OnUpdateLong, settings.debugger.client_port, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_BOOLEAN("xdebug.discover_client_host", "0", PHP_INI_ALL, OnUpdateBool, settings.debugger.discover_client_host, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.client_discovery_header", "HTTP_X_FORWARDED_FOR,REMOTE_ADDR", PHP_INI_ALL, OnUpdateString, settings.debugger.client_discovery_header, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.idekey", "", PHP_INI_ALL, OnUpdateString, settings.debugger.ide_key_setting, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.connect_timeout_ms", "200", PHP_INI_ALL, OnUpdateLong, settings.debugger.connect_timeout_ms, zend_xdebug_globals, xdebug_globals) + + /* Scream support */ + STD_PHP_INI_BOOLEAN("xdebug.scream", "0", PHP_INI_ALL, OnUpdateBool, settings.develop.do_scream, zend_xdebug_globals, xdebug_globals) + + /* GC Stats support */ + STD_PHP_INI_ENTRY("xdebug.gc_stats_output_name", "gcstats.%p", PHP_INI_SYSTEM|PHP_INI_PERDIR, OnUpdateString, settings.gc_stats.output_name, zend_xdebug_globals, xdebug_globals) + + /* Tracing settings */ + STD_PHP_INI_ENTRY("xdebug.trace_output_name", "trace.%c", PHP_INI_ALL, OnUpdateString, settings.tracing.trace_output_name, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.trace_format", "0", PHP_INI_ALL, OnUpdateLong, settings.tracing.trace_format, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_ENTRY("xdebug.trace_options", "0", PHP_INI_ALL, OnUpdateLong, settings.tracing.trace_options, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_BOOLEAN("xdebug.collect_assignments", "0", PHP_INI_ALL, OnUpdateBool, settings.tracing.collect_assignments, zend_xdebug_globals, xdebug_globals) + STD_PHP_INI_BOOLEAN("xdebug.collect_return", "0", PHP_INI_ALL, OnUpdateBool, settings.tracing.collect_return, zend_xdebug_globals, xdebug_globals) + + /* Removed/Changed settings */ + XDEBUG_CHANGED_INI_ENTRY(xdebug.auto_trace) + XDEBUG_REMOVED_INI_ENTRY(xdebug.collect_includes) + XDEBUG_REMOVED_INI_ENTRY(xdebug.collect_params) + XDEBUG_REMOVED_INI_ENTRY(xdebug.collect_vars) + XDEBUG_CHANGED_INI_ENTRY(xdebug.coverage_enable) + XDEBUG_CHANGED_INI_ENTRY(xdebug.default_enable) + XDEBUG_CHANGED_INI_ENTRY(xdebug.gc_stats_enable) + XDEBUG_CHANGED_INI_ENTRY(xdebug.gc_stats_output_dir) + XDEBUG_REMOVED_INI_ENTRY(xdebug.overload_var_dump) + XDEBUG_CHANGED_INI_ENTRY(xdebug.profiler_enable) + XDEBUG_CHANGED_INI_ENTRY(xdebug.profiler_enable_trigger) + XDEBUG_CHANGED_INI_ENTRY(xdebug.profiler_enable_trigger_value) + XDEBUG_CHANGED_INI_ENTRY(xdebug.profiler_output_dir) + XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_autostart) + XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_connect_back) + XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_enable) + XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_host) + XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_log) + XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_log_level) + XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_mode) + XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_port) + XDEBUG_CHANGED_INI_ENTRY(xdebug.remote_timeout) + XDEBUG_REMOVED_INI_ENTRY(xdebug.show_mem_delta) + XDEBUG_CHANGED_INI_ENTRY(xdebug.trace_output_dir) + XDEBUG_CHANGED_INI_ENTRY(xdebug.trace_enable_trigger) + XDEBUG_CHANGED_INI_ENTRY(xdebug.trace_enable_trigger_value) +PHP_INI_END() + +static void xdebug_init_base_globals(xdebug_base_globals_t *xg) +{ + xg->stack = NULL; + xg->in_debug_info = 0; + xg->output_is_tty = OUTPUT_NOT_CHECKED; + xg->in_execution = 0; + xg->in_var_serialisation = 0; + xg->error_reporting_override = 0; + xg->error_reporting_overridden = 0; + + xg->filter_type_code_coverage = XDEBUG_FILTER_NONE; + xg->filter_type_stack = XDEBUG_FILTER_NONE; + xg->filter_type_tracing = XDEBUG_FILTER_NONE; + xg->filters_code_coverage = NULL; + xg->filters_stack = NULL; + xg->filters_tracing = NULL; + + xg->php_version_compile_time = PHP_VERSION; + xg->php_version_run_time = zend_get_module_version("standard"); + + xdebug_nanotime_init(xg); +} + + +static void php_xdebug_init_globals(zend_xdebug_globals *xg) +{ + memset(&xg->globals, 0, sizeof(xg->globals)); + + xdebug_init_library_globals(&xg->globals.library); + xdebug_init_base_globals(&xg->globals.base); + + if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { + xdebug_init_coverage_globals(&xg->globals.coverage); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + xdebug_init_debugger_globals(&xg->globals.debugger); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + xdebug_init_develop_globals(&xg->globals.develop); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + xdebug_init_profiler_globals(&xg->globals.profiler); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { + xdebug_init_gc_stats_globals(&xg->globals.gc_stats); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { + xdebug_init_tracing_globals(&xg->globals.tracing); + } +} + +static void php_xdebug_shutdown_globals(zend_xdebug_globals *xg) +{ + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + xdebug_deinit_develop_globals(&xg->globals.develop); + } +} + + +static void xdebug_env_config(void) +{ + char *config = getenv("XDEBUG_CONFIG"); + xdebug_arg *parts; + int i; + /* + XDEBUG_CONFIG format: + XDEBUG_CONFIG=var=val var=val + */ + if (!config) { + return; + } + + parts = xdebug_arg_ctor(); + xdebug_explode(" ", config, parts, -1); + + for (i = 0; i < parts->c; ++i) { + const char *name = NULL; + char *envvar = parts->argsi; + char *envval = NULL; + char *eq = strchr(envvar, '='); + if (!eq || !*eq) { + continue; + } + *eq = 0; + envval = eq + 1; + if (!*envval) { + continue; + } + + if (strcasecmp(envvar, "discover_client_host") == 0) { + name = "xdebug.discover_client_host"; + } else + if (strcasecmp(envvar, "client_port") == 0) { + name = "xdebug.client_port"; + } else + if (strcasecmp(envvar, "client_host") == 0) { + name = "xdebug.client_host"; + } else + if (strcasecmp(envvar, "cloud_id") == 0) { + name = "xdebug.cloud_id"; + } else + if (strcasecmp(envvar, "idekey") == 0) { + xdebug_debugger_reset_ide_key(envval); + } else + if (strcasecmp(envvar, "output_dir") == 0) { + name = "xdebug.output_dir"; + } else + if (strcasecmp(envvar, "profiler_output_name") == 0) { + name = "xdebug.profiler_output_name"; + } else + if (strcasecmp(envvar, "log") == 0) { + name = "xdebug.log"; + } else + if (strcasecmp(envvar, "log_level") == 0) { + name = "xdebug.log_level"; + } else + if (strcasecmp(envvar, "cli_color") == 0) { + name = "xdebug.cli_color"; + } + + if (name) { + zend_string *ini_name = zend_string_init(name, strlen(name), 0); + zend_string *ini_val = zend_string_init(envval, strlen(envval), 0); + zend_alter_ini_entry(ini_name, ini_val, PHP_INI_SYSTEM, PHP_INI_STAGE_ACTIVATE); + zend_string_release(ini_val); + zend_string_release(ini_name); + } + } + + xdebug_arg_dtor(parts); +} + +int xdebug_is_output_tty(void) +{ + if (XG_BASE(output_is_tty) == OUTPUT_NOT_CHECKED) { +#ifndef PHP_WIN32 + XG_BASE(output_is_tty) = isatty(STDOUT_FILENO); +#else + XG_BASE(output_is_tty) = getenv("ANSICON") != NULL; +#endif + } + return (XG_BASE(output_is_tty)); +} + +PHP_MINIT_FUNCTION(xdebug) +{ + ZEND_INIT_MODULE_GLOBALS(xdebug, php_xdebug_init_globals, php_xdebug_shutdown_globals); + REGISTER_INI_ENTRIES(); + + /* Locking in mode as it currently is */ + if (!xdebug_lib_set_mode(XG(settings.library.requested_mode))) { + xdebug_lib_set_mode("develop"); + } + + if (XDEBUG_MODE_IS_OFF()) { + return SUCCESS; + } + + xdebug_library_minit(); + xdebug_base_minit(INIT_FUNC_ARGS_PASSTHRU); + + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + xdebug_debugger_minit(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + xdebug_develop_minit(INIT_FUNC_ARGS_PASSTHRU); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { + xdebug_gcstats_minit(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + xdebug_profiler_minit(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { + xdebug_tracing_minit(INIT_FUNC_ARGS_PASSTHRU); + } + + /* Overload the "include_or_eval" opcode if the mode is 'debug' or 'trace' */ + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG) || XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { + xdebug_register_with_opcode_multi_handler(ZEND_INCLUDE_OR_EVAL, xdebug_include_or_eval_handler); + } + + /* Coverage must be last, as it has a catch all override for opcodes */ + if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { + xdebug_coverage_minit(INIT_FUNC_ARGS_PASSTHRU); + } + + if (zend_xdebug_initialised == 0) { + zend_error(E_WARNING, "Xdebug MUST be loaded as a Zend extension"); + } + + xdebug_coverage_register_constants(INIT_FUNC_ARGS_PASSTHRU); + xdebug_filter_register_constants(INIT_FUNC_ARGS_PASSTHRU); + xdebug_tracing_register_constants(INIT_FUNC_ARGS_PASSTHRU); + + return SUCCESS; +} + +PHP_MSHUTDOWN_FUNCTION(xdebug) +{ + if (XDEBUG_MODE_IS_OFF()) { +#ifdef ZTS + ts_free_id(xdebug_globals_id); +#endif + return SUCCESS; + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { + xdebug_gcstats_mshutdown(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + xdebug_profiler_mshutdown(); + } + + xdebug_library_mshutdown(); + +#ifdef ZTS + ts_free_id(xdebug_globals_id); +#else + php_xdebug_shutdown_globals(&xdebug_globals); +#endif + + return SUCCESS; +} + +static void xdebug_init_auto_globals(void) +{ + zend_is_auto_global_str((char*) ZEND_STRL("_ENV")); + zend_is_auto_global_str((char*) ZEND_STRL("_GET")); + zend_is_auto_global_str((char*) ZEND_STRL("_POST")); + zend_is_auto_global_str((char*) ZEND_STRL("_COOKIE")); + zend_is_auto_global_str((char*) ZEND_STRL("_REQUEST")); + zend_is_auto_global_str((char*) ZEND_STRL("_FILES")); + zend_is_auto_global_str((char*) ZEND_STRL("_SERVER")); + zend_is_auto_global_str((char*) ZEND_STRL("_SESSION")); +} + + +PHP_RINIT_FUNCTION(xdebug) +{ +#if defined(ZTS) && defined(COMPILE_DL_XDEBUG) + ZEND_TSRMLS_CACHE_UPDATE(); +#endif + + if (XDEBUG_MODE_IS_OFF()) { + return SUCCESS; + } + + xdebug_library_rinit(); + + if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { + xdebug_coverage_rinit(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + xdebug_debugger_rinit(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + xdebug_develop_rinit(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { + xdebug_gcstats_rinit(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + xdebug_profiler_rinit(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { + xdebug_tracing_rinit(); + } + + /* Get xdebug ini entries from the environment also, + this can override the idekey if one is set */ + xdebug_env_config(); + + xdebug_init_auto_globals(); + + /* Only enabled extended info when it is not disabled */ + CG(compiler_options) = CG(compiler_options) | ZEND_COMPILE_EXTENDED_STMT; + + xdebug_base_rinit(); + + return SUCCESS; +} + +ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xdebug) +{ + if (XDEBUG_MODE_IS_OFF()) { + return SUCCESS; + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) { + xdebug_coverage_post_deactivate(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + xdebug_debugger_post_deactivate(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_DEVELOP)) { + xdebug_develop_post_deactivate(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_PROFILING)) { + xdebug_profiler_post_deactivate(); + } + if (XDEBUG_MODE_IS(XDEBUG_MODE_TRACING)) { + xdebug_tracing_post_deactivate(); + } + + xdebug_base_post_deactivate(); + xdebug_library_post_deactivate(); + + return SUCCESS; +} + +PHP_RSHUTDOWN_FUNCTION(xdebug) +{ + if (XDEBUG_MODE_IS_OFF()) { + return SUCCESS; + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_GCSTATS)) { + xdebug_gcstats_rshutdown(); + } + + xdebug_base_rshutdown(); + + return SUCCESS; +} + +PHP_MINFO_FUNCTION(xdebug) +{ + xdebug_print_info(); + + if (zend_xdebug_initialised == 0) { + php_info_print_table_start(); + php_info_print_table_header(1, "XDEBUG NOT LOADED AS ZEND EXTENSION"); + php_info_print_table_end(); + } + + if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)) { + xdebug_debugger_minfo(); + } + + DISPLAY_INI_ENTRIES(); +} + +ZEND_DLEXPORT void xdebug_statement_call(zend_execute_data *frame) +{ + zend_op_array *op_array = &frame->func->op_array; + int lineno; + + if (XDEBUG_MODE_IS_OFF()) { + return; + } + + if (!EG(current_execute_data)) { + return; + } + + lineno = EG(current_execute_data)->opline->lineno; + + xdebug_coverage_count_line_if_active(op_array, op_array->filename, lineno); + xdebug_debugger_statement_call(op_array->filename, lineno); +} + +ZEND_DLEXPORT int xdebug_zend_startup(zend_extension *extension) +{ + xdebug_library_zend_startup(); + xdebug_debugger_zend_startup(); + + zend_xdebug_initialised = 1; + + xdebug_orig_post_startup_cb = zend_post_startup_cb; + zend_post_startup_cb = xdebug_post_startup; + + return zend_startup_module(&xdebug_module_entry); +} + +static int xdebug_post_startup(void) +{ + if (xdebug_orig_post_startup_cb) { + int (*cb)(void) = xdebug_orig_post_startup_cb; + + xdebug_orig_post_startup_cb = NULL; + if (cb() != SUCCESS) { + return FAILURE; + } + } + + xdebug_base_post_startup(); + + return SUCCESS; +} + +ZEND_DLEXPORT void xdebug_zend_shutdown(zend_extension *extension) +{ + xdebug_debugger_zend_shutdown(); + + xdebug_library_zend_shutdown(); +} + +ZEND_DLEXPORT void xdebug_init_oparray(zend_op_array *op_array) +{ + if (XDEBUG_MODE_IS_OFF()) { + return; + } + + xdebug_coverage_init_oparray(op_array); +} + +#ifndef ZEND_EXT_API +#define ZEND_EXT_API ZEND_DLEXPORT +#endif + +ZEND_EXT_API zend_extension_version_info extension_version_info = { ZEND_EXTENSION_API_NO, (char*) ZEND_EXTENSION_BUILD_ID }; + +ZEND_DLEXPORT zend_extension zend_extension_entry = { + (char*) XDEBUG_NAME, + (char*) XDEBUG_VERSION, + (char*) XDEBUG_AUTHOR, + (char*) XDEBUG_URL_FAQ, + (char*) XDEBUG_COPYRIGHT_SHORT, + xdebug_zend_startup, + xdebug_zend_shutdown, + NULL, /* activate_func_t */ + NULL, /* deactivate_func_t */ + NULL, /* message_handler_func_t */ + NULL, /* op_array_handler_func_t */ + xdebug_statement_call, /* statement_handler_func_t */ + NULL, /* fcall_begin_handler_func_t */ + NULL, /* fcall_end_handler_func_t */ + xdebug_init_oparray, /* op_array_ctor_func_t */ + NULL, /* op_array_dtor_func_t */ + STANDARD_ZEND_EXTENSION_PROPERTIES +}; + +#endif
View file
xdebug-3.2.0.tgz/xdebug-3.2.0/xdebug.ini
Added
@@ -0,0 +1,1215 @@ +; This file is generated by the 'xdebug.org:html/docs/convert.php' robot +; for Xdebug 3.2.0 — do not modify by hand + +; ----------------------------------------------------------------------------- +; xdebug.cli_color +; +; Type: integer, Default value: 0 +; +; If this setting is 1, Xdebug will color var_dumps and stack traces output when +; in CLI mode and when the output is a tty. On Windows, the ANSICON 1 tool +; needs to be installed. +; +; 1 http://adoxa.altervista.org/ansicon/ +; +; If the setting is 2, then Xdebug will always color var_dumps and stack trace, +; no matter whether it's connected to a tty or whether ANSICON is installed. In +; this case, you might end up seeing escape codes. +; +; See this article 1 for some more information. +; +; 1 https://derickrethans.nl/cli-color.html +; +; .. note:: +; +; This setting can additionally be configured through the +; ``XDEBUG_CONFIG``environment variable 1. 1 +; /docs/all_settings#XDEBUG_CONFIG +; +; +;xdebug.cli_color = 0 + +; ----------------------------------------------------------------------------- +; xdebug.client_discovery_header +; +; Type: string, Default value: "" +; +; If xdebug.client_discovery_header is configured to be a non-empty string, then +; the value is used as key in the ``$_SERVER`` superglobal array to determine +; which header to use to find the IP address or hostname to use for 'connecting +; back to'. This setting is only used in combination with +; xdebug.discover_client_host and is otherwise ignored. +; +; For example, if xdebug.client_discovery_header is set to +; ``HTTP_FORWARD_HOST``, then Xdebug will check +; ``$_SERVER'HTTP_FORWARD_HOST'`` before the +; ``$_SERVER'HTTP_X_FORWARDED_FOR'`` and ``$_SERVER'REMOTE_ADDR'`` +; variables. +; +; .. warning:: +; +; PHP automatically prepends ``HTTP_``, and converts ``-`` to ``_``, for +; received HTTP header names. The ``THIS-IS-MY-HOST`` HTTP header is +; converted into ``$_SERVER'HTTP_THIS_IS_MY_HOST'``. Therefore, the +; xdebug.client_discovery_header needs to be set to ``HTTP_THIS_IS_MY_HOST`` +; to match this. +; +; +;xdebug.client_discovery_header = "" + +; ----------------------------------------------------------------------------- +; xdebug.client_host +; +; Type: string, Default value: localhost +; +; Configures the IP address or hostname where Xdebug will attempt to connect to +; when initiating a debugging connection. This address should be the address of +; the machine where your IDE or debugging client is listening for incoming +; debugging connections. +; +; On non-Windows platforms, it is also possible to configure a Unix domain +; socket 1 which is supported by only a select view debugging clients. In that +; case, instead of the hostname or IP address, use ``unix:///path/to/sock``. +; +; 1 https://en.wikipedia.org/wiki/Unix_domain_socket +; +; If xdebug.discover_client_host is enabled then Xdebug will only use the value +; of this setting in case Xdebug can not connect to an IDE using the information +; it obtained from HTTP headers. In that case, the value of this setting acts as +; a fallback only. +; +; .. note:: +; +; This setting can additionally be configured through the +; ``XDEBUG_CONFIG``environment variable 1. 1 +; /docs/all_settings#XDEBUG_CONFIG +; +; +;xdebug.client_host = localhost + +; ----------------------------------------------------------------------------- +; xdebug.client_port +; +; Type: integer, Default value: 9003 +; +; The port to which Xdebug tries to connect on the remote host. Port ``9003`` is +; the default for both Xdebug and the Command Line Debug Client. As many clients +; use this port number, it is best to leave this setting unchanged. +; +; .. note:: +; +; This setting can additionally be configured through the +; ``XDEBUG_CONFIG``environment variable 1. 1 +; /docs/all_settings#XDEBUG_CONFIG +; +; +;xdebug.client_port = 9003 + +; ----------------------------------------------------------------------------- +; xdebug.cloud_id +; +; Type: string, Default value: +; +; With this setting you configure Xdebug for use with Xdebug Cloud 1. It needs +; to match one of the tokens from your profile page 2. +; +; 1 https://xdebug.cloud +; 2 https://xdebug.cloud/profile#tokens +; +; Your IDE needs to be configured with the same token for Xdebug and your IDE to +; communicate through Xdebug Cloud. +; +; | In PhpStorm you can find this setting under: +; | File | Settings | PHP | Debug | Xdebug Cloud for Windows and Linux +; | PhpStorm | Preferences | PHP | Debug | Xdebug Cloud for macOS +; +; +;xdebug.cloud_id = + +; ----------------------------------------------------------------------------- +; xdebug.collect_assignments +; +; Type: boolean, Default value: false +; +; This setting, defaulting to 0, controls whether Xdebug should add variable +; assignments to function traces. Assign-by-var ( ``=&``) assignments are +; included too. +; +; +;xdebug.collect_assignments = false + +; ----------------------------------------------------------------------------- +; xdebug.collect_return +; +; Type: boolean, Default value: false +; +; This setting, defaulting to 0, controls whether Xdebug should write the return +; value of function calls to the trace files. +; +; +;xdebug.collect_return = false + +; ----------------------------------------------------------------------------- +; xdebug.connect_timeout_ms +; +; Type: integer, Default value: 200 +; +; The amount of time in milliseconds that Xdebug will wait for on an IDE to +; acknowledge an incoming debugging connection. The default value of 200 ms +; should in most cases be enough. In case you often get dropped debugging +; requests, perhaps because you have a high latency network, or a development +; box far away from your IDE, or have a slow firewall, then you can should +; increase this value. +; +; Please note that increasing this value might mean that your requests seem to +; 'hang' in case Xdebug tries to establish a connection, but your IDE is not +; listening. +; +; +;xdebug.connect_timeout_ms = 200 + +; ----------------------------------------------------------------------------- +; xdebug.discover_client_host +; +; Type: boolean, Default value: false +; +; If enabled, Xdebug will first try to connect to the client that made the HTTP +; request. It checks the ``$_SERVER'HTTP_X_FORWARDED_FOR'`` and +; ``$_SERVER'REMOTE_ADDR'`` variables to find out which hostname or IP address +; to use. +; +; If xdebug.client_discovery_header is configured, then the ``$_SERVER`` +; variable with that configured name will be checked before +; ``HTTP_X_FORWARDED_FOR`` and ``REMOTE_ADDR``. +; +; If Xdebug can not connect to a debugging client as found in one of the HTTP +; headers, it will fall back to the hostname or IP address as configured by the +; xdebug.client_host setting. +; +; This setting does not apply for debugging through the CLI, as the ``$_SERVER`` +; header variables are not available there. +; +; .. note:: +; +; This setting can additionally be configured through the +; ``XDEBUG_CONFIG``environment variable 1. 1 +; /docs/all_settings#XDEBUG_CONFIG +; +; .. warning:: +; +; Please note that there is no filter available, and anybody who can connect +; to the webserver will then be able to start a debugging session, even if +; their address does not match xdebug.client_host. +; +; +;xdebug.discover_client_host = false + +; ----------------------------------------------------------------------------- +; xdebug.dump.* +; +; Type: string, Default value: Empty +; +; * can be any of COOKIE, FILES, GET, POST, REQUEST, SERVER, SESSION. These +; seven settings control which data from the superglobals is shown when an error +; situation occurs. +; +; Each of those php.ini setting can consist of a comma separated list of +; variables from this superglobal to dump, or ``*`` for all of them. Make sure +; you do not add spaces in this setting. +; +; In order to dump the REMOTE_ADDR and the REQUEST_METHOD when an error occurs, +; and all GET parameters, add these settings: +; +; xdebug.dump.SERVER = REMOTE_ADDR,REQUEST_METHOD +; xdebug.dump.GET = * +; +; +;xdebug.dump.* = Empty + +; ----------------------------------------------------------------------------- +; xdebug.dump_globals +; +; Type: boolean, Default value: true +; +; When this setting is set to ``true``, Xdebug adds the values of the super +; globals as configured through the xdebug.dump.* to on-screen stack traces and +; the error log (if enabled). +; +; +;xdebug.dump_globals = true + +; ----------------------------------------------------------------------------- +; xdebug.dump_once +; +; Type: boolean, Default value: true +; +; Controls whether the values of the superglobals should be dumped on all error +; situations (set to 0) or only on the first (set to 1). +; +; +;xdebug.dump_once = true + +; ----------------------------------------------------------------------------- +; xdebug.dump_undefined +; +; Type: boolean, Default value: false +; +; If you want to dump undefined values from the superglobals you should set this +; setting to 1, otherwise leave it set to 0. +; +; +;xdebug.dump_undefined = false + +; ----------------------------------------------------------------------------- +; xdebug.file_link_format +; +; Type: string, Default value: +; +; This setting determines the format of the links that are made in the display +; of stack traces where file names are used. This allows IDEs to set up a +; link-protocol that makes it possible to go directly to a line and file by +; clicking on the filenames that Xdebug shows in stack traces. An example format +; might look like: +; +; myide://%f@%l +; +; The possible format specifiers are: +; +; ========= =============== +; Specifier Meaning +; ========= =============== +; %f the filename +; --------- --------------- +; %l the line number +; ========= =============== +; +; For various IDEs/OSses there are some instructions listed on how to make this +; work: +; +; -------- +; PhpStorm +; -------- +; +; In the configuration file, add the following line, including the single +; quotes. This uses PhpStorm's REST API. +; +; xdebug.file_link_format='javascript: var r = new XMLHttpRequest; r.open("get", "http://localhost:63342/api/file/%f:%l");r.send()' +; +; +; ---------------- +; Firefox on Linux +; ---------------- +; +; - Open +; +; about:config +; +; - Add a new boolean setting "network.protocol-handler.expose.xdebug" and set +; it to "false" +; +; - Add the following into a shell script +; +; ``~/bin/ff-xdebug.sh``: +; +; #! /bin/sh +; +; f=`echo $1 | cut -d @ -f 1 | sed 's/xdebug:\/\///'` +; l=`echo $1 | cut -d @ -f 2` +; +; Add to that one of (depending whether you have komodo, gvim or netbeans): +; +; - komodo $f -l $l +; +; - gvim --remote-tab +$l $f +; +; - netbeans "$f:$l" +; +; - Make the script executable with +; +; chmod +x ~/bin/ff-xdebug.sh +; +; - Set the xdebug.file_link_format setting to +; +; xdebug://%f@%l +; +; -------------------- +; Windows and Netbeans +; -------------------- +; +; - Create the file +; +; ``netbeans.bat`` and save it in your path ( ``C:\Windows`` will work): +; +; @echo off +; setlocal enableextensions enabledelayedexpansion +; set NETBEANS=%1 +; set FILE=%~2 +; set FILE=!FILE:%%5C=\! +; %NETBEANS% --nosplash --console suppress --open "%FILE:~19%" +; nircmd win activate process netbeans.exe +; +; **Note:** Remove the last line if you don't have ``nircmd``. +; +; - Save the following code as +; +; ``netbeans_protocol.reg``: +; +; Windows Registry Editor Version 5.00 +; +; HKEY_CLASSES_ROOT\netbeans +; "URL Protocol"="" +; @="URL:Netbeans Protocol" +; +; HKEY_CLASSES_ROOT\netbeans\DefaultIcon +; @="\"C:\\Program Files\\NetBeans 7.1.1\\bin\\netbeans.exe,1\"" +; +; HKEY_CLASSES_ROOT\netbeans\shell +; +; HKEY_CLASSES_ROOT\netbeans\shell\open +; +; HKEY_CLASSES_ROOT\netbeans\shell\open\command +; @="\"C:\\Windows\\netbeans.bat\" \"C:\\Program Files\\NetBeans 7.1.1\\bin\\netbeans.exe\" \"%1\"" +; +; **Note:** Make sure to change the path to Netbeans (twice), as well as the +; ``netbeans.bat`` batch file if you saved it somewhere else than +; ``C:\Windows\``. +; +; - Double click on the +; +; ``netbeans_protocol.reg`` file to import it into the registry. +; +; - Set the xdebug.file_link_format setting to +; +; xdebug.file_link_format = +; "netbeans://open/?f=%f:%l" +; +; +;xdebug.file_link_format = + +; ----------------------------------------------------------------------------- +; xdebug.filename_format +; +; Type: string, Default value: ...%s%n +; +; This setting determines the format with which Xdebug renders filenames in HTML +; stack traces (default: ``...%s%n``) and location information through the +; overloaded xdebug_var_dump() (default: ``%f``). +; +; The possible format specifiers are listed in this table. The example output is +; rendered according to the full path +; ``/var/www/vendor/mail/transport/mta.php``. +; +; ========= ============================================== =========================================================== +; Specifier Meaning Example Output +; ========= ============================================== =========================================================== +; %a Ancester: Two directory elements and filename mail/transport/mta.php +; --------- ---------------------------------------------- ----------------------------------------------------------- +; %f Full path /var/www/vendor/mail/transport/mta.php +; --------- ---------------------------------------------- ----------------------------------------------------------- +; %n Name: Only the file name mta.php +; --------- ---------------------------------------------- ----------------------------------------------------------- +; %p Parent: One directory element and the filename transport/mta.php +; --------- ---------------------------------------------- ----------------------------------------------------------- +; %s Directory separator / +; on Linux, OSX and other Unix-like systems, ``\`` on Windows +; ========= ============================================== =========================================================== +; +; +;xdebug.filename_format = ...%s%n + +; ----------------------------------------------------------------------------- +; xdebug.force_display_errors +; +; Type: integer, Default value: 0 +; +; If this setting is set to ``1`` then errors will **always** be displayed, no +; matter what the setting of PHP's display_errors 1 is. +; +; 1 https://www.php.net/manual/errorfunc.configuration.php#ini.display-errors +; +; +;xdebug.force_display_errors = 0 + +; ----------------------------------------------------------------------------- +; xdebug.force_error_reporting +; +; Type: integer, Default value: 0 +; +; This setting is a bitmask, like error_reporting 1. This bitmask will be +; logically ORed with the bitmask represented by error_reporting 2 to dermine +; which errors should be displayed. This setting can only be made in php.ini and +; allows you to force certain errors from being shown no matter what an +; application does with ini_set() 3. +; +; 1 https://www.php.net/manual/errorfunc.configuration.php#ini.error-reporting +; 2 https://www.php.net/manual/errorfunc.configuration.php#ini.error-reporting +; 3 https://www.php.net/manual/function.ini-set.php +; +; +;xdebug.force_error_reporting = 0 + +; ----------------------------------------------------------------------------- +; xdebug.gc_stats_output_name +; +; Type: string, Default value: gcstats.%p +; +; This setting determines the name of the file that is used to dump garbage +; collection statistics into. The setting specifies the format with format +; specifiers, very similar to sprintf() and strftime(). There are several format +; specifiers that can be used to format the file name. +; +; See the xdebug.trace_output_name documentation for the supported specifiers. +; +; +;xdebug.gc_stats_output_name = gcstats.%p + +; ----------------------------------------------------------------------------- +; xdebug.halt_level +; +; Type: integer, Default value: 0 +; +; This setting allows you to configure a mask that determines whether, and +; which, notices and/or warnings get converted to errors. You can configure +; notices and warnings that are generated by PHP, and notices and warnings that +; you generate yourself (by means of trigger_error()). For example, to convert +; the warning of strlen() (without arguments) to an error, you would do: +; +; ini_set('xdebug.halt_level', E_WARNING); +; strlen(); +; echo "Hi!\n"; +; +; Which will then result in the showing of the error message, and the abortion +; of the script. ``echo "Hi!\n";`` will not be executed. +; +; The setting is a bit mask, so to convert all notices and warnings into errors +; for all applications, you can set this in php.ini: +; +; xdebug.halt_level=E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE +; +; The bitmask only supports the four level that are mentioned above. +; +; +;xdebug.halt_level = 0 + +; ----------------------------------------------------------------------------- +; xdebug.idekey +; +; Type: string, Default value: *complex* +; +; Controls which IDE Key Xdebug should pass on to the debugging client or proxy. +; The IDE Key is only important for use with the DBGp Proxy Tool, although some +; IDEs are incorrectly picky as to what its value is. +; +; The default is based on the ``DBGP_IDEKEY`` environment setting. If it is not +; present, the default falls back to an empty string. +; +; If this setting is set to a non-empty string, it selects its value over +; ``DBGP_IDEKEY`` environment variable as default value. +; +; The internal IDE Key also gets updated through debugging session management +; and overrides the value of this setting as is explained in the Step Debugging +; documentation. +; +; .. note:: +; +; This setting can additionally be configured through the +; ``XDEBUG_CONFIG``environment variable 1. 1 +; /docs/all_settings#XDEBUG_CONFIG +; +; +;xdebug.idekey = *complex* + +; ----------------------------------------------------------------------------- +; xdebug.log +; +; Type: string, Default value: +; +; Configures Xdebug's log file. +; +; Xdebug will log to this file all file creations issues, Step Debugging +; connection attempts, failures, and debug communication. +; +; Enable this functionality by setting the value to a absolute path. Make sure +; that the system user that PHP runs at (such as ``www-data`` if you are running +; with Apache) can create and write to the file. +; +; The file is opened in append-mode, and will therefore not be overwritten by +; default. There is no concurrency protection available. +; +; The log file will include any attempt that Xdebug makes to connect to an IDE: +; +; 2693358 Log opened at 2020-09-02 07:19:09.616195 +; 2693358 Step Debug INFO: Connecting to configured address/port: localhost:9003. +; 2693358 Step Debug ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port). +; 2693358 Profiler ERR: File '/foo/cachegrind.out.2693358' could not be opened. +; 2693358 Profiler WARN: /foo: No such file or directory +; 2693358 Tracing ERR: File '/foo/trace.1485761369' could not be opened. +; 2693358 Tracing WARN: /foo: No such file or directory +; 2693358 Log closed at 2020-09-02 07:19:09.617510 +; +; It includes the opening time ( ``2020-09-02 07:19:09.616195``), the +; IP/Hostname and port Xdebug is trying to connect to ( ``localhost:9003``), and +; whether it succeeded ( ``Connected to client``). The number in brackets ( +; ``2693358``) is the Process ID. +; +; It includes: +; +; 2693358 +; process ID in brackets +; +; 2020-09-02 07:19:09.616195 +; opening time +; +; For Step Debugging: +; +; INFO: Connecting to configured address/port: localhost:9003. +; ERR: Could not connect to debugging client. Tried: localhost:9003 (through xdebug.client_host/xdebug.client_port). +; +; For Profiling: +; +; ERR: File '/foo/cachegrind.out.2693358' could not be opened. +; WARN: /foo: No such file or directory +; +; For Function Trace: +; +; ERR: File '/foo/trace.1485761369' could not be opened. +; WARN: /foo: No such file or directory +; +; All warnings and errors are described on the Description of errors page, with +; detailed instructions on how to resolve the problem, if possible. All errors +; are always logged through PHP's internal logging mechanism (configured with +; error_log 1 in ``php.ini``). All warnings and errors also show up in the +; diagnostics log that you can view by calling xdebug_info(). +; +; 1 https://www.php.net/manual/en/errorfunc.configuration.php#ini.error-log +; +; --------------------------- +; Step Debugger Communication +; --------------------------- +; +; The debugging log can also log the communication between Xdebug and an IDE. +; This communication is in XML, and starts with the ``<init`` XML element: +; +; <init +; xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" +; fileuri="file:///home/httpd/www.xdebug.org/html/router.php" +; language="PHP" xdebug:language_version="7.4.11-dev" +; protocol_version="1.0" appid="2693358" idekey="XDEBUG_ECLIPSE"> +; <engine version="3.0.0-dev"><!CDATAXdebug></engine> +; <author><!CDATADerick Rethans></author> +; <url><!CDATAhttps://xdebug.org></url> +; <copyright><!CDATACopyright (c) 2002-2020 by Derick Rethans></copyright> +; </init> +; +; The ``fileuri`` attribute lists the entry point of your application, which can +; be useful to compare to ``breakpoint_set`` commands to see if path mappings +; are set-up correctly. +; +; Beyond the ``<init`` element, you will find the configuration of features 1: +; +; 1 /docs/dbgp#feature-names +; +; <- feature_set -i 4 -n extended_properties -v 1 +; -> <response +; xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" +; command="feature_set" transaction_id="4" feature="extended_properties" success="1"> +; </response> +; +; And continuation commands 1: +; +; 1 /docs/dbgp#continuation-commands +; +; <- step_into -i 9 +; -> <response +; xmlns="urn:debugger_protocol_v1" xmlns:xdebug="https://xdebug.org/dbgp/xdebug" +; command="step_into" transaction_id="9" +; status="break" reason="ok"> +; <xdebug:message filename="file:///home/httpd/www.xdebug.org/html/router.php" lineno="3"> +; </xdebug:message> +; </response> +; +; You can read about DBGP - A common debugger protocol specification at its +; dedicated documation page. +; +; The xdebug.log_level setting controls how much information is logged. +; +; .. warning:: +; +; Many Linux distributions now use systemd, which implements **private tmp** +; directories. This means that when PHP is run through a web server or as +; PHP-FPM, the ``/tmp`` directory is prefixed with something akin to: +; +; /tmp/systemd-private-ea3cfa882b4e478993e1994033fc5feb-apache.service-FfWZRg +; +; +; .. note:: +; +; This setting can additionally be configured through the +; ``XDEBUG_CONFIG``environment variable 1. 1 +; /docs/all_settings#XDEBUG_CONFIG +; +; +;xdebug.log = + +; ----------------------------------------------------------------------------- +; xdebug.log_level +; +; Type: integer, Default value: 7 +; +; Configures which logging messages should be added to the log file. +; +; The log file is configured with the xdebug.log setting. +; +; The following levels are supported: +; +; ===== ============= ================================ +; Level Name Example +; ===== ============= ================================ +; 0 Criticals Errors in the configuration +; ----- ------------- -------------------------------- +; 1 Errors Connection errors +; ----- ------------- -------------------------------- +; 3 Warnings Connection warnings +; ----- ------------- -------------------------------- +; 5 Communication Protocol messages +; ----- ------------- -------------------------------- +; **7** Information Information while connecting +; ----- ------------- -------------------------------- +; 10 Debug Breakpoint resolving information +; ===== ============= ================================ +; +; Criticals, errors, and warnings always show up in the diagnostics log that you +; can view by calling xdebug_info(). +; +; Criticals and errors are additionally logged through PHP's internal logging +; mechanism (configured with error_log 1 in ``php.ini``). +; +; 1 https://www.php.net/manual/en/errorfunc.configuration.php#ini.error-log +; +; .. note:: +; +; This setting can additionally be configured through the +; ``XDEBUG_CONFIG``environment variable 1. 1 +; /docs/all_settings#XDEBUG_CONFIG +; +; +;xdebug.log_level = 7 + +; ----------------------------------------------------------------------------- +; xdebug.max_nesting_level +; +; Type: integer, Default value: 256 +; +; Controls the protection mechanism for infinite recursion protection. The value +; of this setting is the maximum level of nested functions that are allowed +; before the script will be aborted. +; +; When the maximum nesting level is reached, an "Error 1" exception is thrown. +; +; 1 https://www.php.net/manual/class.error.php +; +; +;xdebug.max_nesting_level = 256 + +; ----------------------------------------------------------------------------- +; xdebug.max_stack_frames +; +; Type: integer, Default value: -1 +; +; Controls how many stack frames are shown in stack traces, both on the command +; line during PHP error stack traces, as well as in the browser for HTML traces. +; +; +;xdebug.max_stack_frames = -1 + +; ----------------------------------------------------------------------------- +; xdebug.mode +; +; Type: string, Default value: develop +; +; This setting controls which Xdebug features are enabled. +; +; .. note:: +; +; This setting can only be set in ``php.ini`` or files like ``99-xdebug.ini`` +; that are read when a PHP process starts (directly, or through php-fpm), but +; not in ``.htaccess`` and ``.user.ini`` files, which are read per-request. +; +; The following values are accepted: +; +; off +; Nothing is enabled. Xdebug does no work besides checking whether +; functionality is enabled. Use this setting if you want close to 0 +; overhead. +; +; develop +; Enables Development Helpers including the overloaded var_dump(). +; +; coverage +; Enables Code Coverage Analysis to generate code coverage reports, mainly +; in combination with +; +; PHPUnit 1. +; +; debug +; Enables Step Debugging. This can be used to step through your code while +; it is running, and analyse values of variables. +; +; gcstats +; Enables Garbage Collection Statistics to collect statistics about PHP's +; Garbage Collection Mechanism. +; +; profile +; Enables Profiling, with which you can analyse performance bottlenecks with +; tools like +; +; KCacheGrind 2. +; +; trace +; Enables the Function Trace feature, which allows you record every function +; call, including arguments, variable assignment, and return value that is +; made during a request to a file. +; +; You can enable multiple modes at the same time by comma separating their +; identifiers as value to xdebug.mode: ``xdebug.mode=develop,trace``. +; +; 1 https://phpunit.readthedocs.io/en/9.0/code-coverage-analysis.html +; 2 /docs/profiler#kcachegrind +; +; -------------------------------- +; XDEBUG_MODE environment variable +; -------------------------------- +; +; You can also set Xdebug's mode by setting the ``XDEBUG_MODE`` environment +; variable on the command-line; this will take precedence over the xdebug.mode +; setting, but will not change the value of the xdebug.mode setting. +; +; .. warning:: +; +; Some web servers have a configuration option to prevent environment +; variables from being propagated to PHP and Xdebug. For example, PHP-FPM has +; a ``clear_env`` 1 configuration setting that is ``on`` by default, which +; you will need to turn ``off`` if you want to use ``XDEBUG_MODE``. Make sure +; that your web server does not clean the environment, or specifically allows +; the ``XDEBUG_MODE`` environment variable to be passed on. 1 +; https://www.php.net/manual/en/install.fpm.configuration.php#clear-env +; +; +;xdebug.mode = develop + +; ----------------------------------------------------------------------------- +; xdebug.output_dir +; +; Type: string, Default value: /tmp +; +; The directory where Xdebug will write tracing, profiling, and garbage +; collection statistics to. This directory needs to be writable for the system +; user with which PHP is running. +; +; This setting can be changed in ``php.ini``, ``.htaccess`` (and equivalent +; files), and within a PHP file with ``ini_set()``. +; +; In some cases (when profiling, or when xdebug.start_with_request= ``yes`` with +; tracing), Xdebug creates the file before the script runs. In that case, +; changes made through ``ini_set()`` will not be taken into account. +; +; .. note:: +; +; This setting can additionally be configured through the +; ``XDEBUG_CONFIG``environment variable 1. 1 +; /docs/all_settings#XDEBUG_CONFIG +; +; +;xdebug.output_dir = /tmp + +; ----------------------------------------------------------------------------- +; xdebug.profiler_append +; +; Type: integer, Default value: 0 +; +; When this setting is set to 1, profiler files will not be overwritten when a +; new request would map to the same file (depending on the +; xdebug.profiler_output_name setting. Instead the file will be appended to with +; the new profile. +; +; +;xdebug.profiler_append = 0 + +; ----------------------------------------------------------------------------- +; xdebug.profiler_output_name +; +; Type: string, Default value: cachegrind.out.%p +; +; This setting determines the name of the file that is used to dump traces into. +; The setting specifies the format with format specifiers, very similar to +; sprintf() and strftime(). There are several format specifiers that can be used +; to format the file name. +; +; See the xdebug.trace_output_name documentation for the supported specifiers. +; +; .. note:: +; +; This setting can additionally be configured through the +; ``XDEBUG_CONFIG``environment variable 1. 1 +; /docs/all_settings#XDEBUG_CONFIG +; +; +;xdebug.profiler_output_name = cachegrind.out.%p + +; ----------------------------------------------------------------------------- +; xdebug.scream +; +; Type: boolean, Default value: false +; +; If this setting is 1, then Xdebug will disable the @ (shut-up) operator so +; that notices, warnings and errors are no longer hidden. +; +; +;xdebug.scream = false + +; ----------------------------------------------------------------------------- +; xdebug.show_error_trace +; +; Type: integer, Default value: 0 +; +; When this setting is set to 1, Xdebug will show a stack trace whenever an +; Error is raised - even if this Error is actually caught. +; +; +;xdebug.show_error_trace = 0 + +; ----------------------------------------------------------------------------- +; xdebug.show_exception_trace +; +; Type: integer, Default value: 0 +; +; When this setting is set to 1, Xdebug will show a stack trace whenever an +; Exception or Error is raised - even if this Exception or Error is actually +; caught. +; +; Error 'exceptions' were introduced in PHP 7. +; +; +;xdebug.show_exception_trace = 0 + +; ----------------------------------------------------------------------------- +; xdebug.show_local_vars +; +; Type: integer, Default value: 0 +; +; When this setting is set to something != 0 Xdebug's generated stack dumps in +; error situations will also show all variables in the top-most scope. Beware +; that this might generate a lot of information, and is therefore turned off by +; default. +; +; +;xdebug.show_local_vars = 0 + +; ----------------------------------------------------------------------------- +; xdebug.start_upon_error +; +; Type: string, Default value: default +; +; Step Debugging can be activated when a PHP Notice or Warning is emitted, or +; when a Throwable 1 (Exception/Error) is thrown, depending on the value of +; this setting: +; +; 1 https://www.php.net/manual/en/class.throwable.php +; +; yes +; Initialise a debugging session when a PHP Notice or Warning is emitted, or +; when a Throwable is thrown. +; +; no +; default +; Do not start a debugging session upon an error situation. +; +; +;xdebug.start_upon_error = default + +; ----------------------------------------------------------------------------- +; xdebug.start_with_request +; +; Type: string, Default value: default +; +; A Function Trace, Garbage Collection Statistics, Profiling, or Step Debugging +; can be activated at the start of a PHP request. Whether this happens depends +; on the value of this setting: +; +; yes +; The functionality starts when the PHP request starts, and before any PHP +; code is run. +; +; For example xdebug.mode= ``trace`` and xdebug.start_with_request= ``yes`` +; starts a Function Trace for the whole request. +; +; no +; The functionality does not get activated when the request starts. +; +; You can still start a Function Trace with xdebug_start_trace(), Step +; Debugging with xdebug_break(), or Garbage Collection Statistics with +; xdebug_start_gcstats(). +; +; trigger +; The functionality only gets activated when a specific trigger is present +; when the request starts. +; +; The name of the trigger is ``XDEBUG_TRIGGER``, and Xdebug checks for its +; presence in either ``$_ENV`` (environment variable), ``$_GET`` or +; ``$_POST`` variable, or ``$_COOKIE`` (HTTP cookie name). +; +; There is a legacy fallback to a functionality specific trigger name: +; ``XDEBUG_PROFILE`` (for Profiling), ``XDEBUG_TRACE`` (for a Function +; Trace), and ``XDEBUG_SESSION`` (for Step Debugging). +; +; There is another legacy trigger. If you set the ``XDEBUG_CONFIG`` +; environment variable to any value, then Xdebug will also get activated. +; +; Debug session management for Step Debugging is also available through +; ``XDEBUG_SESSION_START``. +; +; With xdebug.trigger_value you can control which specific trigger value +; will activate the trigger. If xdebug.trigger_value is set to an empty +; string, **any** value will be accepted. +; +; default +; The ``default`` value depends on xdebug.mode: +; +; - **debug** : ``trigger`` +; +; - **gcstats** : ``no`` +; +; - **profile** : ``yes`` +; +; - **trace** : ``trigger`` +; +; +;xdebug.start_with_request = default + +; ----------------------------------------------------------------------------- +; xdebug.trace_format +; +; Type: integer, Default value: 0 +; +; The format of the trace file. +; +; ===== ============================================================================== +; Value Description +; ===== ============================================================================== +; 0 shows a human readable indented trace file with: +; +; *time index*, *memory usage*, *memory delta*, *level*, *function name*, +; *function parameters*, *filename* and *line number*. +; ----- ------------------------------------------------------------------------------ +; 1 writes a computer readable format which has two different records. There are +; different records for entering a stack frame, and leaving a stack frame. The +; table below lists the fields in each type of record. Fields are tab separated. +; ----- ------------------------------------------------------------------------------ +; 2 writes a trace formatted in (simple) HTML. +; ===== ============================================================================== +; +; Fields for the computerized format: +; +; =========== ===== ========== ========== ========== ============ ============= ========================================= =================================== ======== =========== ================ ============================================================ +; Record type 1 2 3 4 5 6 7 8 9 10 11 12 - ... +; =========== ===== ========== ========== ========== ============ ============= ========================================= =================================== ======== =========== ================ ============================================================ +; Entry level function # always '0' time index memory usage function name user-defined (1) or internal function (0) name of the include or require file filename line number no. of arguments arguments (as many as specified in field 11) - tab separated +; ----------- ----- ---------- ---------- ---------- ------------ ------------- ----------------------------------------- ----------------------------------- -------- ----------- ---------------- ------------------------------------------------------------ +; Exit level function # always '1' time index memory usage empty +; ----------- ----- ---------- ---------- ---------- ------------ ------------- ----------------------------------------- ----------------------------------- -------- ----------- ---------------- ------------------------------------------------------------ +; Return level function # always 'R' empty return value empty +; =========== ===== ========== ========== ========== ============ ============= ========================================= =================================== ======== =========== ================ ============================================================ +; +; See the introduction for Function Trace for a few examples. +; +; +;xdebug.trace_format = 0 + +; ----------------------------------------------------------------------------- +; xdebug.trace_options +; +; Type: integer, Default value: 0 +; +; When set to '1' the trace files will be appended to, instead of being +; overwritten in subsequent requests. +; +; +;xdebug.trace_options = 0 + +; ----------------------------------------------------------------------------- +; xdebug.trace_output_name +; +; Type: string, Default value: trace.%c +; +; This setting determines the name of the file that is used to dump traces into. +; The setting specifies the format with format specifiers, very similar to +; sprintf() and strftime(). There are several format specifiers that can be used +; to format the file name. The '.xt' extension is always added automatically. +; +; The possible format specifiers are: +; +; ========= ====================================== ================= ==================================================== +; Specifier Meaning Example Format Example Filename +; ========= ====================================== ================= ==================================================== +; %c crc32 of the current working directory trace.%c trace.1258863198.xt +; --------- -------------------------------------- ----------------- ---------------------------------------------------- +; %p pid trace.%p trace.5174.xt +; --------- -------------------------------------- ----------------- ---------------------------------------------------- +; %r random number trace.%r trace.072db0.xt +; --------- -------------------------------------- ----------------- ---------------------------------------------------- +; %s script name 2 cachegrind.out.%s cachegrind.out._home_httpd_html_test_xdebug_test_php +; --------- -------------------------------------- ----------------- ---------------------------------------------------- +; %t timestamp (seconds) trace.%t trace.1179434742.xt +; --------- -------------------------------------- ----------------- ---------------------------------------------------- +; %u timestamp (microseconds) trace.%u trace.1179434749_642382.xt +; --------- -------------------------------------- ----------------- ---------------------------------------------------- +; %H $_SERVER'HTTP_HOST' trace.%H trace.kossu.xt +; --------- -------------------------------------- ----------------- ---------------------------------------------------- +; %R $_SERVER'REQUEST_URI' trace.%R trace._test_xdebug_test_php_var=1_var2=2.xt +; --------- -------------------------------------- ----------------- ---------------------------------------------------- +; %U $_SERVER'UNIQUE_ID' trace.%U trace.TRX4n38AAAEAAB9gBFkAAAAB.xt +; +; 3 +; --------- -------------------------------------- ----------------- ---------------------------------------------------- +; %S session_id (from $_COOKIE if set) trace.%S trace.c70c1ec2375af58f74b390bbdd2a679d.xt +; --------- -------------------------------------- ----------------- ---------------------------------------------------- +; %% literal % trace.%% trace.%%.xt +; ========= ====================================== ================= ==================================================== +; +; 2 This one is only available for trace file names since Xdebug 2.6. +; +; 3 New in version 2.2. This one is set by Apache's mod_unique_id module 1 +; +; 1 http://httpd.apache.org/docs/current/mod/mod_unique_id.html +; +; +;xdebug.trace_output_name = trace.%c + +; ----------------------------------------------------------------------------- +; xdebug.trigger_value +; +; Type: string, Default value: "" +; +; This setting can be used when xdebug.start_with_request is set to ``trigger``, +; which is the default for Step Debugging and Function Trace. +; +; In ``trigger`` mode, Xdebug will only start its functionality when the +; ``XDEBUG_TRIGGER`` is set in the environment, or when the ``XDEBUG_TRIGGER`` +; GET, POST, or COOKIE variable is set. +; +; The legacy names ``XDEBUG_SESSION`` (for Step Debugging), ``XDEBUG_PROFILE`` +; (for Profiling), and ``XDEBUG_TRACE`` (for Function Trace) can also be used +; instead of ``XDEBUG_TRIGGER``. +; +; Normally, Xdebug does not look at which value is actually used. If this +; setting is set to a non-empty string, then Xdebug will only trigger if the +; value matches the value of this setting. +; +; With the following settings: +; +; xdebug.mode=profile +; xdebug.start_with_request=trigger +; xdebug.trigger_value=StartProfileForMe +; +; Xdebug's profiler will only start when either the environment variable +; ``XDEBUG_TRIGGER`` is set to ``StartProfileForMe``, the GET or POST variable +; ``XDEBUG_TRIGGER`` is set to ``StartProfileForMe``, or when the cookie +; ``XDEBUG_TRIGGER`` has the value ``StartProfileForMe``. +; +; From Xdebug 3.1, it is possible to configure multiple values by using a comma +; separated list. In that case, Xdebug will trigger if the supplied value +; matches any of the entries that are configured through this setting: +; +; xdebug.trigger_value=StartDebuggerForMe,StartDebuggerForYou +; +; See also: +; +; xdebug.start_with_request#trigger +; For how the triggering mechanism works, and which environment and server +; variables Xdebug acts on. +; +; +;xdebug.trigger_value = "" + +; ----------------------------------------------------------------------------- +; xdebug.use_compression +; +; Introduced in version 3.1 +; +; Type: boolean, Default value: true +; +; If enabled, the Function Trace and Profiling features will create GZip +; compressed files as output. This reduces diskspace. +; +; If GZip compression is not supported by Xdebug, because it was not compiled +; in, then Xdebug will add a warning to its log and xdebug_info() diagnostics +; section. +; +; It is enabled by default if Xdebug has GZip support, and disable if Xdebug +; does not have GZip support. +; +; The QCacheGrind tool that you can use to visualise profiling information does +; not support reading GZip compressed profile files, whereas KCacheGrind and +; PhpStorm do. If you are a QCacheGrind user, you should set +; xdebug.use_compression to ``false``. +; +; +;xdebug.use_compression = true + +; ----------------------------------------------------------------------------- +; xdebug.var_display_max_children +; +; Type: integer, Default value: 128 +; +; Controls the amount of array children and object's properties are shown when +; variables are displayed with either xdebug_var_dump(), xdebug.show_local_vars +; or when making a Function Trace. +; +; To disable any limitation, use *-1* as value. +; +; This setting does not have any influence on the number of children that is +; send to the client through the Step Debugging feature. +; +; +;xdebug.var_display_max_children = 128 + +; ----------------------------------------------------------------------------- +; xdebug.var_display_max_data +; +; Type: integer, Default value: 512 +; +; Controls the maximum string length that is shown when variables are displayed +; with either xdebug_var_dump(), xdebug.show_local_vars or when making a +; Function Trace. +; +; To disable any limitation, use *-1* as value. +; +; This setting does not have any influence on the number of children that is +; send to the client through the Step Debugging feature. +; +; +;xdebug.var_display_max_data = 512 + +; ----------------------------------------------------------------------------- +; xdebug.var_display_max_depth +; +; Type: integer, Default value: 3 +; +; Controls how many nested levels of array elements and object properties are +; when variables are displayed with either xdebug_var_dump(), +; xdebug.show_local_vars or when making a Function Trace. +; +; The maximum value you can select is *1023*. You can also use *-1* as value to +; select this maximum number. +; +; This setting does not have any influence on the number of children that is +; send to the client through the Step Debugging feature. +; +; .. warning:: +; +; Setting the value to a high number could potentially result in PHP using up +; all the available memory, so use with caution. +; +; +;xdebug.var_display_max_depth = 3 +
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.