summaryrefslogtreecommitdiff
path: root/sapi/phpdbg
diff options
context:
space:
mode:
Diffstat (limited to 'sapi/phpdbg')
-rw-r--r--sapi/phpdbg/.travis.yml1
-rw-r--r--sapi/phpdbg/Makefile.frag2
-rw-r--r--sapi/phpdbg/README.md2
-rw-r--r--sapi/phpdbg/config.m415
-rw-r--r--sapi/phpdbg/config.w3212
-rw-r--r--sapi/phpdbg/create-test.php150
-rw-r--r--sapi/phpdbg/phpdbg.c1601
-rw-r--r--sapi/phpdbg/phpdbg.h280
-rw-r--r--sapi/phpdbg/phpdbg_bp.c1254
-rw-r--r--sapi/phpdbg/phpdbg_bp.h77
-rw-r--r--sapi/phpdbg/phpdbg_break.c14
-rw-r--r--sapi/phpdbg/phpdbg_break.h2
-rw-r--r--sapi/phpdbg/phpdbg_btree.c72
-rw-r--r--sapi/phpdbg/phpdbg_btree.h7
-rw-r--r--sapi/phpdbg/phpdbg_cmd.c496
-rw-r--r--sapi/phpdbg/phpdbg_cmd.h57
-rw-r--r--sapi/phpdbg/phpdbg_eol.c172
-rw-r--r--sapi/phpdbg/phpdbg_eol.h46
-rw-r--r--sapi/phpdbg/phpdbg_frame.c246
-rw-r--r--sapi/phpdbg/phpdbg_frame.h8
-rw-r--r--sapi/phpdbg/phpdbg_help.c149
-rw-r--r--sapi/phpdbg/phpdbg_help.h6
-rw-r--r--sapi/phpdbg/phpdbg_info.c514
-rw-r--r--sapi/phpdbg/phpdbg_info.h4
-rw-r--r--sapi/phpdbg/phpdbg_io.c361
-rw-r--r--sapi/phpdbg/phpdbg_io.h41
-rw-r--r--sapi/phpdbg/phpdbg_lexer.c2029
-rw-r--r--sapi/phpdbg/phpdbg_lexer.h5
-rw-r--r--sapi/phpdbg/phpdbg_lexer.l99
-rw-r--r--sapi/phpdbg/phpdbg_list.c337
-rw-r--r--sapi/phpdbg/phpdbg_list.h24
-rw-r--r--sapi/phpdbg/phpdbg_opcode.c404
-rw-r--r--sapi/phpdbg/phpdbg_opcode.h25
-rw-r--r--sapi/phpdbg/phpdbg_out.c1321
-rw-r--r--sapi/phpdbg/phpdbg_out.h93
-rw-r--r--sapi/phpdbg/phpdbg_parser.c420
-rw-r--r--sapi/phpdbg/phpdbg_parser.h40
-rw-r--r--sapi/phpdbg/phpdbg_parser.y96
-rw-r--r--sapi/phpdbg/phpdbg_print.c354
-rw-r--r--sapi/phpdbg/phpdbg_print.h4
-rw-r--r--sapi/phpdbg/phpdbg_prompt.c1737
-rw-r--r--sapi/phpdbg/phpdbg_prompt.h27
-rw-r--r--sapi/phpdbg/phpdbg_rinit_hook.c105
-rw-r--r--sapi/phpdbg/phpdbg_rinit_hook.h41
-rw-r--r--sapi/phpdbg/phpdbg_set.c168
-rw-r--r--sapi/phpdbg/phpdbg_set.h4
-rw-r--r--sapi/phpdbg/phpdbg_sigio_win32.c112
-rw-r--r--sapi/phpdbg/phpdbg_sigio_win32.h38
-rw-r--r--sapi/phpdbg/phpdbg_sigsafe.c59
-rw-r--r--sapi/phpdbg/phpdbg_sigsafe.h24
-rw-r--r--sapi/phpdbg/phpdbg_utils.c717
-rw-r--r--sapi/phpdbg/phpdbg_utils.h142
-rw-r--r--sapi/phpdbg/phpdbg_wait.c398
-rw-r--r--sapi/phpdbg/phpdbg_wait.h29
-rw-r--r--sapi/phpdbg/phpdbg_watch.c1155
-rw-r--r--sapi/phpdbg/phpdbg_watch.h72
-rw-r--r--sapi/phpdbg/phpdbg_webdata_transfer.c175
-rw-r--r--sapi/phpdbg/phpdbg_webdata_transfer.h27
-rw-r--r--sapi/phpdbg/phpdbg_win.c5
-rw-r--r--sapi/phpdbg/phpdbg_win.h4
-rw-r--r--sapi/phpdbg/tests/basic_run.phpt8
-rw-r--r--sapi/phpdbg/tests/breakpoints_001.phpt33
-rw-r--r--sapi/phpdbg/tests/breakpoints_002.phpt40
-rw-r--r--sapi/phpdbg/tests/breakpoints_003.phpt33
-rw-r--r--sapi/phpdbg/tests/breakpoints_004.phpt41
-rw-r--r--sapi/phpdbg/tests/breakpoints_005.phpt28
-rw-r--r--sapi/phpdbg/tests/breakpoints_006.phpt26
-rw-r--r--sapi/phpdbg/tests/breakpoints_007.phpt25
-rw-r--r--sapi/phpdbg/tests/breakpoints_008.phpt34
-rw-r--r--sapi/phpdbg/tests/clean_001.phpt60
-rw-r--r--sapi/phpdbg/tests/clear_001.phpt44
-rw-r--r--sapi/phpdbg/tests/commands/0001_basic.test8
-rw-r--r--sapi/phpdbg/tests/commands/0002_set.test21
-rw-r--r--sapi/phpdbg/tests/commands/0101_info.test19
-rw-r--r--sapi/phpdbg/tests/commands/0102_print.test28
-rw-r--r--sapi/phpdbg/tests/commands/0103_register.test28
-rw-r--r--sapi/phpdbg/tests/commands/0104_clean.test15
-rw-r--r--sapi/phpdbg/tests/commands/0105_clear.test18
-rw-r--r--sapi/phpdbg/tests/commands/0106_compile.test18
-rw-r--r--sapi/phpdbg/tests/delimiter.phpt7
-rw-r--r--sapi/phpdbg/tests/exceptions_001.phpt46
-rw-r--r--sapi/phpdbg/tests/exceptions_002.phpt51
-rw-r--r--sapi/phpdbg/tests/exceptions_003.phpt54
-rw-r--r--sapi/phpdbg/tests/finish_leave_001.phpt41
-rw-r--r--sapi/phpdbg/tests/generator_run.phpt24
-rw-r--r--sapi/phpdbg/tests/info_001.phpt80
-rw-r--r--sapi/phpdbg/tests/info_002.phpt31
-rw-r--r--sapi/phpdbg/tests/normal_exit.phpt15
-rw-r--r--sapi/phpdbg/tests/phpdbg_break_next.phpt22
-rw-r--r--sapi/phpdbg/tests/phpdbg_oplog_001.phpt58
-rw-r--r--sapi/phpdbg/tests/phpdbg_oplog_002.phpt16
-rw-r--r--sapi/phpdbg/tests/print_001.phpt67
-rw-r--r--sapi/phpdbg/tests/print_002.phpt51
-rw-r--r--sapi/phpdbg/tests/run-tests.php597
-rw-r--r--sapi/phpdbg/tests/run_001.phpt56
-rw-r--r--sapi/phpdbg/tests/stepping_001.phpt65
-rw-r--r--sapi/phpdbg/tests/watch_001.phpt46
-rw-r--r--sapi/phpdbg/xml.md651
98 files changed, 12775 insertions, 5609 deletions
diff --git a/sapi/phpdbg/.travis.yml b/sapi/phpdbg/.travis.yml
index d5b492e7cf..2e777fbe13 100644
--- a/sapi/phpdbg/.travis.yml
+++ b/sapi/phpdbg/.travis.yml
@@ -4,7 +4,6 @@ env:
- PHP="PHP-5.4"
- PHP="PHP-5.5"
- PHP="PHP-5.6"
-- PHP="master"
before_script: ./travis/ci.sh
diff --git a/sapi/phpdbg/Makefile.frag b/sapi/phpdbg/Makefile.frag
index 36c7512d69..e0cdfe25ef 100644
--- a/sapi/phpdbg/Makefile.frag
+++ b/sapi/phpdbg/Makefile.frag
@@ -14,7 +14,7 @@ $(BUILD_BINARY): $(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_PHPDBG_OBJS)
$(builddir)/phpdbg_lexer.lo: $(srcdir)/phpdbg_parser.h
$(srcdir)/phpdbg_lexer.c: $(srcdir)/phpdbg_lexer.l
- @(cd $(top_srcdir); $(RE2C) $(RE2C_FLAGS) --no-generation-date -cbdFo $(srcdir)/phpdbg_lexer.c $(srcdir)/phpdbg_lexer.l)
+ @(cd $(top_srcdir); $(RE2C) $(RE2C_FLAGS) --no-generation-date -cbdFo sapi/phpdbg/phpdbg_lexer.c sapi/phpdbg/phpdbg_lexer.l)
$(srcdir)/phpdbg_parser.h: $(srcdir)/phpdbg_parser.c
$(srcdir)/phpdbg_parser.c: $(srcdir)/phpdbg_parser.y
diff --git a/sapi/phpdbg/README.md b/sapi/phpdbg/README.md
index e7e5c731a8..a2a84deb7b 100644
--- a/sapi/phpdbg/README.md
+++ b/sapi/phpdbg/README.md
@@ -1,7 +1,7 @@
The interactive PHP debugger
============================
-Implemented as a SAPI module, phpdbg can excert complete control over the environment without impacting the functionality or performance of your code.
+Implemented as a SAPI module, phpdbg can exert complete control over the environment without impacting the functionality or performance of your code.
phpdbg aims to be a lightweight, powerful, easy to use debugging platform for PHP 5.4+
diff --git a/sapi/phpdbg/config.m4 b/sapi/phpdbg/config.m4
index d78a439af0..b7d1244669 100644
--- a/sapi/phpdbg/config.m4
+++ b/sapi/phpdbg/config.m4
@@ -3,12 +3,15 @@ dnl $Id$
dnl
PHP_ARG_ENABLE(phpdbg, for phpdbg support,
-[ --enable-phpdbg Build phpdbg], no, no)
+[ --enable-phpdbg Build phpdbg], yes, yes)
+
+PHP_ARG_ENABLE(phpdbg-webhelper, for phpdbg web SAPI support,
+[ --enable-phpdbg-webhelper Build phpdbg web SAPI support], no)
PHP_ARG_ENABLE(phpdbg-debug, for phpdbg debug build,
-[ --enable-phpdbg-debug Build phpdbg in debug mode], no, no)
+[ --enable-phpdbg-debug Build phpdbg in debug mode], no, no)
-if test "$PHP_PHPDBG" != "no"; then
+if test "$BUILD_PHPDBG" == "" && test "$PHP_PHPDBG" != "no"; then
AC_HEADER_TIOCGWINSZ
AC_DEFINE(HAVE_PHPDBG, 1, [ ])
@@ -19,7 +22,7 @@ if test "$PHP_PHPDBG" != "no"; then
fi
PHP_PHPDBG_CFLAGS="-D_GNU_SOURCE"
- PHP_PHPDBG_FILES="phpdbg.c phpdbg_parser.c phpdbg_lexer.c phpdbg_prompt.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c phpdbg_info.c phpdbg_cmd.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_btree.c"
+ PHP_PHPDBG_FILES="phpdbg.c phpdbg_parser.c phpdbg_lexer.c phpdbg_prompt.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c phpdbg_info.c phpdbg_cmd.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_btree.c phpdbg_sigsafe.c phpdbg_wait.c phpdbg_io.c phpdbg_eol.c phpdbg_out.c"
if test "$PHP_READLINE" != "no" -o "$PHP_LIBEDIT" != "no"; then
PHPDBG_EXTRA_LIBS="$PHP_READLINE_LIBS"
@@ -62,6 +65,10 @@ if test "$PHP_PHPDBG" != "no"; then
PHP_SUBST(BUILD_PHPDBG_SHARED)
fi
+if test "$PHP_PHPDBG_WEBHELPER" != "no"; then
+ PHP_NEW_EXTENSION(phpdbg_webhelper, phpdbg_rinit_hook.c phpdbg_webdata_transfer.c, $ext_shared)
+fi
+
dnl ## Local Variables:
dnl ## tab-width: 4
dnl ## End:
diff --git a/sapi/phpdbg/config.w32 b/sapi/phpdbg/config.w32
index 17e15b6ced..8a685d3347 100644
--- a/sapi/phpdbg/config.w32
+++ b/sapi/phpdbg/config.w32
@@ -1,7 +1,12 @@
ARG_ENABLE('phpdbg', 'Build phpdbg', 'no');
ARG_ENABLE('phpdbgs', 'Build phpdbg shared', 'no');
+ARG_ENABLE('phpdbg-webhelper', 'Build phpdbg webhelper', 'yes');
-PHPDBG_SOURCES='phpdbg.c phpdbg_prompt.c phpdbg_cmd.c phpdbg_info.c phpdbg_help.c phpdbg_break.c phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_win.c phpdbg_btree.c phpdbg_parser.c phpdbg_lexer.c';
+PHPDBG_SOURCES='phpdbg.c phpdbg_prompt.c phpdbg_cmd.c phpdbg_info.c phpdbg_help.c phpdbg_break.c ' +
+ 'phpdbg_print.c phpdbg_bp.c phpdbg_opcode.c phpdbg_list.c phpdbg_utils.c ' +
+ 'phpdbg_set.c phpdbg_frame.c phpdbg_watch.c phpdbg_win.c phpdbg_btree.c '+
+ 'phpdbg_parser.c phpdbg_lexer.c phpdbg_sigsafe.c phpdbg_wait.c phpdbg_io.c ' +
+ 'phpdbg_sigio_win32.c phpdbg_eol.c phpdbg_out.c';
PHPDBG_DLL='php' + PHP_VERSION + 'phpdbg.dll';
PHPDBG_EXE='phpdbg.exe';
@@ -9,6 +14,11 @@ if (PHP_PHPDBG == "yes") {
SAPI('phpdbg', PHPDBG_SOURCES, PHPDBG_EXE);
ADD_FLAG("LIBS_PHPDBG", "ws2_32.lib user32.lib");
ADD_FLAG("CFLAGS_PHPDBG", "/D YY_NO_UNISTD_H");
+ ADD_FLAG("LDFLAGS_PHPDBG", "/stack:8388608");
+
+ if (PHP_PHPDBG_WEBHELPER == "yes") {
+ EXTENSION('phpdbg_webhelper', 'phpdbg_rinit_hook.c phpdbg_webdata_transfer.c');
+ }
}
if (PHP_PHPDBGS == "yes") {
diff --git a/sapi/phpdbg/create-test.php b/sapi/phpdbg/create-test.php
new file mode 100644
index 0000000000..5dc1ba48bb
--- /dev/null
+++ b/sapi/phpdbg/create-test.php
@@ -0,0 +1,150 @@
+#!/usr/bin/env php
+<?php
+
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Bob Weinand <bwoebi@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#####
+## This is just a helper for intercepting stdin/stdout and the file and create a half-finished test.
+## The output still may need adapting to match file names etc.
+#####
+
+error_reporting(-1);
+
+$phpdbg = getenv('TEST_PHPDBG_EXECUTABLE') ?: null;
+$pass_options = ' -qbI -n -d "error_reporting=32767" -d "display_errors=1" -d "display_startup_errors=1" -d "log_errors=0"';
+$file = "";
+$cmdargv = "";
+
+if (isset($argc) && $argc > 1) {
+ $post_ddash = false;
+ for ($i = 1; $i < $argc; $i++) {
+ if ($argv[$i][0] == "-" && !$post_ddash) {
+ switch (substr($argv[$i], 1)) {
+ case "p":
+ $phpdbg = $argv[++$i];
+ break;
+ case "n":
+ $pass_options .= " -n";
+ break;
+ case "d":
+ $pass_options .= " -d ".escapeshellarg($argv[++$i]);
+ $ini[] = $argv[$i];
+ break;
+ case "-":
+ $post_ddash = true;
+ break;
+ }
+ } else {
+ $real_argv[] = $argv[$i];
+ }
+ }
+ if (isset($real_argv[0])) {
+ $file = realpath($real_argv[0]);
+ $cmdargv = implode(" ", array_map("escapeshellarg", array_slice($real_argv, 1)));
+ }
+}
+
+$proc = proc_open("$phpdbg $pass_options $file -- $cmdargv", [["pipe", "r"], ["pipe", "w"], ["pipe", "w"]], $pipes);
+if (!$proc) {
+ die("Couldn't start phpdbg\n");
+}
+
+$input = $output = "";
+
+stream_set_blocking(STDIN, false);
+
+do {
+ $r = [$pipes[1], STDIN];
+ $w = $e = null;
+ $n = @stream_select($r, $w, $e, null);
+
+ if ($n > 0) {
+ if ("" != $in = fread(STDIN, 1024)) {
+ $input .= $in;
+ fwrite($pipes[0], $in);
+ continue;
+ }
+
+ if (feof(STDIN)) {
+ die("stdin closed?!\n");
+ }
+
+ if (feof($pipes[1])) {
+ $n = false;
+ } else {
+ $output .= $c = fgetc($pipes[1]);
+ echo $c;
+ }
+ }
+} while ($n !== false);
+
+stream_set_blocking(STDIN, true);
+
+print "\n";
+if (!isset($name)) {
+ print "Specify the test description: ";
+ $desc = trim(fgets(STDIN));
+}
+while (!isset($testfile)) {
+ print "Specify the test file name (leave empty to write to stderr): ";
+ $testfile = trim(fgets(STDIN));
+ if ($testfile != "" && file_exists($testfile)) {
+ print "That file already exists. Type y or yes to overwrite: ";
+ $y = trim(fgets(STDIN));
+ if ($y !== "y" && $y !== "yes") {
+ unset($testfile);
+ }
+ }
+}
+
+$output = str_replace("string(".strlen($file).") \"$file\"", 'string(%d) "%s"', $output);
+$output = str_replace($file, "%s", $output);
+$input = trim($input);
+
+$testdata = <<<TEST
+--TEST--
+$desc
+--PHPDBG--
+$input
+--EXPECTF--
+$output
+TEST;
+
+if (!empty($ini)) {
+ $testdata .= "\n--INI--\n".implode("\n", $ini);
+}
+if ($cmdargv != "") {
+ $testdata .= "\n--ARGS--\n$cmdargv";
+}
+if ($file != "") {
+ $testdata .= "\n--FILE--\n".file_get_contents($file);
+}
+
+if ($testfile == "") {
+ print "\n";
+} elseif (file_put_contents($testfile, $testdata)) {
+ print "Test saved to $testfile\n";
+} else {
+ print "The test could not be saved to $testfile; outputting on stderr now\n";
+ $testfile = "";
+}
+
+if ($testfile == "") {
+ fwrite(STDERR, $testdata);
+}
diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c
index 6fce7f4a42..1fda4b7cb7 100644
--- a/sapi/phpdbg/phpdbg.c
+++ b/sapi/phpdbg/phpdbg.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -21,6 +21,7 @@
#if !defined(ZEND_SIGNALS) || defined(_WIN32)
# include <signal.h>
#endif
+
#include "phpdbg.h"
#include "phpdbg_prompt.h"
#include "phpdbg_bp.h"
@@ -28,7 +29,12 @@
#include "phpdbg_list.h"
#include "phpdbg_utils.h"
#include "phpdbg_set.h"
+#include "phpdbg_io.h"
#include "zend_alloc.h"
+#include "phpdbg_eol.h"
+#include "phpdbg_print.h"
+
+#include "ext/standard/basic_functions.h"
/* {{{ remote console headers */
#ifndef _WIN32
@@ -36,20 +42,35 @@
# include <sys/select.h>
# include <sys/time.h>
# include <sys/types.h>
+# include <sys/poll.h>
# include <netinet/in.h>
# include <unistd.h>
# include <arpa/inet.h>
#endif /* }}} */
+#if defined(PHP_WIN32) && defined(HAVE_OPENSSL)
+# include "openssl/applink.c"
+#endif
+
ZEND_DECLARE_MODULE_GLOBALS(phpdbg);
+int phpdbg_startup_run = 0;
-static zend_bool phpdbg_booted = 0;
+static PHP_INI_MH(OnUpdateEol)
+{
+ if (!new_value) {
+ return FAILURE;
+ }
-#if PHP_VERSION_ID >= 50500
-void (*zend_execute_old)(zend_execute_data *execute_data TSRMLS_DC);
-#else
-void (*zend_execute_old)(zend_op_array *op_array TSRMLS_DC);
-#endif
+ return phpdbg_eol_global_update(ZSTR_VAL(new_value));
+}
+
+PHP_INI_BEGIN()
+ STD_PHP_INI_ENTRY("phpdbg.path", "", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdateString, socket_path, zend_phpdbg_globals, phpdbg_globals)
+ STD_PHP_INI_ENTRY("phpdbg.eol", "2", PHP_INI_ALL, OnUpdateEol, socket_path, zend_phpdbg_globals, phpdbg_globals)
+PHP_INI_END()
+
+static zend_bool phpdbg_booted = 0;
+static zend_bool phpdbg_fully_started = 0;
static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */
{
@@ -60,33 +81,51 @@ static inline void php_phpdbg_globals_ctor(zend_phpdbg_globals *pg) /* {{{ */
pg->colors[1] = NULL;
pg->colors[2] = NULL;
+ pg->lines = phpdbg_get_terminal_height();
pg->exec = NULL;
pg->exec_len = 0;
pg->buffer = NULL;
+ pg->last_was_newline = 1;
pg->ops = NULL;
pg->vmret = 0;
+ pg->in_execution = 0;
pg->bp_count = 0;
pg->flags = PHPDBG_DEFAULT_FLAGS;
pg->oplog = NULL;
- pg->io[PHPDBG_STDIN] = NULL;
- pg->io[PHPDBG_STDOUT] = NULL;
- pg->io[PHPDBG_STDERR] = NULL;
+ memset(pg->io, 0, sizeof(pg->io));
pg->frame.num = 0;
+ pg->sapi_name_ptr = NULL;
+ pg->socket_fd = -1;
+ pg->socket_server_fd = -1;
+ pg->unclean_eval = 0;
+
+ pg->req_id = 0;
+ pg->err_buf.active = 0;
+ pg->err_buf.type = 0;
+
+ pg->input_buflen = 0;
+ pg->sigsafe_mem.mem = NULL;
+ pg->sigsegv_bailout = NULL;
+
+ pg->oplog_list = NULL;
+
+#ifdef PHP_WIN32
+ pg->sigio_watcher_thread = INVALID_HANDLE_VALUE;
+ memset(&pg->swd, 0, sizeof(struct win32_sigio_watcher_data));
+#endif
+
+ pg->eol = PHPDBG_EOL_LF;
} /* }}} */
static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */
{
ZEND_INIT_MODULE_GLOBALS(phpdbg, php_phpdbg_globals_ctor, NULL);
-#if PHP_VERSION_ID >= 50500
- zend_execute_old = zend_execute_ex;
+ REGISTER_INI_ENTRIES();
+
zend_execute_ex = phpdbg_execute_ex;
-#else
- zend_execute_old = zend_execute;
- zend_execute = phpdbg_execute_ex;
-#endif
REGISTER_STRINGL_CONSTANT("PHPDBG_VERSION", PHPDBG_VERSION, sizeof(PHPDBG_VERSION)-1, CONST_CS|CONST_PERSISTENT);
-
+
REGISTER_LONG_CONSTANT("PHPDBG_FILE", FILE_PARAM, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PHPDBG_METHOD", METHOD_PARAM, CONST_CS|CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("PHPDBG_LINENO", NUMERIC_PARAM, CONST_CS|CONST_PERSISTENT);
@@ -99,61 +138,63 @@ static PHP_MINIT_FUNCTION(phpdbg) /* {{{ */
return SUCCESS;
} /* }}} */
-static void php_phpdbg_destroy_bp_file(void *brake) /* {{{ */
+static void php_phpdbg_destroy_bp_file(zval *brake) /* {{{ */
{
- zend_hash_destroy((HashTable*)brake);
+ zend_hash_destroy(Z_ARRVAL_P(brake));
+ efree(Z_ARRVAL_P(brake));
} /* }}} */
-static void php_phpdbg_destroy_bp_symbol(void *brake) /* {{{ */
+static void php_phpdbg_destroy_bp_symbol(zval *brake) /* {{{ */
{
- efree((char*)((phpdbg_breaksymbol_t*)brake)->symbol);
+ efree((char *) ((phpdbg_breaksymbol_t *) Z_PTR_P(brake))->symbol);
+ efree(Z_PTR_P(brake));
} /* }}} */
-static void php_phpdbg_destroy_bp_opcode(void *brake) /* {{{ */
+static void php_phpdbg_destroy_bp_opcode(zval *brake) /* {{{ */
{
- efree((char*)((phpdbg_breakop_t*)brake)->name);
+ efree((char *) ((phpdbg_breakop_t *) Z_PTR_P(brake))->name);
+ efree(Z_PTR_P(brake));
} /* }}} */
-
-static void php_phpdbg_destroy_bp_methods(void *brake) /* {{{ */
+static void php_phpdbg_destroy_bp_opline(zval *brake) /* {{{ */
{
- zend_hash_destroy((HashTable*)brake);
+ efree(Z_PTR_P(brake));
} /* }}} */
-static void php_phpdbg_destroy_bp_condition(void *data) /* {{{ */
+static void php_phpdbg_destroy_bp_methods(zval *brake) /* {{{ */
{
- phpdbg_breakcond_t *brake = (phpdbg_breakcond_t*) data;
+ zend_hash_destroy(Z_ARRVAL_P(brake));
+ efree(Z_ARRVAL_P(brake));
+} /* }}} */
- if (brake) {
- if (brake->ops) {
- TSRMLS_FETCH();
+static void php_phpdbg_destroy_bp_condition(zval *data) /* {{{ */
+{
+ phpdbg_breakcond_t *brake = (phpdbg_breakcond_t *) Z_PTR_P(data);
- destroy_op_array(
- brake->ops TSRMLS_CC);
- efree(brake->ops);
- }
- efree((char*)brake->code);
+ if (brake->ops) {
+ destroy_op_array(brake->ops);
+ efree(brake->ops);
}
+ efree((char*) brake->code);
+ efree(brake);
} /* }}} */
-static void php_phpdbg_destroy_registered(void *data) /* {{{ */
+static void php_phpdbg_destroy_registered(zval *data) /* {{{ */
{
- zend_function *function = (zend_function*) data;
- TSRMLS_FETCH();
-
- destroy_zend_function(
- function TSRMLS_CC);
+ zend_function *function = (zend_function *) Z_PTR_P(data);
+ destroy_zend_function(function);
} /* }}} */
static PHP_RINIT_FUNCTION(phpdbg) /* {{{ */
{
- zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], 8, NULL, php_phpdbg_destroy_bp_file, 0);
+ zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], 8, NULL, php_phpdbg_destroy_bp_file, 0);
+ zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], 8, NULL, php_phpdbg_destroy_bp_file, 0);
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], 8, NULL, php_phpdbg_destroy_bp_symbol, 0);
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], 8, NULL, php_phpdbg_destroy_bp_methods, 0);
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], 8, NULL, php_phpdbg_destroy_bp_methods, 0);
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], 8, NULL, php_phpdbg_destroy_bp_methods, 0);
- zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], 8, NULL, NULL, 0);
+ zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], 8, NULL, php_phpdbg_destroy_bp_opline, 0);
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], 8, NULL, php_phpdbg_destroy_bp_opcode, 0);
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], 8, NULL, php_phpdbg_destroy_bp_methods, 0);
zend_hash_init(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], 8, NULL, php_phpdbg_destroy_bp_condition, 0);
@@ -168,6 +209,7 @@ static PHP_RINIT_FUNCTION(phpdbg) /* {{{ */
static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
{
zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]);
+ zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING]);
zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]);
zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE]);
zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE]);
@@ -177,43 +219,45 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]);
zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_COND]);
zend_hash_destroy(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP]);
+ zend_hash_destroy(&PHPDBG_G(file_sources));
zend_hash_destroy(&PHPDBG_G(seek));
zend_hash_destroy(&PHPDBG_G(registered));
zend_hash_destroy(&PHPDBG_G(watchpoints));
zend_llist_destroy(&PHPDBG_G(watchlist_mem));
if (PHPDBG_G(buffer)) {
- efree(PHPDBG_G(buffer));
+ free(PHPDBG_G(buffer));
PHPDBG_G(buffer) = NULL;
}
-
+
if (PHPDBG_G(exec)) {
efree(PHPDBG_G(exec));
PHPDBG_G(exec) = NULL;
}
- if (PHPDBG_G(prompt)[0]) {
- free(PHPDBG_G(prompt)[0]);
- }
- if (PHPDBG_G(prompt)[1]) {
- free(PHPDBG_G(prompt)[1]);
- }
-
- PHPDBG_G(prompt)[0] = NULL;
- PHPDBG_G(prompt)[1] = NULL;
-
if (PHPDBG_G(oplog)) {
- fclose(
- PHPDBG_G(oplog));
+ fclose(PHPDBG_G(oplog));
PHPDBG_G(oplog) = NULL;
}
if (PHPDBG_G(ops)) {
- destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
+ destroy_op_array(PHPDBG_G(ops));
efree(PHPDBG_G(ops));
PHPDBG_G(ops) = NULL;
}
+ if (PHPDBG_G(oplog_list)) {
+ phpdbg_oplog_list *cur = PHPDBG_G(oplog_list);
+ do {
+ phpdbg_oplog_list *prev = cur->prev;
+ efree(cur);
+ cur = prev;
+ } while (cur != NULL);
+
+ zend_arena_destroy(PHPDBG_G(oplog_arena));
+ PHPDBG_G(oplog_list) = NULL;
+ }
+
return SUCCESS;
} /* }}} */
@@ -224,99 +268,97 @@ static PHP_RSHUTDOWN_FUNCTION(phpdbg) /* {{{ */
If the request to set the context fails, boolean false is returned, and an E_WARNING raised */
static PHP_FUNCTION(phpdbg_exec)
{
- char *exec = NULL;
- int exec_len = 0;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &exec, &exec_len) == FAILURE) {
+ zend_string *exec;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "S", &exec) == FAILURE) {
return;
}
{
- struct stat sb;
+ zend_stat_t sb;
zend_bool result = 1;
- if (VCWD_STAT(exec, &sb) != FAILURE) {
+ if (VCWD_STAT(ZSTR_VAL(exec), &sb) != FAILURE) {
if (sb.st_mode & (S_IFREG|S_IFLNK)) {
if (PHPDBG_G(exec)) {
- ZVAL_STRINGL(return_value, PHPDBG_G(exec), PHPDBG_G(exec_len), 1);
+ ZVAL_STRINGL(return_value, PHPDBG_G(exec), PHPDBG_G(exec_len));
efree(PHPDBG_G(exec));
result = 0;
}
- PHPDBG_G(exec) = estrndup(exec, exec_len);
- PHPDBG_G(exec_len) = exec_len;
+ PHPDBG_G(exec) = estrndup(ZSTR_VAL(exec), ZSTR_LEN(exec));
+ PHPDBG_G(exec_len) = ZSTR_LEN(exec);
- if (result)
- ZVAL_BOOL(return_value, 1);
+ if (result) {
+ ZVAL_TRUE(return_value);
+ }
} else {
- zend_error(
- E_WARNING, "Failed to set execution context (%s), not a regular file or symlink", exec);
- ZVAL_BOOL(return_value, 0);
+ zend_error(E_WARNING, "Failed to set execution context (%s), not a regular file or symlink", ZSTR_VAL(exec));
+ ZVAL_FALSE(return_value);
}
} else {
- zend_error(
- E_WARNING, "Failed to set execution context (%s) the file does not exist", exec);
+ zend_error(E_WARNING, "Failed to set execution context (%s) the file does not exist", ZSTR_VAL(exec));
- ZVAL_BOOL(return_value, 0);
+ ZVAL_FALSE(return_value);
}
}
} /* }}} */
-/* {{{ proto void phpdbg_break_next()
+/* {{{ proto void phpdbg_break()
instructs phpdbg to insert a breakpoint at the next opcode */
static PHP_FUNCTION(phpdbg_break_next)
{
- if (zend_parse_parameters_none() != SUCCESS) {
- return;
- } else if (EG(current_execute_data) && EG(active_op_array)) {
- zend_ulong opline_num = (EG(current_execute_data)->opline -
- EG(active_op_array)->opcodes);
+ zend_execute_data *ex = EG(current_execute_data);
- phpdbg_set_breakpoint_opline_ex(
- &EG(active_op_array)->opcodes[opline_num+1] TSRMLS_CC);
+ while (ex && ex->func && !ZEND_USER_CODE(ex->func->type)) {
+ ex = ex->prev_execute_data;
}
+
+ if (zend_parse_parameters_none() == FAILURE || !ex) {
+ return;
+ }
+
+ phpdbg_set_breakpoint_opline_ex((phpdbg_opline_ptr_t) ex->opline + 1);
} /* }}} */
/* {{{ proto void phpdbg_break_file(string file, integer line) */
static PHP_FUNCTION(phpdbg_break_file)
{
- char *file = NULL;
- int flen = 0;
- long line;
-
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl", &file, &flen, &line) == FAILURE) {
- return;
- }
-
- phpdbg_set_breakpoint_file(file, line TSRMLS_CC);
+ char *file;
+ size_t flen;
+ zend_long line;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl", &file, &flen, &line) == FAILURE) {
+ return;
+ }
+
+ phpdbg_set_breakpoint_file(file, line);
} /* }}} */
/* {{{ proto void phpdbg_break_method(string class, string method) */
static PHP_FUNCTION(phpdbg_break_method)
{
- char *class = NULL,
- *method = NULL;
- int clen = 0,
- mlen = 0;
+ char *class = NULL, *method = NULL;
+ size_t clen = 0, mlen = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss", &class, &clen, &method, &mlen) == FAILURE) {
- return;
- }
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &class, &clen, &method, &mlen) == FAILURE) {
+ return;
+ }
- phpdbg_set_breakpoint_method(class, method TSRMLS_CC);
+ phpdbg_set_breakpoint_method(class, method);
} /* }}} */
/* {{{ proto void phpdbg_break_function(string function) */
static PHP_FUNCTION(phpdbg_break_function)
{
- char *function = NULL;
- int function_len;
+ char *function = NULL;
+ size_t function_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &function, &function_len) == FAILURE) {
- return;
- }
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &function, &function_len) == FAILURE) {
+ return;
+ }
- phpdbg_set_breakpoint_symbol(function, function_len TSRMLS_CC);
+ phpdbg_set_breakpoint_symbol(function, function_len);
} /* }}} */
/* {{{ proto void phpdbg_clear(void)
@@ -324,6 +366,7 @@ static PHP_FUNCTION(phpdbg_break_function)
static PHP_FUNCTION(phpdbg_clear)
{
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]);
+ zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING]);
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]);
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE]);
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE]);
@@ -336,11 +379,11 @@ static PHP_FUNCTION(phpdbg_clear)
/* {{{ proto void phpdbg_color(integer element, string color) */
static PHP_FUNCTION(phpdbg_color)
{
- long element = 0L;
- char *color = NULL;
- int color_len = 0;
+ zend_long element;
+ char *color;
+ size_t color_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &element, &color, &color_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ls", &element, &color, &color_len) == FAILURE) {
return;
}
@@ -348,7 +391,7 @@ static PHP_FUNCTION(phpdbg_color)
case PHPDBG_COLOR_NOTICE:
case PHPDBG_COLOR_ERROR:
case PHPDBG_COLOR_PROMPT:
- phpdbg_set_color_ex(element, color, color_len TSRMLS_CC);
+ phpdbg_set_color_ex(element, color, color_len);
break;
default: zend_error(E_ERROR, "phpdbg detected an incorrect color constant");
@@ -359,30 +402,299 @@ static PHP_FUNCTION(phpdbg_color)
static PHP_FUNCTION(phpdbg_prompt)
{
char *prompt = NULL;
- int prompt_len = 0;
+ size_t prompt_len = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &prompt, &prompt_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &prompt, &prompt_len) == FAILURE) {
return;
}
- phpdbg_set_prompt(prompt TSRMLS_CC);
+ phpdbg_set_prompt(prompt);
} /* }}} */
+/* {{{ proto void phpdbg_start_oplog() */
+static PHP_FUNCTION(phpdbg_start_oplog)
+{
+ phpdbg_oplog_list *prev;
+
+ if (zend_parse_parameters_none() == FAILURE) {
+ return;
+ }
+
+ prev = PHPDBG_G(oplog_list);
+
+ if (!prev) {
+ PHPDBG_G(oplog_arena) = zend_arena_create(64 * 1024);
+
+ PHPDBG_G(oplog_cur) = ((phpdbg_oplog_entry *) zend_arena_alloc(&PHPDBG_G(oplog_arena), sizeof(phpdbg_oplog_entry))) + 1;
+ PHPDBG_G(oplog_cur)->next = NULL;
+ }
+
+ PHPDBG_G(oplog_list) = emalloc(sizeof(phpdbg_oplog_list));
+ PHPDBG_G(oplog_list)->prev = prev;
+ PHPDBG_G(oplog_list)->start = PHPDBG_G(oplog_cur);
+}
+
+static void phpdbg_oplog_fill_executable(zend_op_array *op_array, HashTable *insert_ht, zend_bool by_opcode) {
+ /* ignore RECV_* opcodes */
+ zend_op *cur = op_array->opcodes + op_array->num_args + !!(op_array->fn_flags & ZEND_ACC_VARIADIC);
+ zend_op *end = op_array->opcodes + op_array->last;
+
+ zend_long insert_idx;
+ zval zero;
+ ZVAL_LONG(&zero, 0);
+
+ /* ignore autogenerated return (well, not too precise with finally branches, but that's okay) */
+ if (op_array->last >= 1 && (((end - 1)->opcode == ZEND_RETURN || (end - 1)->opcode == ZEND_RETURN_BY_REF || (end - 1)->opcode == ZEND_GENERATOR_RETURN)
+ && ((op_array->last > 1 && ((end - 2)->opcode == ZEND_RETURN || (end - 2)->opcode == ZEND_RETURN_BY_REF || (end - 2)->opcode == ZEND_GENERATOR_RETURN || (end - 2)->opcode == ZEND_THROW))
+ || op_array->function_name == NULL || (end - 1)->extended_value == -1))) {
+ end--;
+ }
+
+ for (; cur < end; cur++) {
+ if (cur->opcode == ZEND_NOP || cur->opcode == ZEND_OP_DATA || cur->opcode == ZEND_FE_FREE || cur->opcode == ZEND_FREE || cur->opcode == ZEND_ASSERT_CHECK || cur->opcode == ZEND_VERIFY_RETURN_TYPE
+ || cur->opcode == ZEND_DECLARE_CONST || cur->opcode == ZEND_DECLARE_CLASS || cur->opcode == ZEND_DECLARE_INHERITED_CLASS || cur->opcode == ZEND_DECLARE_FUNCTION
+ || cur->opcode == ZEND_DECLARE_INHERITED_CLASS_DELAYED || cur->opcode == ZEND_VERIFY_ABSTRACT_CLASS || cur->opcode == ZEND_ADD_TRAIT || cur->opcode == ZEND_BIND_TRAITS
+ || cur->opcode == ZEND_DECLARE_ANON_CLASS || cur->opcode == ZEND_DECLARE_ANON_INHERITED_CLASS || cur->opcode == ZEND_FAST_RET || cur->opcode == ZEND_TICKS
+ || cur->opcode == ZEND_EXT_STMT || cur->opcode == ZEND_EXT_FCALL_BEGIN || cur->opcode == ZEND_EXT_FCALL_END || cur->opcode == ZEND_EXT_NOP || cur->opcode == ZEND_BIND_GLOBAL) {
+ continue;
+ }
+
+ if (by_opcode) {
+ insert_idx = cur - op_array->opcodes;
+ } else {
+ insert_idx = cur->lineno;
+ }
+
+ if (cur->opcode == ZEND_NEW && (cur + 1)->opcode == ZEND_DO_FCALL) {
+ cur++;
+ }
+
+ zend_hash_index_update(insert_ht, insert_idx, &zero);
+ }
+}
+
+static inline HashTable* phpdbg_add_empty_array(HashTable *ht, zend_string *name) {
+ zval *ht_zv = zend_hash_find(ht, name);
+ if (!ht_zv) {
+ zval zv;
+ array_init(&zv);
+ ht_zv = zend_hash_add_new(ht, name, &zv);
+ }
+ return Z_ARR_P(ht_zv);
+}
+
+/* {{{ proto void phpdbg_end_oplog() */
+static PHP_FUNCTION(phpdbg_get_executable)
+{
+ HashTable *options = NULL;
+ zval *option_buffer;
+ zend_bool by_function = 0;
+ zend_bool by_opcode = 0;
+ HashTable *insert_ht;
+
+ zend_function *func;
+ zend_class_entry *ce;
+ zend_string *name;
+ HashTable *files = &PHPDBG_G(file_sources);
+ HashTable files_tmp;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|H", &options) == FAILURE) {
+ return;
+ }
+
+ if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("functions")))) {
+ by_function = zend_is_true(option_buffer);
+ }
+
+ if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("opcodes")))) {
+ if (by_function) {
+ by_opcode = zend_is_true(option_buffer);
+ }
+ }
+
+ if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("files")))) {
+ ZVAL_DEREF(option_buffer);
+ if (Z_TYPE_P(option_buffer) == IS_ARRAY && zend_hash_num_elements(Z_ARR_P(option_buffer)) > 0) {
+ zval *filename;
+
+ files = &files_tmp;
+ zend_hash_init(files, 0, NULL, NULL, 0);
+
+ ZEND_HASH_FOREACH_VAL(Z_ARR_P(option_buffer), filename) {
+ zend_hash_add_empty_element(files, zval_get_string(filename));
+ } ZEND_HASH_FOREACH_END();
+ } else {
+ GC_REFCOUNT(files)++;
+ }
+ } else {
+ GC_REFCOUNT(files)++;
+ }
+
+ array_init(return_value);
+
+ ZEND_HASH_FOREACH_STR_KEY_PTR(EG(function_table), name, func) {
+ if (func->type == ZEND_USER_FUNCTION) {
+ if (zend_hash_exists(files, func->op_array.filename)) {
+ insert_ht = phpdbg_add_empty_array(Z_ARR_P(return_value), func->op_array.filename);
+
+ if (by_function) {
+ insert_ht = phpdbg_add_empty_array(insert_ht, name);
+ }
+
+ phpdbg_oplog_fill_executable(&func->op_array, insert_ht, by_opcode);
+ }
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), name, ce) {
+ if (ce->type == ZEND_USER_CLASS) {
+ if (zend_hash_exists(files, ce->info.user.filename)) {
+ ZEND_HASH_FOREACH_PTR(&ce->function_table, func) {
+ if (func->type == ZEND_USER_FUNCTION) {
+ insert_ht = phpdbg_add_empty_array(Z_ARR_P(return_value), func->op_array.filename);
+
+ if (by_function) {
+ zend_string *fn_name = strpprintf(ZSTR_LEN(name) + ZSTR_LEN(func->op_array.function_name) + 2, "%.*s::%.*s", ZSTR_LEN(name), ZSTR_VAL(name), ZSTR_LEN(func->op_array.function_name), ZSTR_VAL(func->op_array.function_name));
+ insert_ht = phpdbg_add_empty_array(insert_ht, fn_name);
+ zend_string_release(fn_name);
+ }
+
+ phpdbg_oplog_fill_executable(&func->op_array, insert_ht, by_opcode);
+ }
+ } ZEND_HASH_FOREACH_END();
+ }
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ ZEND_HASH_FOREACH_STR_KEY(files, name) {
+ phpdbg_file_source *source = zend_hash_find_ptr(&PHPDBG_G(file_sources), name);
+ if (source) {
+ phpdbg_oplog_fill_executable(
+ &source->op_array,
+ phpdbg_add_empty_array(Z_ARR_P(return_value), source->op_array.filename),
+ by_opcode);
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ if (!--GC_REFCOUNT(files)) {
+ zend_hash_destroy(files);
+ }
+}
+
+/* {{{ proto void phpdbg_end_oplog() */
+static PHP_FUNCTION(phpdbg_end_oplog)
+{
+ phpdbg_oplog_entry *cur;
+ phpdbg_oplog_list *prev;
+
+ HashTable *options = NULL;
+ zval *option_buffer;
+ zend_bool by_function = 0;
+ zend_bool by_opcode = 0;
+
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "|H", &options) == FAILURE) {
+ return;
+ }
+
+ if (!PHPDBG_G(oplog_list)) {
+ zend_error(E_WARNING, "Can not end an oplog without starting it");
+ return;
+ }
+
+ cur = PHPDBG_G(oplog_list)->start;
+ prev = PHPDBG_G(oplog_list)->prev;
+
+ efree(PHPDBG_G(oplog_list));
+ PHPDBG_G(oplog_list) = prev;
+
+ if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("functions")))) {
+ by_function = zend_is_true(option_buffer);
+ }
+
+ if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("opcodes")))) {
+ if (by_function) {
+ by_opcode = zend_is_true(option_buffer);
+ }
+ }
+
+ array_init(return_value);
+
+ {
+ zend_string *last_file = NULL;
+ HashTable *file_ht;
+ zend_string *last_function = (void *)~(uintptr_t)0;
+ zend_class_entry *last_scope = NULL;
+
+ HashTable *insert_ht;
+ zend_long insert_idx;
+
+ do {
+ zval zero;
+ ZVAL_LONG(&zero, 0);
+
+ if (cur->filename != last_file) {
+ last_file = cur->filename;
+ file_ht = insert_ht = phpdbg_add_empty_array(Z_ARR_P(return_value), last_file);
+ }
+
+ if (by_function) {
+ if (cur->function_name == NULL) {
+ if (last_function != NULL) {
+ insert_ht = file_ht;
+ }
+ last_function = NULL;
+ } else if (cur->function_name != last_function || cur->scope != last_scope) {
+ zend_string *fn_name;
+ last_function = cur->function_name;
+ last_scope = cur->scope;
+ if (last_scope == NULL) {
+ fn_name = zend_string_copy(last_function);
+ } else {
+ fn_name = strpprintf(ZSTR_LEN(last_function) + ZSTR_LEN(last_scope->name) + 2, "%.*s::%.*s", ZSTR_LEN(last_scope->name), ZSTR_VAL(last_scope->name), ZSTR_LEN(last_function), ZSTR_VAL(last_function));
+ }
+ insert_ht = phpdbg_add_empty_array(Z_ARR_P(return_value), fn_name);
+ zend_string_release(fn_name);
+ }
+ }
+
+ if (by_opcode) {
+ insert_idx = cur->op - cur->opcodes;
+ } else {
+ insert_idx = cur->op->lineno;
+ }
+
+ {
+ zval *num = zend_hash_index_find(insert_ht, insert_idx);
+ if (!num) {
+ num = zend_hash_index_add_new(insert_ht, insert_idx, &zero);
+ }
+ Z_LVAL_P(num)++;
+ }
+
+ cur = cur->next;
+ } while (cur != NULL);
+ }
+
+ if (!prev) {
+ zend_arena_destroy(PHPDBG_G(oplog_arena));
+ }
+}
+
ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_next_arginfo, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_file_arginfo, 0, 0, 2)
- ZEND_ARG_INFO(0, file)
- ZEND_ARG_INFO(0, line)
+ ZEND_ARG_INFO(0, file)
+ ZEND_ARG_INFO(0, line)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_method_arginfo, 0, 0, 2)
- ZEND_ARG_INFO(0, class)
- ZEND_ARG_INFO(0, method)
+ ZEND_ARG_INFO(0, class)
+ ZEND_ARG_INFO(0, method)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(phpdbg_break_function_arginfo, 0, 0, 1)
- ZEND_ARG_INFO(0, function)
+ ZEND_ARG_INFO(0, function)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(phpdbg_color_arginfo, 0, 0, 0)
@@ -401,6 +713,17 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(phpdbg_clear_arginfo, 0, 0, 0)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(phpdbg_start_oplog_arginfo, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(phpdbg_end_oplog_arginfo, 0, 0, 0)
+ ZEND_ARG_INFO(0, options)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(phpdbg_get_executable_arginfo, 0, 0, 0)
+ ZEND_ARG_INFO(0, options)
+ZEND_END_ARG_INFO()
+
zend_function_entry phpdbg_user_functions[] = {
PHP_FE(phpdbg_clear, phpdbg_clear_arginfo)
PHP_FE(phpdbg_break_next, phpdbg_break_next_arginfo)
@@ -410,6 +733,9 @@ zend_function_entry phpdbg_user_functions[] = {
PHP_FE(phpdbg_exec, phpdbg_exec_arginfo)
PHP_FE(phpdbg_color, phpdbg_color_arginfo)
PHP_FE(phpdbg_prompt, phpdbg_prompt_arginfo)
+ PHP_FE(phpdbg_start_oplog, phpdbg_start_oplog_arginfo)
+ PHP_FE(phpdbg_end_oplog, phpdbg_end_oplog_arginfo)
+ PHP_FE(phpdbg_get_executable, phpdbg_get_executable_arginfo)
#ifdef PHP_FE_END
PHP_FE_END
#else
@@ -441,18 +767,18 @@ static inline int php_sapi_phpdbg_module_startup(sapi_module_struct *module) /*
return SUCCESS;
} /* }}} */
-static char* php_sapi_phpdbg_read_cookies(TSRMLS_D) /* {{{ */
+static char* php_sapi_phpdbg_read_cookies(void) /* {{{ */
{
return NULL;
} /* }}} */
-static int php_sapi_phpdbg_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s TSRMLS_DC) /* {{{ */
+static int php_sapi_phpdbg_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s) /* {{{ */
{
return 0;
}
/* }}} */
-static int php_sapi_phpdbg_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC) /* {{{ */
+static int php_sapi_phpdbg_send_headers(sapi_headers_struct *sapi_headers) /* {{{ */
{
/* We do nothing here, this function is needed to prevent that the fallback
* header handling is called. */
@@ -460,18 +786,27 @@ static int php_sapi_phpdbg_send_headers(sapi_headers_struct *sapi_headers TSRMLS
}
/* }}} */
-static void php_sapi_phpdbg_send_header(sapi_header_struct *sapi_header, void *server_context TSRMLS_DC) /* {{{ */
+static void php_sapi_phpdbg_send_header(sapi_header_struct *sapi_header, void *server_context) /* {{{ */
{
}
/* }}} */
-static void php_sapi_phpdbg_log_message(char *message TSRMLS_DC) /* {{{ */
+static void php_sapi_phpdbg_log_message(char *message) /* {{{ */
{
/*
- * We must not request TSRM before being boot
+ * We must not request TSRM before being booted
*/
if (phpdbg_booted) {
- phpdbg_error("%s", message);
+ if (PHPDBG_G(flags) & PHPDBG_IN_EVAL) {
+ phpdbg_error("eval", "msg=\"%s\"", "%s", message);
+ return;
+ }
+
+ phpdbg_error("php", "msg=\"%s\"", "%s", message);
+
+ if (PHPDBG_G(flags) & PHPDBG_PREVENT_INTERACTIVE) {
+ return;
+ }
switch (PG(last_error_type)) {
case E_ERROR:
@@ -479,123 +814,137 @@ static void php_sapi_phpdbg_log_message(char *message TSRMLS_DC) /* {{{ */
case E_COMPILE_ERROR:
case E_USER_ERROR:
case E_PARSE:
- case E_RECOVERABLE_ERROR:
- if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) {
- phpdbg_list_file(
- zend_get_executed_filename(TSRMLS_C),
- 3,
- zend_get_executed_lineno(TSRMLS_C)-1,
- zend_get_executed_lineno(TSRMLS_C)
- TSRMLS_CC
- );
+ case E_RECOVERABLE_ERROR: {
+ const char *file_char = zend_get_executed_filename();
+ zend_string *file = zend_string_init(file_char, strlen(file_char), 0);
+ phpdbg_list_file(file, 3, zend_get_executed_lineno() - 1, zend_get_executed_lineno());
+ zend_string_release(file);
+
+ if (!phpdbg_fully_started) {
+ return;
}
do {
- switch (phpdbg_interactive(TSRMLS_C)) {
+ switch (phpdbg_interactive(1)) {
case PHPDBG_LEAVE:
case PHPDBG_FINISH:
case PHPDBG_UNTIL:
case PHPDBG_NEXT:
return;
}
- } while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));
-
+ } while (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING));
+ }
}
- } else fprintf(stdout, "%s\n", message);
+ } else {
+ fprintf(stdout, "%s\n", message);
+ }
}
/* }}} */
-static int php_sapi_phpdbg_deactivate(TSRMLS_D) /* {{{ */
+static int php_sapi_phpdbg_deactivate(void) /* {{{ */
{
fflush(stdout);
- if(SG(request_info).argv0) {
+ if (SG(request_info).argv0) {
free(SG(request_info).argv0);
SG(request_info).argv0 = NULL;
}
+
return SUCCESS;
}
/* }}} */
-static void php_sapi_phpdbg_register_vars(zval *track_vars_array TSRMLS_DC) /* {{{ */
+static void php_sapi_phpdbg_register_vars(zval *track_vars_array) /* {{{ */
{
- unsigned int len;
- char *docroot = "";
+ size_t len;
+ char *docroot = "";
/* In phpdbg mode, we consider the environment to be a part of the server variables
*/
- php_import_environment_variables(track_vars_array TSRMLS_CC);
+ php_import_environment_variables(track_vars_array);
if (PHPDBG_G(exec)) {
len = PHPDBG_G(exec_len);
- if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF",
- &PHPDBG_G(exec), PHPDBG_G(exec_len), &len TSRMLS_CC)) {
- php_register_variable("PHP_SELF", PHPDBG_G(exec),
- track_vars_array TSRMLS_CC);
+ if (sapi_module.input_filter(PARSE_SERVER, "PHP_SELF", &PHPDBG_G(exec), PHPDBG_G(exec_len), &len)) {
+ php_register_variable("PHP_SELF", PHPDBG_G(exec), track_vars_array);
}
- if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_NAME",
- &PHPDBG_G(exec), PHPDBG_G(exec_len), &len TSRMLS_CC)) {
- php_register_variable("SCRIPT_NAME", PHPDBG_G(exec),
- track_vars_array TSRMLS_CC);
+ if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_NAME", &PHPDBG_G(exec), PHPDBG_G(exec_len), &len)) {
+ php_register_variable("SCRIPT_NAME", PHPDBG_G(exec), track_vars_array);
}
- if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_FILENAME",
- &PHPDBG_G(exec), PHPDBG_G(exec_len), &len TSRMLS_CC)) {
- php_register_variable("SCRIPT_FILENAME", PHPDBG_G(exec),
- track_vars_array TSRMLS_CC);
+ if (sapi_module.input_filter(PARSE_SERVER, "SCRIPT_FILENAME", &PHPDBG_G(exec), PHPDBG_G(exec_len), &len)) {
+ php_register_variable("SCRIPT_FILENAME", PHPDBG_G(exec), track_vars_array);
}
- if (sapi_module.input_filter(PARSE_SERVER, "PATH_TRANSLATED",
- &PHPDBG_G(exec), PHPDBG_G(exec_len), &len TSRMLS_CC)) {
- php_register_variable("PATH_TRANSLATED", PHPDBG_G(exec),
- track_vars_array TSRMLS_CC);
+ if (sapi_module.input_filter(PARSE_SERVER, "PATH_TRANSLATED", &PHPDBG_G(exec), PHPDBG_G(exec_len), &len)) {
+ php_register_variable("PATH_TRANSLATED", PHPDBG_G(exec), track_vars_array);
}
}
- /* any old docroot will doo */
- len = 0U;
- if (sapi_module.input_filter(PARSE_SERVER, "DOCUMENT_ROOT",
- &docroot, len, &len TSRMLS_CC)) {
- php_register_variable("DOCUMENT_ROOT", docroot, track_vars_array TSRMLS_CC);
+ /* any old docroot will do */
+ len = 0;
+ if (sapi_module.input_filter(PARSE_SERVER, "DOCUMENT_ROOT", &docroot, len, &len)) {
+ php_register_variable("DOCUMENT_ROOT", docroot, track_vars_array);
}
}
/* }}} */
-static inline int php_sapi_phpdbg_ub_write(const char *message, unsigned int length TSRMLS_DC) /* {{{ */
+static inline size_t php_sapi_phpdbg_ub_write(const char *message, size_t length) /* {{{ */
{
- return phpdbg_write("%s", message);
+ if (PHPDBG_G(socket_fd) != -1 && !(PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE)) {
+ send(PHPDBG_G(socket_fd), message, length, 0);
+ }
+ return phpdbg_script(P_STDOUT, "%.*s", length, message);
} /* }}} */
-#if PHP_VERSION_ID >= 50700
-static inline void php_sapi_phpdbg_flush(void *context TSRMLS_DC) /* {{{ */
-{
-#else
+/* beginning of struct, see main/streams/plain_wrapper.c line 111 */
+typedef struct {
+ FILE *file;
+ int fd;
+} php_stdio_stream_data;
+
+static size_t phpdbg_stdiop_write(php_stream *stream, const char *buf, size_t count) {
+ php_stdio_stream_data *data = (php_stdio_stream_data*)stream->abstract;
+
+ while (data->fd >= 0) {
+ struct stat stat[3];
+ memset(stat, 0, sizeof(stat));
+ if (((fstat(fileno(stderr), &stat[2]) < 0) & (fstat(fileno(stdout), &stat[0]) < 0)) | (fstat(data->fd, &stat[1]) < 0)) {
+ break;
+ }
+
+ if (stat[0].st_dev == stat[1].st_dev && stat[0].st_ino == stat[1].st_ino) {
+ phpdbg_script(P_STDOUT, "%.*s", (int) count, buf);
+ return count;
+ }
+ if (stat[2].st_dev == stat[1].st_dev && stat[2].st_ino == stat[1].st_ino) {
+ phpdbg_script(P_STDERR, "%.*s", (int) count, buf);
+ return count;
+ }
+ break;
+ }
+
+ return PHPDBG_G(php_stdiop_write)(stream, buf, count);
+}
+
static inline void php_sapi_phpdbg_flush(void *context) /* {{{ */
{
- TSRMLS_FETCH();
-#endif
-
- fflush(PHPDBG_G(io)[PHPDBG_STDOUT]);
+ if (!phpdbg_active_sigsafe_mem()) {
+ fflush(PHPDBG_G(io)[PHPDBG_STDOUT].ptr);
+ }
} /* }}} */
/* copied from sapi/cli/php_cli.c cli_register_file_handles */
-static void phpdbg_register_file_handles(TSRMLS_D) /* {{{ */
+static void phpdbg_register_file_handles(void) /* {{{ */
{
- zval *zin, *zout, *zerr;
+ zval zin, zout, zerr;
php_stream *s_in, *s_out, *s_err;
php_stream_context *sc_in=NULL, *sc_out=NULL, *sc_err=NULL;
zend_constant ic, oc, ec;
- MAKE_STD_ZVAL(zin);
- MAKE_STD_ZVAL(zout);
- MAKE_STD_ZVAL(zerr);
-
s_in = php_stream_open_wrapper_ex("php://stdin", "rb", 0, NULL, sc_in);
s_out = php_stream_open_wrapper_ex("php://stdout", "wb", 0, NULL, sc_out);
s_err = php_stream_open_wrapper_ex("php://stderr", "wb", 0, NULL, sc_err);
if (s_in==NULL || s_out==NULL || s_err==NULL) {
- FREE_ZVAL(zin);
- FREE_ZVAL(zout);
- FREE_ZVAL(zerr);
if (s_in) php_stream_close(s_in);
if (s_out) php_stream_close(s_out);
if (s_err) php_stream_close(s_err);
@@ -608,34 +957,27 @@ static void phpdbg_register_file_handles(TSRMLS_D) /* {{{ */
s_err->flags |= PHP_STREAM_FLAG_NO_CLOSE;
#endif
- php_stream_to_zval(s_in, zin);
- php_stream_to_zval(s_out, zout);
- php_stream_to_zval(s_err, zerr);
+ php_stream_to_zval(s_in, &zin);
+ php_stream_to_zval(s_out, &zout);
+ php_stream_to_zval(s_err, &zerr);
- ic.value = *zin;
+ ic.value = zin;
ic.flags = CONST_CS;
- ic.name = zend_strndup(ZEND_STRL("STDIN"));
- ic.name_len = sizeof("STDIN");
+ ic.name = zend_string_init(ZEND_STRL("STDIN"), 0);
ic.module_number = 0;
- zend_register_constant(&ic TSRMLS_CC);
+ zend_register_constant(&ic);
- oc.value = *zout;
+ oc.value = zout;
oc.flags = CONST_CS;
- oc.name = zend_strndup(ZEND_STRL("STDOUT"));
- oc.name_len = sizeof("STDOUT");
+ oc.name = zend_string_init(ZEND_STRL("STDOUT"), 0);
oc.module_number = 0;
- zend_register_constant(&oc TSRMLS_CC);
+ zend_register_constant(&oc);
- ec.value = *zerr;
+ ec.value = zerr;
ec.flags = CONST_CS;
- ec.name = zend_strndup(ZEND_STRL("STDERR"));
- ec.name_len = sizeof("STDERR");
+ ec.name = zend_string_init(ZEND_STRL("STDERR"), 0);
ec.module_number = 0;
- zend_register_constant(&ec TSRMLS_CC);
-
- FREE_ZVAL(zin);
- FREE_ZVAL(zout);
- FREE_ZVAL(zerr);
+ zend_register_constant(&ec);
}
/* }}} */
@@ -681,18 +1023,21 @@ const opt_struct OPTIONS[] = { /* {{{ */
/* phpdbg options */
{'q', 0, "no banner"},
{'v', 0, "disable quietness"},
- {'s', 0, "enable stepping"},
{'b', 0, "boring colours"},
{'i', 1, "specify init"},
{'I', 0, "ignore init"},
{'O', 1, "opline log"},
{'r', 0, "run"},
+ {'e', 0, "generate ext_stmt opcodes"},
{'E', 0, "step-through-eval"},
{'S', 1, "sapi-name"},
#ifndef _WIN32
{'l', 1, "listen"},
{'a', 1, "address-or-any"},
#endif
+ {'x', 0, "xml output"},
+ {'p', 2, "show opcodes"},
+ {'h', 0, "help"},
{'V', 0, "version"},
{'-', 0, NULL}
}; /* }}} */
@@ -706,14 +1051,12 @@ const char phpdbg_ini_hardcoded[] =
"max_execution_time=0\n"
"max_input_time=-1\n"
"error_log=\n"
-"output_buffering=off\0";
+"output_buffering=off\n\0";
/* overwriteable ini defaults must be set in phpdbg_ini_defaults() */
#define INI_DEFAULT(name, value) \
- Z_SET_REFCOUNT(tmp, 0); \
- Z_UNSET_ISREF(tmp); \
- ZVAL_STRINGL(&tmp, zend_strndup(value, sizeof(value)-1), sizeof(value)-1, 0); \
- zend_hash_update(configuration_hash, name, sizeof(name), &tmp, sizeof(zval), NULL);
+ ZVAL_STRINGL(&tmp, value, sizeof(value) - 1); \
+ zend_hash_str_update(configuration_hash, name, sizeof(name) - 1, &tmp);
void phpdbg_ini_defaults(HashTable *configuration_hash) /* {{{ */
{
@@ -721,199 +1064,181 @@ void phpdbg_ini_defaults(HashTable *configuration_hash) /* {{{ */
INI_DEFAULT("report_zend_debug", "0");
} /* }}} */
-static void phpdbg_welcome(zend_bool cleaning TSRMLS_DC) /* {{{ */
+static void phpdbg_welcome(zend_bool cleaning) /* {{{ */
{
/* print blurb */
if (!cleaning) {
- phpdbg_notice("Welcome to phpdbg, the interactive PHP debugger, v%s",
- PHPDBG_VERSION);
- phpdbg_writeln("To get help using phpdbg type \"help\" and press enter");
- phpdbg_notice("Please report bugs to <%s>", PHPDBG_ISSUES);
- } else {
- phpdbg_notice("Clean Execution Environment");
+ phpdbg_xml("<intros>");
+ phpdbg_notice("intro", "version=\"%s\"", "Welcome to phpdbg, the interactive PHP debugger, v%s", PHPDBG_VERSION);
+ phpdbg_writeln("intro", "help=\"help\"", "To get help using phpdbg type \"help\" and press enter");
+ phpdbg_notice("intro", "report=\"%s\"", "Please report bugs to <%s>", PHPDBG_ISSUES);
+ phpdbg_xml("</intros>");
+ } else if (phpdbg_startup_run == 0) {
+ if (!(PHPDBG_G(flags) & PHPDBG_WRITE_XML)) {
+ phpdbg_notice(NULL, NULL, "Clean Execution Environment");
+ }
- phpdbg_writeln("Classes\t\t\t%d", zend_hash_num_elements(EG(class_table)));
- phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(EG(function_table)));
- phpdbg_writeln("Constants\t\t%d", zend_hash_num_elements(EG(zend_constants)));
- phpdbg_writeln("Includes\t\t%d", zend_hash_num_elements(&EG(included_files)));
+ phpdbg_write("cleaninfo", "classes=\"%d\" functions=\"%d\" constants=\"%d\" includes=\"%d\"",
+ "Classes %d\n"
+ "Functions %d\n"
+ "Constants %d\n"
+ "Includes %d\n",
+ zend_hash_num_elements(EG(class_table)),
+ zend_hash_num_elements(EG(function_table)),
+ zend_hash_num_elements(EG(zend_constants)),
+ zend_hash_num_elements(&EG(included_files)));
}
} /* }}} */
static inline void phpdbg_sigint_handler(int signo) /* {{{ */
{
- TSRMLS_FETCH();
- if (EG(in_execution)) {
- /* set signalled only when not interactive */
- if (!(PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE)) {
- PHPDBG_G(flags) |= PHPDBG_IS_SIGNALED;
- }
- } else {
+ if (PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE) {
/* we quit remote consoles on recv SIGINT */
if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) {
- PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
+ PHPDBG_G(flags) |= PHPDBG_IS_STOPPING;
zend_bailout();
}
- }
-} /* }}} */
-
-#ifndef _WIN32
-int phpdbg_open_socket(const char *interface, short port) /* {{{ */
-{
- int fd = socket(AF_INET, SOCK_STREAM, 0);
-
- switch (fd) {
- case -1:
- return -1;
-
- default: {
- int reuse = 1;
-
- switch (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*) &reuse, sizeof(reuse))) {
- case -1:
- close(fd);
- return -2;
-
- default: {
- struct sockaddr_in address;
-
- memset(&address, 0, sizeof(address));
-
- address.sin_port = htons(port);
- address.sin_family = AF_INET;
+ } else {
+ /* set signalled only when not interactive */
+ if (PHPDBG_G(flags) & PHPDBG_IS_SIGNALED) {
+ char mem[PHPDBG_SIGSAFE_MEM_SIZE + 1];
- if ((*interface == '*')) {
- address.sin_addr.s_addr = htonl(INADDR_ANY);
- } else if (!inet_pton(AF_INET, interface, &address.sin_addr)) {
- close(fd);
- return -3;
- }
+ phpdbg_set_sigsafe_mem(mem);
+ zend_try {
+ phpdbg_force_interruption();
+ } zend_end_try()
+ phpdbg_clear_sigsafe_mem();
- switch (bind(fd, (struct sockaddr *)&address, sizeof(address))) {
- case -1:
- close(fd);
- return -4;
+ PHPDBG_G(flags) &= ~PHPDBG_IS_SIGNALED;
- default: {
- listen(fd, 5);
- }
- }
- }
+ if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) {
+ zend_bailout();
}
+ } else {
+ PHPDBG_G(flags) |= PHPDBG_IS_SIGNALED;
}
}
-
- return fd;
} /* }}} */
-static inline void phpdbg_close_sockets(int (*socket)[2], FILE *streams[2]) /* {{{ */
-{
- if ((*socket)[0] >= 0) {
- shutdown(
- (*socket)[0], SHUT_RDWR);
- close((*socket)[0]);
+static void phpdbg_remote_close(int socket, FILE *stream) {
+ if (socket >= 0) {
+ phpdbg_close_socket(socket);
}
- if (streams[0]) {
- fclose(streams[0]);
+ if (stream) {
+ fclose(stream);
}
+}
- if ((*socket)[1] >= 0) {
- shutdown(
- (*socket)[1], SHUT_RDWR);
- close((*socket)[1]);
- }
+/* don't inline this, want to debug it easily, will inline when done */
+static int phpdbg_remote_init(const char* address, unsigned short port, int server, int *socket, FILE **stream) {
+ phpdbg_remote_close(*socket, *stream);
+
+ if (server < 0) {
+ phpdbg_rlog(fileno(stderr), "Initializing connection on %s:%u failed", address, port);
- if (streams[1]) {
- fclose(streams[1]);
+ return FAILURE;
}
-} /* }}} */
-/* don't inline this, want to debug it easily, will inline when done */
+ phpdbg_rlog(fileno(stderr), "accepting connections on %s:%u", address, port);
+ {
+ struct sockaddr_storage address;
+ socklen_t size = sizeof(address);
+ char buffer[20] = {0};
+ /* XXX error checks */
+ memset(&address, 0, size);
+ *socket = accept(server, (struct sockaddr *) &address, &size);
+ inet_ntop(AF_INET, &(((struct sockaddr_in *)&address)->sin_addr), buffer, sizeof(buffer));
-int phpdbg_open_sockets(char *address, int port[2], int (*listen)[2], int (*socket)[2], FILE* streams[2]) /* {{{ */
-{
- if (((*listen)[0]) < 0 && ((*listen)[1]) < 0) {
- ((*listen)[0]) = phpdbg_open_socket(address, (short)port[0]);
- ((*listen)[1]) = phpdbg_open_socket(address, (short)port[1]);
+ phpdbg_rlog(fileno(stderr), "connection established from %s", buffer);
}
- streams[0] = NULL;
- streams[1] = NULL;
-
- if ((*listen)[0] < 0 || (*listen)[1] < 0) {
- if ((*listen)[0] < 0) {
- phpdbg_rlog(stderr,
- "console failed to initialize (stdin) on %s:%d", address, port[0]);
- }
+#ifndef _WIN32
+ dup2(*socket, fileno(stdout));
+ dup2(*socket, fileno(stdin));
- if ((*listen)[1] < 0) {
- phpdbg_rlog(stderr,
- "console failed to initialize (stdout) on %s:%d", address, port[1]);
- }
+ setbuf(stdout, NULL);
- if ((*listen)[0] >= 0) {
- close((*listen)[0]);
- }
+ *stream = fdopen(*socket, "r+");
- if ((*listen)[1] >= 0) {
- close((*listen)[1]);
- }
+ phpdbg_set_async_io(*socket);
+#endif
+ return SUCCESS;
+}
- return FAILURE;
- }
+#ifndef _WIN32
+/* This function *strictly* assumes that SIGIO is *only* used on the remote connection stream */
+void phpdbg_sigio_handler(int sig, siginfo_t *info, void *context) /* {{{ */
+{
+ int flags;
+ size_t newlen;
+ size_t i/*, last_nl*/;
- phpdbg_close_sockets(socket, streams);
+// if (!(info->si_band & POLLIN)) {
+// return; /* Not interested in writeablility etc., just interested in incoming data */
+// }
- phpdbg_rlog(stderr,
- "accepting connections on %s:%d/%d", address, port[0], port[1]);
- {
- struct sockaddr_in address;
- socklen_t size = sizeof(address);
- char buffer[20] = {0};
+ /* only non-blocking reading, avoid non-blocking writing */
+ flags = fcntl(PHPDBG_G(io)[PHPDBG_STDIN].fd, F_GETFL, 0);
+ fcntl(PHPDBG_G(io)[PHPDBG_STDIN].fd, F_SETFL, flags | O_NONBLOCK);
- {
- memset(&address, 0, size);
- (*socket)[0] = accept(
- (*listen)[0], (struct sockaddr *) &address, &size);
- inet_ntop(AF_INET, &address.sin_addr, buffer, sizeof(buffer));
+ do {
+ char mem[PHPDBG_SIGSAFE_MEM_SIZE + 1];
+ size_t off = 0;
- phpdbg_rlog(stderr, "connection (stdin) from %s", buffer);
+ if ((newlen = recv(PHPDBG_G(io)[PHPDBG_STDIN].fd, mem, PHPDBG_SIGSAFE_MEM_SIZE, MSG_PEEK)) == (size_t) -1) {
+ break;
}
+ for (i = 0; i < newlen; i++) {
+ switch (mem[off + i]) {
+ case '\x03': /* ^C char */
+ if (PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE) {
+ break; /* or quit ??? */
+ }
+ if (PHPDBG_G(flags) & PHPDBG_IS_SIGNALED) {
+ phpdbg_set_sigsafe_mem(mem);
+ zend_try {
+ phpdbg_force_interruption();
+ } zend_end_try();
+ phpdbg_clear_sigsafe_mem();
- {
- memset(&address, 0, size);
- (*socket)[1] = accept(
- (*listen)[1], (struct sockaddr *) &address, &size);
- inet_ntop(AF_INET, &address.sin_addr, buffer, sizeof(buffer));
+ PHPDBG_G(flags) &= ~PHPDBG_IS_SIGNALED;
- phpdbg_rlog(stderr, "connection (stdout) from %s", buffer);
+ if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) {
+ zend_bailout();
+ }
+ } else if (!(PHPDBG_G(flags) & PHPDBG_IS_INTERACTIVE)) {
+ PHPDBG_G(flags) |= PHPDBG_IS_SIGNALED;
+ }
+ break;
+/* case '\n':
+ zend_llist_add_element(PHPDBG_G(stdin), strndup()
+ last_nl = PHPDBG_G(stdin_buf).len + i;
+ break;
+*/ }
}
- }
-
- dup2((*socket)[0], fileno(stdin));
- dup2((*socket)[1], fileno(stdout));
-
- setbuf(stdout, NULL);
+ off += i;
+ } while (0);
- streams[0] = fdopen((*socket)[0], "r");
- streams[1] = fdopen((*socket)[1], "w");
- return SUCCESS;
+ fcntl(PHPDBG_G(io)[PHPDBG_STDIN].fd, F_SETFL, flags);
} /* }}} */
void phpdbg_signal_handler(int sig, siginfo_t *info, void *context) /* {{{ */
{
int is_handled = FAILURE;
- TSRMLS_FETCH();
switch (sig) {
case SIGBUS:
case SIGSEGV:
- is_handled = phpdbg_watchpoint_segfault_handler(info, context TSRMLS_CC);
+ if (PHPDBG_G(sigsegv_bailout)) {
+ LONGJMP(*PHPDBG_G(sigsegv_bailout), FAILURE);
+ }
+ is_handled = phpdbg_watchpoint_segfault_handler(info, context);
if (is_handled == FAILURE) {
#ifdef ZEND_SIGNALS
- zend_sigaction(sig, &PHPDBG_G(old_sigsegv_signal), NULL TSRMLS_CC);
+ zend_sigaction(sig, &PHPDBG_G(old_sigsegv_signal), NULL);
#else
sigaction(sig, &PHPDBG_G(old_sigsegv_signal), NULL);
#endif
@@ -924,31 +1249,32 @@ void phpdbg_signal_handler(int sig, siginfo_t *info, void *context) /* {{{ */
} /* }}} */
#endif
-static inline zend_mm_heap *phpdbg_mm_get_heap() /* {{{ */
+void phpdbg_sighup_handler(int sig) /* {{{ */
{
- zend_mm_heap *mm_heap;
-
- TSRMLS_FETCH();
-
- mm_heap = zend_mm_set_heap(NULL TSRMLS_CC);
- zend_mm_set_heap(mm_heap TSRMLS_CC);
-
- return mm_heap;
+ exit(0);
} /* }}} */
-void *phpdbg_malloc_wrapper(size_t size) /* {{{ */
+void *phpdbg_malloc_wrapper(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) /* {{{ */
{
- return zend_mm_alloc(phpdbg_mm_get_heap(), size);
+ return _zend_mm_alloc(zend_mm_get_heap(), size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
} /* }}} */
-void phpdbg_free_wrapper(void *p) /* {{{ */
+void phpdbg_free_wrapper(void *p ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) /* {{{ */
{
- zend_mm_free(phpdbg_mm_get_heap(), p);
+ zend_mm_heap *heap = zend_mm_get_heap();
+ if (UNEXPECTED(heap == p)) {
+ /* TODO: heap maybe allocated by mmap(zend_mm_init) or malloc(USE_ZEND_ALLOC=0)
+ * let's prevent it from segfault for now
+ */
+ } else {
+ phpdbg_watch_efree(p);
+ return _zend_mm_free(heap, p ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
+ }
} /* }}} */
-void *phpdbg_realloc_wrapper(void *ptr, size_t size) /* {{{ */
+void *phpdbg_realloc_wrapper(void *ptr, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) /* {{{ */
{
- return zend_mm_realloc(phpdbg_mm_get_heap(), ptr, size);
+ return _zend_mm_realloc(zend_mm_get_heap(), ptr, size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
} /* }}} */
int main(int argc, char **argv) /* {{{ */
@@ -961,8 +1287,7 @@ int main(int argc, char **argv) /* {{{ */
zend_ulong zend_extensions_len = 0L;
zend_bool ini_ignore;
char *ini_override;
- char *exec;
- size_t exec_len;
+ char *exec = NULL;
char *init_file;
size_t init_file_len;
zend_bool init_file_default;
@@ -971,43 +1296,37 @@ int main(int argc, char **argv) /* {{{ */
zend_ulong flags;
char *php_optarg;
int php_optind, opt, show_banner = 1;
- long cleaning = 0;
+ long cleaning = -1;
+ volatile zend_bool quit_immediately = 0; /* somehow some gcc release builds will play a bit around with order in combination with setjmp..., hence volatile */
zend_bool remote = 0;
- int run = 0;
- int step = 0;
-
-#ifdef _WIN32
- char *bp_tmp_file = NULL;
-#else
- char bp_tmp_file[] = "/tmp/phpdbg.XXXXXX";
-#endif
-
-#ifndef _WIN32
+ zend_phpdbg_globals *settings = NULL;
+ char *bp_tmp = NULL;
char *address;
- int listen[2];
- int server[2];
- int socket[2];
- FILE* streams[2] = {NULL, NULL};
-#endif
+ int listen = -1;
+ int server = -1;
+ int socket = -1;
+ FILE* stream = NULL;
+ char *print_opline_func;
+ zend_bool ext_stmt = 0;
+ zend_bool use_mm_wrappers = 0;
+ zend_bool is_exit;
+ int exit_status;
#ifdef ZTS
void ***tsrm_ls;
#endif
#ifndef _WIN32
+ struct sigaction sigio_struct;
struct sigaction signal_struct;
signal_struct.sa_sigaction = phpdbg_signal_handler;
signal_struct.sa_flags = SA_SIGINFO | SA_NODEFER;
+ sigemptyset(&signal_struct.sa_mask);
+ sigio_struct.sa_sigaction = phpdbg_sigio_handler;
+ sigio_struct.sa_flags = SA_SIGINFO;
+ sigemptyset(&sigio_struct.sa_mask);
address = strdup("127.0.0.1");
- socket[0] = -1;
- socket[1] = -1;
- listen[0] = -1;
- listen[1] = -1;
- server[0] = -1;
- server[1] = -1;
- streams[0] = NULL;
- streams[1] = NULL;
#endif
#ifdef PHP_WIN32
@@ -1023,55 +1342,39 @@ int main(int argc, char **argv) /* {{{ */
tsrm_ls = ts_resource(0);
#endif
-phpdbg_main:
- if (!cleaning) {
-
-#ifdef _WIN32
- bp_tmp_file = malloc(L_tmpnam);
-
- if (bp_tmp_file) {
- if (!tmpnam(bp_tmp_file)) {
- free(bp_tmp_file);
- bp_tmp_file = NULL;
- }
- }
-
- if (!bp_tmp_file) {
- phpdbg_error("Unable to create temporary file");
- return 1;
- }
-#else
- if (!mkstemp(bp_tmp_file)) {
- memset(bp_tmp_file, 0, sizeof(bp_tmp_file));
- }
+#ifdef ZEND_SIGNALS
+ zend_signal_startup();
#endif
- }
+phpdbg_main:
ini_entries = NULL;
ini_entries_len = 0;
ini_ignore = 0;
ini_override = NULL;
zend_extensions = NULL;
zend_extensions_len = 0L;
- exec = NULL;
- exec_len = 0;
init_file = NULL;
init_file_len = 0;
init_file_default = 1;
oplog_file = NULL;
oplog_file_len = 0;
flags = PHPDBG_DEFAULT_FLAGS;
+ is_exit = 0;
php_optarg = NULL;
php_optind = 1;
opt = 0;
- run = 0;
- step = 0;
sapi_name = NULL;
+ exit_status = 0;
+ if (settings) {
+ exec = settings->exec;
+ }
while ((opt = php_getopt(argc, argv, OPTIONS, &php_optarg, &php_optind, 0, 2)) != -1) {
switch (opt) {
case 'r':
- run++;
+ if (settings == NULL) {
+ phpdbg_startup_run++;
+ }
break;
case 'n':
ini_ignore = 1;
@@ -1155,8 +1458,8 @@ phpdbg_main:
flags &= ~PHPDBG_IS_QUIET;
break;
- case 's': /* set stepping on */
- step = 1;
+ case 'e':
+ ext_stmt = 1;
break;
case 'E': /* stepping through eval on */
@@ -1172,20 +1475,12 @@ phpdbg_main:
break;
#ifndef _WIN32
- /* if you pass a listen port, we will accept input on listen port */
- /* and write output to listen port * 2 */
-
- case 'l': { /* set listen ports */
- if (sscanf(php_optarg, "%d/%d", &listen[0], &listen[1]) != 2) {
- if (sscanf(php_optarg, "%d", &listen[0]) != 1) {
- /* default to hardcoded ports */
- listen[0] = 4000;
- listen[1] = 8000;
- } else {
- listen[1] = (listen[0] * 2);
- }
+ /* if you pass a listen port, we will read and write on listen port */
+ case 'l': /* set listen ports */
+ if (sscanf(php_optarg, "%d", &listen) != 1) {
+ listen = 8000;
}
- } break;
+ break;
case 'a': { /* set bind address */
free(address);
@@ -1195,6 +1490,32 @@ phpdbg_main:
} break;
#endif
+ case 'x':
+ flags |= PHPDBG_WRITE_XML;
+ break;
+
+
+ case 'p': {
+ print_opline_func = php_optarg;
+ show_banner = 0;
+ settings = (void *) 0x1;
+ } break;
+
+ case 'h': {
+ sapi_startup(phpdbg);
+ phpdbg->startup(phpdbg);
+ PHPDBG_G(flags) = 0;
+ /* It ain't gonna proceed to real execution anyway,
+ but the correct descriptor is needed already. */
+ PHPDBG_G(io)[PHPDBG_STDOUT].ptr = stdout;
+ PHPDBG_G(io)[PHPDBG_STDOUT].fd = fileno(stdout);
+ phpdbg_set_prompt(PHPDBG_DEFAULT_PROMPT);
+ phpdbg_do_help(NULL);
+ sapi_deactivate();
+ sapi_shutdown();
+ return 0;
+ } break;
+
case 'V': {
sapi_startup(phpdbg);
phpdbg->startup(phpdbg);
@@ -1206,39 +1527,23 @@ phpdbg_main:
PHP_VERSION,
get_zend_version()
);
- sapi_deactivate(TSRMLS_C);
+ sapi_deactivate();
sapi_shutdown();
return 0;
} break;
}
+
+ php_optarg = NULL;
}
-
+
/* set exec if present on command line */
- if ((argc > php_optind) && (strcmp(argv[php_optind-1],"--") != SUCCESS))
- {
- exec_len = strlen(argv[php_optind]);
- if (exec_len) {
- if (exec) {
- free(exec);
- }
+ if (argc > php_optind && (strcmp(argv[php_optind-1], "--") != SUCCESS)) {
+ if (!exec && strlen(argv[php_optind])) {
exec = strdup(argv[php_optind]);
}
php_optind++;
}
-#ifndef _WIN32
- /* setup remote server if necessary */
- if (!cleaning &&
- (listen[0] > 0 && listen[1] > 0)) {
- if (phpdbg_open_sockets(address, listen, &server, &socket, streams) == FAILURE) {
- remote = 0;
- exit(0);
- }
- /* set remote flag to stop service shutting down upon quit */
- remote = 1;
- }
-#endif
-
if (sapi_name) {
phpdbg->name = sapi_name;
}
@@ -1289,153 +1594,246 @@ phpdbg_main:
phpdbg->ini_entries = ini_entries;
if (phpdbg->startup(phpdbg) == SUCCESS) {
+ zend_mm_heap *mm_heap;
#ifdef _WIN32
EXCEPTION_POINTERS *xp;
__try {
#endif
- zend_mm_heap *mm_heap = phpdbg_mm_get_heap();
+ void* (*_malloc)(size_t);
+ void (*_free)(void*);
+ void* (*_realloc)(void*, size_t);
+
+ /* set flags from command line */
+ PHPDBG_G(flags) = flags;
+
+ if (settings > (zend_phpdbg_globals *) 0x2) {
+#ifdef ZTS
+ *((zend_phpdbg_globals *) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(phpdbg_globals_id)]) = *settings;
+#else
+ phpdbg_globals = *settings;
+#endif
+ free(settings);
+ }
+
+ /* setup remote server if necessary */
+ if (cleaning <= 0 && listen > 0) {
+ server = phpdbg_open_socket(address, listen);
+ if (-1 > server || phpdbg_remote_init(address, listen, server, &socket, &stream) == FAILURE) {
+ exit(0);
+ }
+
+#ifndef _WIN32
+ sigaction(SIGIO, &sigio_struct, NULL);
+#endif
- if (mm_heap->use_zend_alloc) {
- mm_heap->_malloc = phpdbg_malloc_wrapper;
- mm_heap->_realloc = phpdbg_realloc_wrapper;
- mm_heap->_free = phpdbg_free_wrapper;
- mm_heap->use_zend_alloc = 0;
+ /* set remote flag to stop service shutting down upon quit */
+ remote = 1;
+#ifndef _WIN32
+ } else {
+
+ signal(SIGHUP, phpdbg_sighup_handler);
+#endif
}
- zend_activate(TSRMLS_C);
+ mm_heap = zend_mm_get_heap();
+ zend_mm_get_custom_handlers(mm_heap, &_malloc, &_free, &_realloc);
+
+ use_mm_wrappers = !_malloc && !_realloc && !_free;
- PHPDBG_G(original_free_function) = mm_heap->_free;
- mm_heap->_free = phpdbg_watch_efree;
+ phpdbg_init_list();
- phpdbg_setup_watchpoints(TSRMLS_C);
+ PHPDBG_G(original_free_function) = _free;
+ _free = phpdbg_watch_efree;
+
+ if (use_mm_wrappers) {
+#if ZEND_DEBUG
+ zend_mm_set_custom_debug_handlers(mm_heap, phpdbg_malloc_wrapper, phpdbg_free_wrapper, phpdbg_realloc_wrapper);
+#else
+ zend_mm_set_custom_handlers(mm_heap, phpdbg_malloc_wrapper, phpdbg_free_wrapper, phpdbg_realloc_wrapper);
+#endif
+ } else {
+ zend_mm_set_custom_handlers(mm_heap, _malloc, _free, _realloc);
+ }
+
+ phpdbg_setup_watchpoints();
#if defined(ZEND_SIGNALS) && !defined(_WIN32)
zend_try {
- zend_signal_activate(TSRMLS_C);
+ zend_signal_activate();
} zend_end_try();
#endif
#if defined(ZEND_SIGNALS) && !defined(_WIN32)
- zend_try { zend_sigaction(SIGSEGV, &signal_struct, &PHPDBG_G(old_sigsegv_signal) TSRMLS_CC); } zend_end_try();
- zend_try { zend_sigaction(SIGBUS, &signal_struct, &PHPDBG_G(old_sigsegv_signal) TSRMLS_CC); } zend_end_try();
+ zend_try { zend_sigaction(SIGSEGV, &signal_struct, &PHPDBG_G(old_sigsegv_signal)); } zend_end_try();
+ zend_try { zend_sigaction(SIGBUS, &signal_struct, &PHPDBG_G(old_sigsegv_signal)); } zend_end_try();
#elif !defined(_WIN32)
sigaction(SIGSEGV, &signal_struct, &PHPDBG_G(old_sigsegv_signal));
sigaction(SIGBUS, &signal_struct, &PHPDBG_G(old_sigsegv_signal));
#endif
- if (php_request_startup(TSRMLS_C) == SUCCESS) {
+ PHPDBG_G(sapi_name_ptr) = sapi_name;
+
+ if (exec) { /* set execution context */
+ PHPDBG_G(exec) = phpdbg_resolve_path(exec);
+ PHPDBG_G(exec_len) = PHPDBG_G(exec) ? strlen(PHPDBG_G(exec)) : 0;
+
+ free(exec);
+ exec = NULL;
+ }
+
+ php_output_activate();
+ php_output_deactivate();
+
+ if (SG(sapi_headers).mimetype) {
+ efree(SG(sapi_headers).mimetype);
+ SG(sapi_headers).mimetype = NULL;
+ }
+
+ php_output_activate();
+
+ {
int i;
-
- SG(request_info).argc = argc - php_optind + 1;
+
+ SG(request_info).argc = argc - php_optind + 1;
SG(request_info).argv = emalloc(SG(request_info).argc * sizeof(char *));
for (i = SG(request_info).argc; --i;) {
SG(request_info).argv[i] = estrdup(argv[php_optind - 1 + i]);
}
- SG(request_info).argv[i] = exec ? estrndup(exec, exec_len) : estrdup("");
+ SG(request_info).argv[0] = PHPDBG_G(exec) ? estrdup(PHPDBG_G(exec)) : estrdup("");
+ }
- php_hash_environment(TSRMLS_C);
+ if (php_request_startup() == FAILURE) {
+ PUTS("Could not startup");
+ return 1;
}
- /* make sure to turn off buffer for ev command */
- php_output_activate(TSRMLS_C);
- php_output_deactivate(TSRMLS_C);
-
/* do not install sigint handlers for remote consoles */
/* sending SIGINT then provides a decent way of shutting down the server */
#ifndef _WIN32
- if (listen[0] < 0) {
+ if (listen < 0) {
#endif
#if defined(ZEND_SIGNALS) && !defined(_WIN32)
- zend_try { zend_signal(SIGINT, phpdbg_sigint_handler TSRMLS_CC); } zend_end_try();
+ zend_try { zend_signal(SIGINT, phpdbg_sigint_handler); } zend_end_try();
#else
signal(SIGINT, phpdbg_sigint_handler);
#endif
#ifndef _WIN32
}
-#endif
-
- PG(modules_activated) = 0;
- /* set flags from command line */
- PHPDBG_G(flags) = flags;
-
-#ifndef _WIN32
/* setup io here */
- if (streams[0] && streams[1]) {
+ if (remote) {
PHPDBG_G(flags) |= PHPDBG_IS_REMOTE;
signal(SIGPIPE, SIG_IGN);
}
+ PHPDBG_G(io)[PHPDBG_STDIN].ptr = stdin;
+ PHPDBG_G(io)[PHPDBG_STDIN].fd = fileno(stdin);
+ PHPDBG_G(io)[PHPDBG_STDOUT].ptr = stdout;
+ PHPDBG_G(io)[PHPDBG_STDOUT].fd = fileno(stdout);
+#else
+ /* XXX this is a complete mess here with FILE/fd/SOCKET,
+ we should let only one to survive probably. Need
+ a clean separation whether it's a remote or local
+ prompt. And what is supposed to go as user interaction,
+ error log, etc. */
+ if (remote) {
+ PHPDBG_G(io)[PHPDBG_STDIN].ptr = stdin;
+ PHPDBG_G(io)[PHPDBG_STDIN].fd = socket;
+ PHPDBG_G(io)[PHPDBG_STDOUT].ptr = stdout;
+ PHPDBG_G(io)[PHPDBG_STDOUT].fd = socket;
+ } else {
+ PHPDBG_G(io)[PHPDBG_STDIN].ptr = stdin;
+ PHPDBG_G(io)[PHPDBG_STDIN].fd = fileno(stdin);
+ PHPDBG_G(io)[PHPDBG_STDOUT].ptr = stdout;
+ PHPDBG_G(io)[PHPDBG_STDOUT].fd = fileno(stdout);
+ }
#endif
+ PHPDBG_G(io)[PHPDBG_STDERR].ptr = stderr;
+ PHPDBG_G(io)[PHPDBG_STDERR].fd = fileno(stderr);
- PHPDBG_G(io)[PHPDBG_STDIN] = stdin;
- PHPDBG_G(io)[PHPDBG_STDOUT] = stdout;
- PHPDBG_G(io)[PHPDBG_STDERR] = stderr;
-
- if (exec) { /* set execution context */
- PHPDBG_G(exec) = phpdbg_resolve_path(exec TSRMLS_CC);
- PHPDBG_G(exec_len) = strlen(PHPDBG_G(exec));
-
- free(exec);
- }
+#ifndef _WIN32
+ PHPDBG_G(php_stdiop_write) = php_stream_stdio_ops.write;
+ php_stream_stdio_ops.write = phpdbg_stdiop_write;
+#endif
if (oplog_file) { /* open oplog */
PHPDBG_G(oplog) = fopen(oplog_file, "w+");
if (!PHPDBG_G(oplog)) {
- phpdbg_error(
- "Failed to open oplog %s", oplog_file);
+ phpdbg_error("oplog", "path=\"%s\"", "Failed to open oplog %s", oplog_file);
}
free(oplog_file);
+ oplog_file = NULL;
}
/* set default colors */
- phpdbg_set_color_ex(PHPDBG_COLOR_PROMPT, PHPDBG_STRL("white-bold") TSRMLS_CC);
- phpdbg_set_color_ex(PHPDBG_COLOR_ERROR, PHPDBG_STRL("red-bold") TSRMLS_CC);
- phpdbg_set_color_ex(PHPDBG_COLOR_NOTICE, PHPDBG_STRL("green") TSRMLS_CC);
+ phpdbg_set_color_ex(PHPDBG_COLOR_PROMPT, PHPDBG_STRL("white-bold"));
+ phpdbg_set_color_ex(PHPDBG_COLOR_ERROR, PHPDBG_STRL("red-bold"));
+ phpdbg_set_color_ex(PHPDBG_COLOR_NOTICE, PHPDBG_STRL("green"));
/* set default prompt */
- phpdbg_set_prompt(PROMPT TSRMLS_CC);
+ phpdbg_set_prompt(PHPDBG_DEFAULT_PROMPT);
/* Make stdin, stdout and stderr accessible from PHP scripts */
- phpdbg_register_file_handles(TSRMLS_C);
+ phpdbg_register_file_handles();
- if (show_banner) {
+ phpdbg_list_update();
+
+ if (show_banner && cleaning < 2) {
/* print blurb */
- phpdbg_welcome((cleaning > 0) TSRMLS_CC);
+ phpdbg_welcome(cleaning == 1);
}
- /* auto compile */
- if (PHPDBG_G(exec)) {
- phpdbg_compile(TSRMLS_C);
+ cleaning = -1;
+
+ if (ext_stmt) {
+ CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
}
/* initialize from file */
PHPDBG_G(flags) |= PHPDBG_IS_INITIALIZING;
zend_try {
- phpdbg_init(init_file, init_file_len, init_file_default TSRMLS_CC);
- phpdbg_try_file_init(bp_tmp_file, strlen(bp_tmp_file), 0 TSRMLS_CC);
+ phpdbg_init(init_file, init_file_len, init_file_default);
+ if (bp_tmp) {
+ PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT;
+ phpdbg_string_init(bp_tmp);
+ free(bp_tmp);
+ bp_tmp = NULL;
+ PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT;
+ }
} zend_end_try();
PHPDBG_G(flags) &= ~PHPDBG_IS_INITIALIZING;
-
+
/* quit if init says so */
if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) {
goto phpdbg_out;
}
- /* step from here, not through init */
- if (step) {
- PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
+ /* auto compile */
+ if (PHPDBG_G(exec)) {
+ if (settings || phpdbg_startup_run > 0) {
+ PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT;
+ }
+
+ zend_try {
+ phpdbg_compile();
+ } zend_end_try();
+
+ PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT;
}
- if (run) {
- /* no need to try{}, run does it ... */
- PHPDBG_COMMAND_HANDLER(run)(NULL TSRMLS_CC);
- if (run > 1) {
- /* if -r is on the command line more than once just quit */
- goto phpdbg_out;
+ if (settings == (void *) 0x1) {
+ if (PHPDBG_G(ops)) {
+ phpdbg_print_opcodes(print_opline_func);
+ } else {
+ quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, ZEND_STRL("No opcodes could be compiled | No file specified or compilation failed?\n"));
}
+ goto phpdbg_out;
}
+ PG(during_request_startup) = 0;
+
+ phpdbg_fully_started = 1;
+
/* #ifndef for making compiler shutting up */
#ifndef _WIN32
phpdbg_interact:
@@ -1443,12 +1841,37 @@ phpdbg_interact:
/* phpdbg main() */
do {
zend_try {
- phpdbg_interactive(TSRMLS_C);
+ if (phpdbg_startup_run) {
+ quit_immediately = phpdbg_startup_run > 1;
+ phpdbg_startup_run = 0;
+ if (quit_immediately) {
+ PHPDBG_G(flags) = (PHPDBG_G(flags) & ~PHPDBG_HAS_PAGINATION) | PHPDBG_IS_INTERACTIVE | PHPDBG_PREVENT_INTERACTIVE;
+ } else {
+ PHPDBG_G(flags) |= PHPDBG_IS_INTERACTIVE;
+ }
+ zend_try {
+ PHPDBG_COMMAND_HANDLER(run)(NULL);
+ } zend_end_try();
+ if (quit_immediately) {
+ /* if -r is on the command line more than once just quit */
+ EG(bailout) = __orig_bailout; /* reset zend_try */
+ exit_status = EG(exit_status);
+ break;
+ }
+ }
+
+ CG(unclean_shutdown) = 0;
+ phpdbg_interactive(1);
} zend_catch {
if ((PHPDBG_G(flags) & PHPDBG_IS_CLEANING)) {
- FILE *bp_tmp_fp = fopen(bp_tmp_file, "w");
- phpdbg_export_breakpoints(bp_tmp_fp TSRMLS_CC);
- fclose(bp_tmp_fp);
+ char *bp_tmp_str;
+ PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT;
+ phpdbg_export_breakpoints_to_string(&bp_tmp_str);
+ PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT;
+ if (bp_tmp_str) {
+ bp_tmp = strdup(bp_tmp_str);
+ efree(bp_tmp_str);
+ }
cleaning = 1;
} else {
cleaning = 0;
@@ -1458,17 +1881,16 @@ phpdbg_interact:
if (!cleaning) {
/* remote client disconnected */
if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) {
-
+
if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) {
/* renegociate connections */
- phpdbg_open_sockets(
- address, listen, &server, &socket, streams);
-
+ phpdbg_remote_init(address, listen, server, &socket, &stream);
+
/* set streams */
- if (streams[0] && streams[1]) {
+ if (stream) {
PHPDBG_G(flags) &= ~PHPDBG_IS_QUITTING;
}
-
+
/* this must be forced */
CG(unclean_shutdown) = 0;
} else {
@@ -1479,14 +1901,9 @@ phpdbg_interact:
}
#endif
} zend_end_try();
- } while(!cleaning && !(PHPDBG_G(flags) & PHPDBG_IS_QUITTING));
-
- /* this must be forced */
- CG(unclean_shutdown) = 0;
-
- /* this is just helpful */
- PG(report_memleaks) = 0;
-
+ } while (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING));
+
+
#ifndef _WIN32
phpdbg_out:
if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) {
@@ -1497,26 +1914,25 @@ phpdbg_out:
#ifdef _WIN32
} __except(phpdbg_exception_handler_win32(xp = GetExceptionInformation())) {
- phpdbg_error("Access violation (Segmentation fault) encountered\ntrying to abort cleanly...");
+ phpdbg_error("segfault", "", "Access violation (Segmentation fault) encountered\ntrying to abort cleanly...");
}
phpdbg_out:
#endif
-
+
+ if (cleaning <= 0) {
+ PHPDBG_G(flags) &= ~PHPDBG_IS_CLEANING;
+ cleaning = -1;
+ }
+
{
int i;
/* free argv */
- for (i = SG(request_info).argc; --i;) {
+ for (i = SG(request_info).argc; i--;) {
efree(SG(request_info).argv[i]);
}
efree(SG(request_info).argv);
}
-#ifndef ZTS
- /* force cleanup of auto and core globals */
- zend_hash_clean(CG(auto_globals));
- memset(
- &core_globals, 0, sizeof(php_core_globals));
-#endif
if (ini_entries) {
free(ini_entries);
}
@@ -1524,27 +1940,87 @@ phpdbg_out:
if (ini_override) {
free(ini_override);
}
-
- /* this must be forced */
- CG(unclean_shutdown) = 0;
-
- /* this is just helpful */
- PG(report_memleaks) = 0;
- php_request_shutdown((void*)0);
+ /* In case we aborted during script execution, we may not reset CG(unclean_shutdown) */
+ if (!(PHPDBG_G(flags) & PHPDBG_IS_RUNNING)) {
+ is_exit = !PHPDBG_G(in_execution);
+ CG(unclean_shutdown) = is_exit || PHPDBG_G(unclean_eval);
+ }
+
+ if ((PHPDBG_G(flags) & (PHPDBG_IS_CLEANING | PHPDBG_IS_RUNNING)) == PHPDBG_IS_CLEANING) {
+ php_free_shutdown_functions();
+ zend_objects_store_mark_destructed(&EG(objects_store));
+ }
+
+ /* backup globals when cleaning */
+ if ((cleaning > 0 || remote) && !quit_immediately) {
+ settings = calloc(1, sizeof(zend_phpdbg_globals));
+
+ php_phpdbg_globals_ctor(settings);
+
+ if (PHPDBG_G(exec)) {
+ settings->exec = zend_strndup(PHPDBG_G(exec), PHPDBG_G(exec_len));
+ settings->exec_len = PHPDBG_G(exec_len);
+ }
+ settings->oplog = PHPDBG_G(oplog);
+ settings->prompt[0] = PHPDBG_G(prompt)[0];
+ settings->prompt[1] = PHPDBG_G(prompt)[1];
+ memcpy(settings->colors, PHPDBG_G(colors), sizeof(settings->colors));
+ settings->eol = PHPDBG_G(eol);
+ settings->input_buflen = PHPDBG_G(input_buflen);
+ memcpy(settings->input_buffer, PHPDBG_G(input_buffer), settings->input_buflen);
+ settings->flags = PHPDBG_G(flags) & PHPDBG_PRESERVE_FLAGS_MASK;
+ } else {
+ if (PHPDBG_G(prompt)[0]) {
+ free(PHPDBG_G(prompt)[0]);
+ }
+ if (PHPDBG_G(prompt)[1]) {
+ free(PHPDBG_G(prompt)[1]);
+ }
+ }
+
+ /* hack to restore mm_heap->use_custom_heap in order to receive memory leak info */
+ if (use_mm_wrappers) {
+ /* ASSUMING that mm_heap->use_custom_heap is the first element of the struct ... */
+ *(int *) mm_heap = 0;
+ }
+ zend_try {
+ php_request_shutdown(NULL);
+ } zend_end_try();
+
+ if (exit_status == 0) {
+ exit_status = EG(exit_status);
+ }
+
+ if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
+ if (PHPDBG_G(in_execution) || is_exit) {
+ if (!quit_immediately && !phpdbg_startup_run) {
+ phpdbg_notice("stop", "type=\"normal\"", "Script ended normally");
+ cleaning++;
+ }
+ }
+ }
+ php_output_deactivate();
zend_try {
- php_module_shutdown(TSRMLS_C);
+ php_module_shutdown();
} zend_end_try();
- sapi_shutdown();
+#ifndef _WIN32
+ /* reset it... else we risk a stack overflow upon next run (when clean'ing) */
+ php_stream_stdio_ops.write = PHPDBG_G(php_stdiop_write);
+#endif
+ sapi_shutdown();
}
- if (cleaning || remote) {
+ if ((cleaning > 0 || remote) && !quit_immediately) {
+ /* reset internal php_getopt state */
+ php_getopt(-1, argv, OPTIONS, NULL, &php_optind, 0, 0);
+
goto phpdbg_main;
}
-
+
#ifdef ZTS
/* bugggy */
/* tsrm_shutdown(); */
@@ -1556,15 +2032,10 @@ phpdbg_out:
}
#endif
- if (sapi_name) {
- free(sapi_name);
+ if (PHPDBG_G(sapi_name_ptr)) {
+ free(PHPDBG_G(sapi_name_ptr));
}
-
-#ifdef _WIN32
- free(bp_tmp_file);
-#else
- unlink(bp_tmp_file);
-#endif
- return 0;
+ /* usually 0; just for -rr */
+ return exit_status;
} /* }}} */
diff --git a/sapi/phpdbg/phpdbg.h b/sapi/phpdbg/phpdbg.h
index 06cb4b83a9..63b05cd806 100644
--- a/sapi/phpdbg/phpdbg.h
+++ b/sapi/phpdbg/phpdbg.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -29,6 +29,12 @@
# define PHPDBG_API
#endif
+#ifndef PHP_WIN32
+# include <stdint.h>
+# include <stddef.h>
+#else
+# include "main/php_stdint.h"
+#endif
#include "php.h"
#include "php_globals.h"
#include "php_variables.h"
@@ -40,20 +46,20 @@
#include "zend_ini_scanner.h"
#include "zend_stream.h"
#ifndef _WIN32
-# include "zend_signal.h"
+# include "zend_signal.h"
#endif
#include "SAPI.h"
#include <fcntl.h>
#include <sys/types.h>
#if defined(_WIN32) && !defined(__MINGW32__)
-# include <windows.h>
-# include "config.w32.h"
-# undef strcasecmp
-# undef strncasecmp
-# define strcasecmp _stricmp
-# define strncasecmp _strnicmp
+# include <windows.h>
+# include "config.w32.h"
+# undef strcasecmp
+# undef strncasecmp
+# define strcasecmp _stricmp
+# define strncasecmp _strnicmp
#else
-# include "php_config.h"
+# include "php_config.h"
#endif
#ifndef O_BINARY
# define O_BINARY 0
@@ -64,21 +70,52 @@
# include "TSRM.h"
#endif
-#ifdef LIBREADLINE
-# include <readline/readline.h>
-# include <readline/history.h>
+#undef zend_hash_str_add
+#ifdef PHP_WIN32
+#define zend_hash_str_add(...) \
+ _zend_hash_str_add(__VA_ARGS__ ZEND_FILE_LINE_CC)
+#else
+#define zend_hash_str_add_tmp(ht, key, len, pData) \
+ _zend_hash_str_add(ht, key, len, pData ZEND_FILE_LINE_CC)
+#define zend_hash_str_add(...) zend_hash_str_add_tmp(__VA_ARGS__)
+#endif
+
+#ifdef HAVE_LIBREADLINE
+# include <readline/readline.h>
+# include <readline/history.h>
#endif
#ifdef HAVE_LIBEDIT
-# include <editline/readline.h>
+# include <editline/readline.h>
#endif
-#include "phpdbg_lexer.h"
-#include "phpdbg_cmd.h"
-#include "phpdbg_utils.h"
-#include "phpdbg_btree.h"
-#include "phpdbg_watch.h"
+/* {{{ remote console headers */
+#ifndef _WIN32
+# include <sys/socket.h>
+# include <sys/un.h>
+# include <sys/select.h>
+# include <sys/types.h>
+# include <netdb.h>
+#endif /* }}} */
-int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC);
+/* {{{ strings */
+#define PHPDBG_NAME "phpdbg"
+#define PHPDBG_AUTHORS "Felipe Pena, Joe Watkins and Bob Weinand" /* Ordered by last name */
+#define PHPDBG_ISSUES "http://bugs.php.net/report.php"
+#define PHPDBG_VERSION "0.5.0"
+#define PHPDBG_INIT_FILENAME ".phpdbginit"
+#define PHPDBG_DEFAULT_PROMPT "prompt>"
+/* }}} */
+
+/* Hey, apple. One shouldn't define *functions* from the standard C library as marcos. */
+#ifdef memcpy
+#define memcpy_tmp(...) memcpy(__VA_ARGS__)
+#undef memcpy
+#define memcpy(...) memcpy_tmp(__VA_ARGS__)
+#endif
+
+#define quiet_write(...) ZEND_IGNORE_VALUE(write(__VA_ARGS__))
+
+#if !defined(PHPDBG_WEBDATA_TRANSFER_H) && !defined(PHPDBG_WEBHELPER_H)
#ifdef ZTS
# define PHPDBG_G(v) TSRMG(phpdbg_globals_id, zend_phpdbg_globals *, v)
@@ -86,6 +123,21 @@ int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC);
# define PHPDBG_G(v) (phpdbg_globals.v)
#endif
+#include "phpdbg_sigsafe.h"
+#include "phpdbg_out.h"
+#include "phpdbg_lexer.h"
+#include "phpdbg_cmd.h"
+#include "phpdbg_utils.h"
+#include "phpdbg_btree.h"
+#include "phpdbg_watch.h"
+#include "phpdbg_bp.h"
+#include "phpdbg_opcode.h"
+#ifdef PHP_WIN32
+# include "phpdbg_sigio_win32.h"
+#endif
+
+int phpdbg_do_parse(phpdbg_param_t *stack, char *input);
+
#define PHPDBG_NEXT 2
#define PHPDBG_UNTIL 3
#define PHPDBG_FINISH 4
@@ -95,92 +147,100 @@ int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC);
BEGIN: DO NOT CHANGE DO NOT CHANGE DO NOT CHANGE
*/
-/* {{{ tables */
-#define PHPDBG_BREAK_FILE 0
-#define PHPDBG_BREAK_SYM 1
-#define PHPDBG_BREAK_OPLINE 2
-#define PHPDBG_BREAK_METHOD 3
-#define PHPDBG_BREAK_COND 4
-#define PHPDBG_BREAK_OPCODE 5
-#define PHPDBG_BREAK_FUNCTION_OPLINE 6
-#define PHPDBG_BREAK_METHOD_OPLINE 7
-#define PHPDBG_BREAK_FILE_OPLINE 8
-#define PHPDBG_BREAK_MAP 9
-#define PHPDBG_BREAK_TABLES 10 /* }}} */
-
/* {{{ flags */
-#define PHPDBG_HAS_FILE_BP (1<<1)
-#define PHPDBG_HAS_SYM_BP (1<<2)
-#define PHPDBG_HAS_OPLINE_BP (1<<3)
-#define PHPDBG_HAS_METHOD_BP (1<<4)
-#define PHPDBG_HAS_COND_BP (1<<5)
-#define PHPDBG_HAS_OPCODE_BP (1<<6)
-#define PHPDBG_HAS_FUNCTION_OPLINE_BP (1<<7)
-#define PHPDBG_HAS_METHOD_OPLINE_BP (1<<8)
-#define PHPDBG_HAS_FILE_OPLINE_BP (1<<9) /* }}} */
+#define PHPDBG_HAS_FILE_BP (1ULL<<1)
+#define PHPDBG_HAS_PENDING_FILE_BP (1ULL<<2)
+#define PHPDBG_HAS_SYM_BP (1ULL<<3)
+#define PHPDBG_HAS_OPLINE_BP (1ULL<<4)
+#define PHPDBG_HAS_METHOD_BP (1ULL<<5)
+#define PHPDBG_HAS_COND_BP (1ULL<<6)
+#define PHPDBG_HAS_OPCODE_BP (1ULL<<7)
+#define PHPDBG_HAS_FUNCTION_OPLINE_BP (1ULL<<8)
+#define PHPDBG_HAS_METHOD_OPLINE_BP (1ULL<<9)
+#define PHPDBG_HAS_FILE_OPLINE_BP (1ULL<<10) /* }}} */
/*
END: DO NOT CHANGE DO NOT CHANGE DO NOT CHANGE
*/
-#define PHPDBG_IN_COND_BP (1<<10)
-#define PHPDBG_IN_EVAL (1<<11)
+#define PHPDBG_IN_COND_BP (1ULL<<11)
+#define PHPDBG_IN_EVAL (1ULL<<12)
-#define PHPDBG_IS_STEPPING (1<<12)
-#define PHPDBG_STEP_OPCODE (1<<13)
-#define PHPDBG_IS_QUIET (1<<14)
-#define PHPDBG_IS_QUITTING (1<<15)
-#define PHPDBG_IS_COLOURED (1<<16)
-#define PHPDBG_IS_CLEANING (1<<17)
+#define PHPDBG_IS_STEPPING (1ULL<<13)
+#define PHPDBG_STEP_OPCODE (1ULL<<14)
+#define PHPDBG_IS_QUIET (1ULL<<15)
+#define PHPDBG_IS_QUITTING (1ULL<<16)
+#define PHPDBG_IS_COLOURED (1ULL<<17)
+#define PHPDBG_IS_CLEANING (1ULL<<18)
+#define PHPDBG_IS_RUNNING (1ULL<<19)
-#define PHPDBG_IN_UNTIL (1<<18)
-#define PHPDBG_IN_FINISH (1<<19)
-#define PHPDBG_IN_LEAVE (1<<20)
+#define PHPDBG_IN_UNTIL (1ULL<<20)
+#define PHPDBG_IN_FINISH (1ULL<<21)
+#define PHPDBG_IN_LEAVE (1ULL<<22)
-#define PHPDBG_IS_REGISTERED (1<<21)
-#define PHPDBG_IS_STEPONEVAL (1<<22)
-#define PHPDBG_IS_INITIALIZING (1<<23)
-#define PHPDBG_IS_SIGNALED (1<<24)
-#define PHPDBG_IS_INTERACTIVE (1<<25)
-#define PHPDBG_IS_BP_ENABLED (1<<26)
-#define PHPDBG_IS_REMOTE (1<<27)
-#define PHPDBG_IS_DISCONNECTED (1<<28)
+#define PHPDBG_IS_REGISTERED (1ULL<<23)
+#define PHPDBG_IS_STEPONEVAL (1ULL<<24)
+#define PHPDBG_IS_INITIALIZING (1ULL<<25)
+#define PHPDBG_IS_SIGNALED (1ULL<<26)
+#define PHPDBG_IS_INTERACTIVE (1ULL<<27)
+#define PHPDBG_PREVENT_INTERACTIVE (1ULL<<28)
+#define PHPDBG_IS_BP_ENABLED (1ULL<<29)
+#define PHPDBG_IS_REMOTE (1ULL<<30)
+#define PHPDBG_IS_DISCONNECTED (1ULL<<31)
+#define PHPDBG_WRITE_XML (1ULL<<32)
-#define PHPDBG_SHOW_REFCOUNTS (1<<29)
+#define PHPDBG_SHOW_REFCOUNTS (1ULL<<33)
-#define PHPDBG_SEEK_MASK (PHPDBG_IN_UNTIL|PHPDBG_IN_FINISH|PHPDBG_IN_LEAVE)
-#define PHPDBG_BP_RESOLVE_MASK (PHPDBG_HAS_FUNCTION_OPLINE_BP|PHPDBG_HAS_METHOD_OPLINE_BP|PHPDBG_HAS_FILE_OPLINE_BP)
-#define PHPDBG_BP_MASK (PHPDBG_HAS_FILE_BP|PHPDBG_HAS_SYM_BP|PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_OPLINE_BP|PHPDBG_HAS_COND_BP|PHPDBG_HAS_OPCODE_BP|PHPDBG_HAS_FUNCTION_OPLINE_BP|PHPDBG_HAS_METHOD_OPLINE_BP|PHPDBG_HAS_FILE_OPLINE_BP)
+#define PHPDBG_IN_SIGNAL_HANDLER (1ULL<<34)
+
+#define PHPDBG_DISCARD_OUTPUT (1ULL<<35)
+
+#define PHPDBG_HAS_PAGINATION (1ULL<<36)
+
+#define PHPDBG_SEEK_MASK (PHPDBG_IN_UNTIL | PHPDBG_IN_FINISH | PHPDBG_IN_LEAVE)
+#define PHPDBG_BP_RESOLVE_MASK (PHPDBG_HAS_FUNCTION_OPLINE_BP | PHPDBG_HAS_METHOD_OPLINE_BP | PHPDBG_HAS_FILE_OPLINE_BP)
+#define PHPDBG_BP_MASK (PHPDBG_HAS_FILE_BP | PHPDBG_HAS_SYM_BP | PHPDBG_HAS_METHOD_BP | PHPDBG_HAS_OPLINE_BP | PHPDBG_HAS_COND_BP | PHPDBG_HAS_OPCODE_BP | PHPDBG_HAS_FUNCTION_OPLINE_BP | PHPDBG_HAS_METHOD_OPLINE_BP | PHPDBG_HAS_FILE_OPLINE_BP)
+#define PHPDBG_IS_STOPPING (PHPDBG_IS_QUITTING | PHPDBG_IS_CLEANING)
+
+#define PHPDBG_PRESERVE_FLAGS_MASK (PHPDBG_SHOW_REFCOUNTS | PHPDBG_IS_STEPONEVAL | PHPDBG_IS_BP_ENABLED | PHPDBG_STEP_OPCODE | PHPDBG_IS_QUIET | PHPDBG_IS_COLOURED | PHPDBG_IS_REMOTE | PHPDBG_WRITE_XML | PHPDBG_IS_DISCONNECTED | PHPDBG_HAS_PAGINATION)
#ifndef _WIN32
-# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_COLOURED|PHPDBG_IS_BP_ENABLED)
+# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET | PHPDBG_IS_COLOURED | PHPDBG_IS_BP_ENABLED | PHPDBG_HAS_PAGINATION)
#else
-# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET|PHPDBG_IS_BP_ENABLED)
+# define PHPDBG_DEFAULT_FLAGS (PHPDBG_IS_QUIET | PHPDBG_IS_BP_ENABLED | PHPDBG_HAS_PAGINATION)
#endif /* }}} */
-/* {{{ strings */
-#define PHPDBG_NAME "phpdbg"
-#define PHPDBG_AUTHORS "Felipe Pena, Joe Watkins and Bob Weinand" /* Ordered by last name */
-#define PHPDBG_URL "http://phpdbg.com"
-#define PHPDBG_ISSUES "http://github.com/krakjoe/phpdbg/issues"
-#define PHPDBG_VERSION "0.4.0"
-#define PHPDBG_INIT_FILENAME ".phpdbginit"
-/* }}} */
-
/* {{{ output descriptors */
#define PHPDBG_STDIN 0
#define PHPDBG_STDOUT 1
#define PHPDBG_STDERR 2
#define PHPDBG_IO_FDS 3 /* }}} */
+#define phpdbg_try_access \
+ { \
+ JMP_BUF *__orig_bailout = PHPDBG_G(sigsegv_bailout); \
+ JMP_BUF __bailout; \
+ \
+ PHPDBG_G(sigsegv_bailout) = &__bailout; \
+ if (SETJMP(__bailout) == 0) {
+#define phpdbg_catch_access \
+ } else { \
+ PHPDBG_G(sigsegv_bailout) = __orig_bailout;
+#define phpdbg_end_try_access() \
+ } \
+ PHPDBG_G(sigsegv_bailout) = __orig_bailout; \
+ }
+
/* {{{ structs */
ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
HashTable bp[PHPDBG_BREAK_TABLES]; /* break points */
HashTable registered; /* registered */
HashTable seek; /* seek oplines */
+ zend_execute_data *seek_ex; /* call frame of oplines to seek to */
+ zend_object *handled_exception; /* last handled exception (prevent multiple handling of same exception) */
phpdbg_frame_t frame; /* frame */
- zend_uint last_line; /* last executed line */
+ uint32_t last_line; /* last executed line */
phpdbg_lexer_data lexer; /* lexer data */
phpdbg_param_t *parser_stack; /* param stack during lexer / parser phase */
@@ -191,40 +251,74 @@ ZEND_BEGIN_MODULE_GLOBALS(phpdbg)
phpdbg_btree watchpoint_tree; /* tree with watchpoints */
phpdbg_btree watch_HashTables; /* tree with original dtors of watchpoints */
HashTable watchpoints; /* watchpoints */
+ HashTable watch_collisions; /* collision table to check if multiple watches share the same recursive watchpoint */
zend_llist watchlist_mem; /* triggered watchpoints */
zend_bool watchpoint_hit; /* a watchpoint was hit */
void (*original_free_function)(void *); /* the original AG(mm_heap)->_free function */
+ phpdbg_watchpoint_t *watch_tmp; /* temporary pointer for a watchpoint */
char *exec; /* file to execute */
size_t exec_len; /* size of exec */
zend_op_array *ops; /* op_array */
- zval *retval; /* return value */
+ zval retval; /* return value */
int bp_count; /* breakpoint count */
int vmret; /* return from last opcode handler execution */
+ zend_bool in_execution; /* in execution? */
+ zend_bool unclean_eval; /* do not check for memory leaks when we needed to bail out during eval */
+
+ zend_op_array *(*compile_file)(zend_file_handle *file_handle, int type);
+ zend_op_array *(*init_compile_file)(zend_file_handle *file_handle, int type);
+ zend_op_array *(*compile_string)(zval *source_string, char *filename);
+ HashTable file_sources;
FILE *oplog; /* opline log */
- FILE *io[PHPDBG_IO_FDS]; /* io */
+ zend_arena *oplog_arena; /* arena for storing oplog */
+ phpdbg_oplog_list *oplog_list; /* list of oplog starts */
+ phpdbg_oplog_entry *oplog_cur; /* current oplog entry */
+
+ struct {
+ FILE *ptr;
+ int fd;
+ } io[PHPDBG_IO_FDS]; /* io */
+ int eol; /* type of line ending to use */
+ size_t (*php_stdiop_write)(php_stream *, const char *, size_t);
+ int in_script_xml; /* in <stream> output mode */
+ struct {
+ zend_bool active;
+ int type;
+ int fd;
+ char *tag;
+ char *msg;
+ int msglen;
+ char *xml;
+ int xmllen;
+ } err_buf; /* error buffer */
+ zend_ulong req_id; /* "request id" to keep track of commands */
char *prompt[2]; /* prompt */
const phpdbg_color_t *colors[PHPDBG_COLORS]; /* colors */
char *buffer; /* buffer */
+ zend_bool last_was_newline; /* check if we don't need to output a newline upon next phpdbg_error or phpdbg_notice */
- zend_ulong flags; /* phpdbg flags */
+ char input_buffer[PHPDBG_MAX_CMD]; /* stdin input buffer */
+ int input_buflen; /* length of stdin input buffer */
+ phpdbg_signal_safe_mem sigsafe_mem; /* memory to use in async safe environment (only once!) */
+
+ JMP_BUF *sigsegv_bailout; /* bailout address for accesibility probing */
+
+ uint64_t flags; /* phpdbg flags */
+
+ char *socket_path; /* phpdbg.path ini setting */
+ char *sapi_name_ptr; /* store sapi name to free it if necessary to not leak memory */
+ int socket_fd; /* file descriptor to socket (wait command) (-1 if unused) */
+ int socket_server_fd; /* file descriptor to master socket (wait command) (-1 if unused) */
+#ifdef PHP_WIN32
+ HANDLE sigio_watcher_thread; /* sigio watcher thread handle */
+ struct win32_sigio_watcher_data swd;
+#endif
+ long lines; /* max number of lines to display */
ZEND_END_MODULE_GLOBALS(phpdbg) /* }}} */
-/* the beginning (= the important part) of the _zend_mm_heap struct defined in Zend/zend_alloc.c
- Needed for realizing watchpoints */
-struct _zend_mm_heap {
- int use_zend_alloc;
- void *(*_malloc)(size_t);
- void (*_free)(void *);
- void *(*_realloc)(void *, size_t);
- size_t free_bitmap;
- size_t large_free_bitmap;
- size_t block_size;
- size_t compact_size;
- zend_mm_segment *segments_list;
- zend_mm_storage *storage;
-};
+#endif
#endif /* PHPDBG_H */
diff --git a/sapi/phpdbg/phpdbg_bp.c b/sapi/phpdbg/phpdbg_bp.c
index 3122a9f609..c90623a03b 100644
--- a/sapi/phpdbg/phpdbg_bp.c
+++ b/sapi/phpdbg/phpdbg_bp.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -29,25 +29,25 @@
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
/* {{{ private api functions */
-static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array* TSRMLS_DC);
-static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_symbol(zend_function* TSRMLS_DC);
-static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_method(zend_op_array* TSRMLS_DC);
-static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t TSRMLS_DC);
-static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opcode(zend_uchar TSRMLS_DC);
-static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execute_data *execute_data TSRMLS_DC); /* }}} */
+static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array*);
+static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_symbol(zend_function*);
+static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_method(zend_op_array*);
+static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t);
+static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opcode(zend_uchar);
+static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execute_data *execute_data); /* }}} */
/*
* Note:
* A break point must always set the correct id and type
* A set breakpoint function must always map new points
*/
-static inline void _phpdbg_break_mapping(int id, HashTable *table TSRMLS_DC)
+static inline void _phpdbg_break_mapping(int id, HashTable *table) /* {{{ */
{
- zend_hash_index_update(
- &PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (id), (void**) &table, sizeof(void*), NULL);
+ zend_hash_index_update_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id, table);
}
+/* }}} */
-#define PHPDBG_BREAK_MAPPING(id, table) _phpdbg_break_mapping(id, table TSRMLS_CC)
+#define PHPDBG_BREAK_MAPPING(id, table) _phpdbg_break_mapping(id, table)
#define PHPDBG_BREAK_UNMAPPING(id) \
zend_hash_index_del(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (id))
@@ -58,29 +58,32 @@ static inline void _phpdbg_break_mapping(int id, HashTable *table TSRMLS_DC)
b.hits = 0; \
} while(0)
-static void phpdbg_file_breaks_dtor(void *data) /* {{{ */
+static void phpdbg_file_breaks_dtor(zval *data) /* {{{ */
{
- phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) data;
+ phpdbg_breakfile_t *bp = (phpdbg_breakfile_t*) Z_PTR_P(data);
efree((char*)bp->filename);
+ efree(bp);
} /* }}} */
-static void phpdbg_class_breaks_dtor(void *data) /* {{{ */
+static void phpdbg_class_breaks_dtor(zval *data) /* {{{ */
{
- phpdbg_breakmethod_t *bp = (phpdbg_breakmethod_t*) data;
+ phpdbg_breakmethod_t *bp = (phpdbg_breakmethod_t *) Z_PTR_P(data);
efree((char*)bp->class_name);
efree((char*)bp->func_name);
+ efree(bp);
} /* }}} */
-static void phpdbg_opline_class_breaks_dtor(void *data) /* {{{ */
+static void phpdbg_opline_class_breaks_dtor(zval *data) /* {{{ */
{
- zend_hash_destroy((HashTable *)data);
+ zend_hash_destroy(Z_ARRVAL_P(data));
+ efree(Z_ARRVAL_P(data));
} /* }}} */
-static void phpdbg_opline_breaks_dtor(void *data) /* {{{ */
+static void phpdbg_opline_breaks_dtor(zval *data) /* {{{ */
{
- phpdbg_breakopline_t *bp = (phpdbg_breakopline_t *) data;
+ phpdbg_breakopline_t *bp = (phpdbg_breakopline_t *) Z_PTR_P(data);
if (bp->class_name) {
efree((char*)bp->class_name);
@@ -88,96 +91,94 @@ static void phpdbg_opline_breaks_dtor(void *data) /* {{{ */
if (bp->func_name) {
efree((char*)bp->func_name);
}
+ efree(bp);
} /* }}} */
-PHPDBG_API void phpdbg_reset_breakpoints(TSRMLS_D) /* {{{ */
+PHPDBG_API void phpdbg_reset_breakpoints(void) /* {{{ */
{
- if (zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])) {
- HashPosition position[2];
- HashTable **table = NULL;
+ HashTable *table;
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0]);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (void**)&table, &position[0]) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0])) {
- phpdbg_breakbase_t *brake;
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], table) {
+ phpdbg_breakbase_t *brake;
- for (zend_hash_internal_pointer_reset_ex((*table), &position[1]);
- zend_hash_get_current_data_ex((*table), (void**)&brake, &position[1]) == SUCCESS;
- zend_hash_move_forward_ex((*table), &position[1])) {
- brake->hits = 0;
- }
- }
- }
+ ZEND_HASH_FOREACH_PTR(table, brake) {
+ brake->hits = 0;
+ } ZEND_HASH_FOREACH_END();
+ } ZEND_HASH_FOREACH_END();
} /* }}} */
-PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_export_breakpoints(FILE *handle) /* {{{ */
{
- HashPosition position[2];
- HashTable **table = NULL;
+ char *string;
+ phpdbg_export_breakpoints_to_string(&string);
+ fputs(string, handle);
+}
+/* }}} */
+
+PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str) /* {{{ */
+{
+ HashTable *table;
zend_ulong id = 0L;
+ *str = "";
+
if (zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP])) {
- phpdbg_notice(
- "Exporting %d breakpoints",
- zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP]));
+ phpdbg_notice("exportbreakpoint", "count=\"%d\"", "Exporting %d breakpoints", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP]));
+
/* this only looks like magic, it isn't */
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0]);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], (void**)&table, &position[0]) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], &position[0])) {
+ ZEND_HASH_FOREACH_NUM_KEY_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id, table) {
phpdbg_breakbase_t *brake;
- zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], NULL, NULL, &id, 0, &position[0]);
-
- for (zend_hash_internal_pointer_reset_ex((*table), &position[1]);
- zend_hash_get_current_data_ex((*table), (void**)&brake, &position[1]) == SUCCESS;
- zend_hash_move_forward_ex((*table), &position[1])) {
+ ZEND_HASH_FOREACH_PTR(table, brake) {
if (brake->id == id) {
+ char *new_str = NULL;
+
switch (brake->type) {
case PHPDBG_BREAK_FILE: {
- fprintf(handle,
- "break %s:%lu\n",
+ phpdbg_asprintf(&new_str,
+ "%sbreak %s:%lu\n", *str,
((phpdbg_breakfile_t*)brake)->filename,
((phpdbg_breakfile_t*)brake)->line);
} break;
case PHPDBG_BREAK_SYM: {
- fprintf(handle,
- "break %s\n",
+ phpdbg_asprintf(&new_str,
+ "%sbreak %s\n", *str,
((phpdbg_breaksymbol_t*)brake)->symbol);
} break;
case PHPDBG_BREAK_METHOD: {
- fprintf(handle,
- "break %s::%s\n",
+ phpdbg_asprintf(&new_str,
+ "%sbreak %s::%s\n", *str,
((phpdbg_breakmethod_t*)brake)->class_name,
((phpdbg_breakmethod_t*)brake)->func_name);
} break;
case PHPDBG_BREAK_METHOD_OPLINE: {
- fprintf(handle,
- "break %s::%s#%ld\n",
+ phpdbg_asprintf(&new_str,
+ "%sbreak %s::%s#%llu\n", *str,
((phpdbg_breakopline_t*)brake)->class_name,
((phpdbg_breakopline_t*)brake)->func_name,
((phpdbg_breakopline_t*)brake)->opline_num);
} break;
case PHPDBG_BREAK_FUNCTION_OPLINE: {
- fprintf(handle,
- "break %s#%ld\n",
+ phpdbg_asprintf(&new_str,
+ "%sbreak %s#%llu\n", *str,
((phpdbg_breakopline_t*)brake)->func_name,
((phpdbg_breakopline_t*)brake)->opline_num);
} break;
case PHPDBG_BREAK_FILE_OPLINE: {
- fprintf(handle,
- "break %s:#%ld\n",
+ phpdbg_asprintf(&new_str,
+ "%sbreak %s:#%llu\n", *str,
((phpdbg_breakopline_t*)brake)->class_name,
((phpdbg_breakopline_t*)brake)->opline_num);
} break;
case PHPDBG_BREAK_OPCODE: {
- fprintf(handle,
- "break %s\n",
+ phpdbg_asprintf(&new_str,
+ "%sbreak %s\n", *str,
((phpdbg_breakop_t*)brake)->name);
} break;
@@ -187,20 +188,20 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */
if (conditional->paramed) {
switch (conditional->param.type) {
case STR_PARAM:
- fprintf(handle,
- "break at %s if %s\n", conditional->param.str, conditional->code);
+ phpdbg_asprintf(&new_str,
+ "%sbreak at %s if %s\n", *str, conditional->param.str, conditional->code);
break;
case METHOD_PARAM:
- fprintf(handle,
- "break at %s::%s if %s\n",
+ phpdbg_asprintf(&new_str,
+ "%sbreak at %s::%s if %s\n", *str,
conditional->param.method.class, conditional->param.method.name,
conditional->code);
break;
case FILE_PARAM:
- fprintf(handle,
- "break at %s:%lu if %s\n",
+ phpdbg_asprintf(&new_str,
+ "%sbreak at %s:%lu if %s\n", *str,
conditional->param.file.name, conditional->param.file.line,
conditional->code);
break;
@@ -208,73 +209,186 @@ PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC) /* {{{ */
default: { /* do nothing */ } break;
}
} else {
- fprintf(
- handle, "break if %s\n", conditional->code);
+ phpdbg_asprintf(&new_str, "%sbreak if %s\n", str, conditional->code);
}
} break;
+
+ default: continue;
+ }
+
+ if ((*str)[0]) {
+ efree(*str);
}
+ *str = new_str;
}
- }
- }
+ } ZEND_HASH_FOREACH_END();
+ } ZEND_HASH_FOREACH_END();
+ }
+
+ if (!(*str)[0]) {
+ *str = NULL;
}
} /* }}} */
-PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_breakpoint_file(const char *path, long line_num) /* {{{ */
{
php_stream_statbuf ssb;
char realpath[MAXPATHLEN];
-
- if (php_stream_stat_path(path, &ssb) != FAILURE) {
- if (ssb.sb.st_mode & (S_IFREG|S_IFLNK)) {
- HashTable *broken;
- phpdbg_breakfile_t new_break;
- size_t path_len = 0L;
-
- if (VCWD_REALPATH(path, realpath)) {
- path = realpath;
+ const char *original_path = path;
+ zend_bool pending = 0;
+ zend_string *path_str;
+
+ HashTable *broken, *file_breaks = &PHPDBG_G(bp)[PHPDBG_BREAK_FILE];
+ phpdbg_breakfile_t new_break;
+ size_t path_len = 0L;
+
+ if (VCWD_REALPATH(path, realpath)) {
+ path = realpath;
+ }
+ path_len = strlen(path);
+
+ phpdbg_debug("file path: %s, resolved path: %s, was compiled: %d\n", original_path, path, zend_hash_str_exists(&PHPDBG_G(file_sources), path, path_len));
+
+ if (!zend_hash_str_exists(&PHPDBG_G(file_sources), path, path_len)) {
+ if (php_stream_stat_path(path, &ssb) == FAILURE) {
+ if (original_path[0] == '/') {
+ phpdbg_error("breakpoint", "type=\"nofile\" add=\"fail\" file=\"%s\"", "Cannot stat %s, it does not exist", original_path);
+ return;
}
+
+ file_breaks = &PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING];
+ path = original_path;
path_len = strlen(path);
-
- if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE],
- path, path_len, (void**)&broken) == FAILURE) {
- HashTable breaks;
+ pending = 1;
+ } else if (!(ssb.sb.st_mode & (S_IFREG|S_IFLNK))) {
+ phpdbg_error("breakpoint", "type=\"notregular\" add=\"fail\" file=\"%s\"", "Cannot set breakpoint in %s, it is not a regular file", path);
+ return;
+ } else {
+ phpdbg_debug("File exists, but not compiled\n");
+ }
+ }
- zend_hash_init(&breaks, 8, NULL, phpdbg_file_breaks_dtor, 0);
+ path_str = zend_string_init(path, path_len, 0);
- zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE],
- path, path_len, &breaks, sizeof(HashTable),
- (void**)&broken);
- }
+ if (!(broken = zend_hash_find_ptr(file_breaks, path_str))) {
+ HashTable breaks;
+ zend_hash_init(&breaks, 8, NULL, phpdbg_file_breaks_dtor, 0);
- if (!zend_hash_index_exists(broken, line_num)) {
- PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP;
+ broken = zend_hash_add_mem(file_breaks, path_str, &breaks, sizeof(HashTable));
+ }
- PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_FILE);
- new_break.filename = estrndup(path, path_len);
- new_break.line = line_num;
+ if (!zend_hash_index_exists(broken, line_num)) {
+ PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_FILE);
+ new_break.filename = estrndup(path, path_len);
+ new_break.line = line_num;
- zend_hash_index_update(
- broken, line_num, (void**)&new_break, sizeof(phpdbg_breakfile_t), NULL);
+ zend_hash_index_update_mem(broken, line_num, &new_break, sizeof(phpdbg_breakfile_t));
- phpdbg_notice("Breakpoint #%d added at %s:%ld",
- new_break.id, new_break.filename, new_break.line);
+ PHPDBG_BREAK_MAPPING(new_break.id, broken);
- PHPDBG_BREAK_MAPPING(new_break.id, broken);
- } else {
- phpdbg_error("Breakpoint at %s:%ld exists", path, line_num);
- }
+ if (pending) {
+ zend_string *file;
+ ZEND_HASH_FOREACH_STR_KEY(&PHPDBG_G(file_sources), file) {
+ HashTable *fileht;
+
+ phpdbg_debug("Compare against loaded %s\n", file);
+
+ if (!(pending = ((fileht = phpdbg_resolve_pending_file_break_ex(ZSTR_VAL(file), ZSTR_LEN(file), path_str, broken)) == NULL))) {
+ new_break = *(phpdbg_breakfile_t *) zend_hash_index_find_ptr(fileht, line_num);
+ break;
+ }
+ } ZEND_HASH_FOREACH_END();
+ }
+
+ if (pending) {
+ PHPDBG_G(flags) |= PHPDBG_HAS_PENDING_FILE_BP;
+ phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" file=\"%s\" line=\"%ld\" pending=\"pending\"", "Pending breakpoint #%d added at %s:%ld", new_break.id, new_break.filename, new_break.line);
} else {
- phpdbg_error("Cannot set breakpoint in %s, it is not a regular file", path);
+ PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP;
+
+ phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" file=\"%s\" line=\"%ld\"", "Breakpoint #%d added at %s:%ld", new_break.id, new_break.filename, new_break.line);
}
} else {
- phpdbg_error("Cannot stat %s, it does not exist", path);
+ phpdbg_error("breakpoint", "type=\"exists\" add=\"fail\" file=\"%s\" line=\"%ld\"", "Breakpoint at %s:%ld exists", path, line_num);
+ }
+
+ zend_string_release(path_str);
+} /* }}} */
+
+PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uint filelen, zend_string *cur, HashTable *fileht) /* {{{ */
+{
+ phpdbg_debug("file: %s, filelen: %u, cur: %s, curlen %u, pos: %c, memcmp: %d\n", file, filelen, ZSTR_VAL(cur), ZSTR_LEN(cur), filelen > ZSTR_LEN(cur) ? file[filelen - ZSTR_LEN(cur) - 1] : '?', filelen > ZSTR_LEN(cur) ? memcmp(file + filelen - ZSTR_LEN(cur), ZSTR_VAL(cur), ZSTR_LEN(cur)) : 0);
+
+#ifdef _WIN32
+# define WIN32_PATH_CHECK file[filelen - ZSTR_LEN(cur) - 1] == '\\'
+#else
+# define WIN32_PATH_CHECK 0
+#endif
+
+ if (((ZSTR_LEN(cur) < filelen && (file[filelen - ZSTR_LEN(cur) - 1] == '/' || WIN32_PATH_CHECK)) || filelen == ZSTR_LEN(cur)) && !memcmp(file + filelen - ZSTR_LEN(cur), ZSTR_VAL(cur), ZSTR_LEN(cur))) {
+ phpdbg_breakfile_t *brake, new_brake;
+ HashTable *master;
+
+ PHPDBG_G(flags) |= PHPDBG_HAS_FILE_BP;
+
+ if (!(master = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen))) {
+ HashTable new_ht;
+ zend_hash_init(&new_ht, 8, NULL, phpdbg_file_breaks_dtor, 0);
+ master = zend_hash_str_add_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], file, filelen, &new_ht, sizeof(HashTable));
+ }
+
+ ZEND_HASH_FOREACH_PTR(fileht, brake) {
+ new_brake = *brake;
+ new_brake.filename = estrndup(file, filelen);
+ PHPDBG_BREAK_UNMAPPING(brake->id);
+
+ if (zend_hash_index_add_mem(master, brake->line, &new_brake, sizeof(phpdbg_breakfile_t))) {
+ PHPDBG_BREAK_MAPPING(brake->id, master);
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ zend_hash_del(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], cur);
+
+ if (!zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING])) {
+ PHPDBG_G(flags) &= ~PHPDBG_HAS_PENDING_FILE_BP;
+ }
+
+ phpdbg_debug("compiled file: %s, cur bp file: %s\n", file, cur);
+
+ return master;
}
+
+ return NULL;
+} /* }}} */
+
+PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file) /* {{{ */
+{
+ HashTable *fileht;
+ uint filelen = strlen(file);
+ zend_string *cur;
+
+ phpdbg_debug("was compiled: %s\n", file);
+
+ ZEND_HASH_FOREACH_STR_KEY_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], cur, fileht) {
+ phpdbg_debug("check bp: %s\n", cur);
+
+ phpdbg_resolve_pending_file_break_ex(file, filelen, cur, fileht);
+ } ZEND_HASH_FOREACH_END();
} /* }}} */
-PHPDBG_API void phpdbg_set_breakpoint_symbol(const char *name, size_t name_len TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_breakpoint_symbol(const char *name, size_t name_len) /* {{{ */
{
- if (!zend_hash_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], name, name_len)) {
+ char *lcname;
+
+ if (*name == '\\') {
+ name++;
+ name_len--;
+ }
+
+ lcname = zend_str_tolower_dup(name, name_len);
+
+ if (!zend_hash_str_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], name, name_len)) {
phpdbg_breaksymbol_t new_break;
PHPDBG_G(flags) |= PHPDBG_HAS_SYM_BP;
@@ -282,35 +396,39 @@ PHPDBG_API void phpdbg_set_breakpoint_symbol(const char *name, size_t name_len T
PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_SYM);
new_break.symbol = estrndup(name, name_len);
- zend_hash_update(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], new_break.symbol,
- name_len, &new_break, sizeof(phpdbg_breaksymbol_t), NULL);
+ zend_hash_str_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], lcname, name_len, &new_break, sizeof(phpdbg_breaksymbol_t));
- phpdbg_notice("Breakpoint #%d added at %s",
- new_break.id, new_break.symbol);
+ phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" function=\"%s\"", "Breakpoint #%d added at %s", new_break.id, new_break.symbol);
PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_SYM]);
} else {
- phpdbg_notice("Breakpoint exists at %s", name);
+ phpdbg_error("breakpoint", "type=\"exists\" add=\"fail\" function=\"%s\"", "Breakpoint exists at %s", name);
}
+
+ efree(lcname);
} /* }}} */
-PHPDBG_API void phpdbg_set_breakpoint_method(const char *class_name, const char *func_name TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_breakpoint_method(const char *class_name, const char *func_name) /* {{{ */
{
HashTable class_breaks, *class_table;
size_t class_len = strlen(class_name);
size_t func_len = strlen(func_name);
- char *lcname = zend_str_tolower_dup(func_name, func_len);
+ char *func_lcname, *class_lcname;
- if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_name,
- class_len, (void**)&class_table) != SUCCESS) {
+ if (*class_name == '\\') {
+ class_name++;
+ class_len--;
+ }
+
+ func_lcname = zend_str_tolower_dup(func_name, func_len);
+ class_lcname = zend_str_tolower_dup(class_name, class_len);
+
+ if (!(class_table = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_lcname, class_len))) {
zend_hash_init(&class_breaks, 8, NULL, phpdbg_class_breaks_dtor, 0);
- zend_hash_update(
- &PHPDBG_G(bp)[PHPDBG_BREAK_METHOD],
- class_name, class_len,
- (void**)&class_breaks, sizeof(HashTable), (void**)&class_table);
+ class_table = zend_hash_str_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_lcname, class_len, &class_breaks, sizeof(HashTable));
}
- if (!zend_hash_exists(class_table, lcname, func_len)) {
+ if (!zend_hash_str_exists(class_table, func_lcname, func_len)) {
phpdbg_breakmethod_t new_break;
PHPDBG_G(flags) |= PHPDBG_HAS_METHOD_BP;
@@ -321,21 +439,20 @@ PHPDBG_API void phpdbg_set_breakpoint_method(const char *class_name, const char
new_break.func_name = estrndup(func_name, func_len);
new_break.func_len = func_len;
- zend_hash_update(class_table, lcname, func_len,
- &new_break, sizeof(phpdbg_breakmethod_t), NULL);
+ zend_hash_str_update_mem(class_table, func_lcname, func_len, &new_break, sizeof(phpdbg_breakmethod_t));
- phpdbg_notice("Breakpoint #%d added at %s::%s",
- new_break.id, class_name, func_name);
+ phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" method=\"%s::%s\"", "Breakpoint #%d added at %s::%s", new_break.id, class_name, func_name);
PHPDBG_BREAK_MAPPING(new_break.id, class_table);
} else {
- phpdbg_notice("Breakpoint exists at %s::%s", class_name, func_name);
+ phpdbg_error("breakpoint", "type=\"exists\" add=\"fail\" method=\"%s::%s\"", "Breakpoint exists at %s::%s", class_name, func_name);
}
- efree(lcname);
+ efree(func_lcname);
+ efree(class_lcname);
} /* }}} */
-PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline) /* {{{ */
{
if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline)) {
phpdbg_breakline_t new_break;
@@ -347,27 +464,25 @@ PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC) /* {{{
new_break.opline = opline;
new_break.base = NULL;
- zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline,
- &new_break, sizeof(phpdbg_breakline_t), NULL);
+ zend_hash_index_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline, &new_break, sizeof(phpdbg_breakline_t));
- phpdbg_notice("Breakpoint #%d added at %#lx",
- new_break.id, new_break.opline);
+ phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" opline=\"%#lx\"", "Breakpoint #%d added at %#lx", new_break.id, new_break.opline);
PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
} else {
- phpdbg_notice("Breakpoint exists at %#lx", opline);
+ phpdbg_error("breakpoint", "type=\"exists\" add=\"fail\" opline=\"%#lx\"", "Breakpoint exists at %#lx", opline);
}
} /* }}} */
-PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_op_array *op_array TSRMLS_DC) /* {{{ */
+PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_op_array *op_array) /* {{{ */
{
phpdbg_breakline_t opline_break;
if (op_array->last <= brake->opline_num) {
if (brake->class_name == NULL) {
- phpdbg_error("There are only %d oplines in function %s (breaking at opline %ld impossible)", op_array->last, brake->func_name, brake->opline_num);
+ phpdbg_error("breakpoint", "type=\"maxoplines\" add=\"fail\" maxoplinenum=\"%d\" function=\"%s\" usedoplinenum=\"%ld\"", "There are only %d oplines in function %s (breaking at opline %ld impossible)", op_array->last, brake->func_name, brake->opline_num);
} else if (brake->func_name == NULL) {
- phpdbg_error("There are only %d oplines in file %s (breaking at opline %ld impossible)", op_array->last, brake->class_name, brake->opline_num);
+ phpdbg_error("breakpoint", "type=\"maxoplines\" add=\"fail\" maxoplinenum=\"%d\" file=\"%s\" usedoplinenum=\"%ld\"", "There are only %d oplines in file %s (breaking at opline %ld impossible)", op_array->last, brake->class_name, brake->opline_num);
} else {
- phpdbg_error("There are only %d oplines in method %s::%s (breaking at opline %ld impossible)", op_array->last, brake->class_name, brake->func_name, brake->opline_num);
+ phpdbg_error("breakpoint", "type=\"maxoplines\" add=\"fail\" maxoplinenum=\"%d\" method=\"%s::%s\" usedoplinenum=\"%ld\"", "There are only %d oplines in method %s::%s (breaking at opline %ld impossible)", op_array->last, brake->class_name, brake->func_name, brake->opline_num);
}
return FAILURE;
@@ -389,52 +504,48 @@ PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_o
PHPDBG_G(flags) |= PHPDBG_HAS_OPLINE_BP;
- zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline_break.opline, &opline_break, sizeof(phpdbg_breakline_t), NULL);
+ zend_hash_index_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], opline_break.opline, &opline_break, sizeof(phpdbg_breakline_t));
return SUCCESS;
} /* }}} */
-PHPDBG_API void phpdbg_resolve_op_array_breaks(zend_op_array *op_array TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_resolve_op_array_breaks(zend_op_array *op_array) /* {{{ */
{
HashTable *func_table = &PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE];
HashTable *oplines_table;
- HashPosition position;
phpdbg_breakopline_t *brake;
- if (op_array->scope != NULL &&
- zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], op_array->scope->name, op_array->scope->name_length, (void **)&func_table) == FAILURE) {
+ if (op_array->scope != NULL && !(func_table = zend_hash_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], op_array->scope->name))) {
return;
}
if (op_array->function_name == NULL) {
- if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], op_array->filename, strlen(op_array->filename), (void **)&oplines_table) == FAILURE) {
+ if (!(oplines_table = zend_hash_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], op_array->filename))) {
return;
}
- } else if (zend_hash_find(func_table, op_array->function_name?op_array->function_name:"", op_array->function_name?strlen(op_array->function_name):0, (void **)&oplines_table) == FAILURE) {
+ } else if (!op_array->function_name || !(oplines_table = zend_hash_find_ptr(func_table, op_array->function_name))) {
return;
}
- for (zend_hash_internal_pointer_reset_ex(oplines_table, &position);
- zend_hash_get_current_data_ex(oplines_table, (void**) &brake, &position) == SUCCESS;
- zend_hash_move_forward_ex(oplines_table, &position)) {
- if (phpdbg_resolve_op_array_break(brake, op_array TSRMLS_CC) == SUCCESS) {
+ ZEND_HASH_FOREACH_PTR(oplines_table, brake) {
+ if (phpdbg_resolve_op_array_break(brake, op_array) == SUCCESS) {
phpdbg_breakline_t *opline_break;
zend_hash_internal_pointer_end(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
- zend_hash_get_current_data(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (void **)&opline_break);
+ opline_break = zend_hash_get_current_data_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
- phpdbg_notice("Breakpoint #%d resolved at %s%s%s#%ld (opline %#lx)",
- brake->id,
- brake->class_name?brake->class_name:"",
- brake->class_name&&brake->func_name?"::":"",
- brake->func_name?brake->func_name:"",
+ phpdbg_notice("breakpoint", "add=\"success\" id=\"%d\" symbol=\"%s\" num=\"%ld\" opline=\"%#lx\"", "Breakpoint #%d resolved at %s%s%s#%ld (opline %#lx)",
+ opline_break->id,
+ brake->class_name ? brake->class_name : "",
+ brake->class_name && brake->func_name ? "::" : "",
+ brake->func_name ? brake->func_name : "",
brake->opline_num,
- brake->opline);
+ opline_break->opline);
}
- }
+ } ZEND_HASH_FOREACH_END();
} /* }}} */
-PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRMLS_DC) /* {{{ */
+PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break) /* {{{ */
{
HashTable *func_table = EG(function_table);
zend_function *func;
@@ -442,7 +553,7 @@ PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRML
if (new_break->func_name == NULL) {
if (EG(current_execute_data) == NULL) {
if (PHPDBG_G(ops) != NULL && !memcmp(PHPDBG_G(ops)->filename, new_break->class_name, new_break->class_len)) {
- if (phpdbg_resolve_op_array_break(new_break, PHPDBG_G(ops) TSRMLS_CC) == SUCCESS) {
+ if (phpdbg_resolve_op_array_break(new_break, PHPDBG_G(ops)) == SUCCESS) {
return SUCCESS;
} else {
return 2;
@@ -452,8 +563,9 @@ PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRML
} else {
zend_execute_data *execute_data = EG(current_execute_data);
do {
- if (execute_data->op_array->function_name == NULL && execute_data->op_array->scope == NULL && !memcmp(execute_data->op_array->filename, new_break->class_name, new_break->class_len)) {
- if (phpdbg_resolve_op_array_break(new_break, execute_data->op_array TSRMLS_CC) == SUCCESS) {
+ zend_op_array *op_array = &execute_data->func->op_array;
+ if (op_array->function_name == NULL && op_array->scope == NULL && new_break->class_len == ZSTR_LEN(op_array->filename) && !memcmp(ZSTR_VAL(op_array->filename), new_break->class_name, new_break->class_len)) {
+ if (phpdbg_resolve_op_array_break(new_break, op_array) == SUCCESS) {
return SUCCESS;
} else {
return 2;
@@ -465,16 +577,16 @@ PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRML
}
if (new_break->class_name != NULL) {
- zend_class_entry **ce;
- if (zend_hash_find(EG(class_table), zend_str_tolower_dup(new_break->class_name, new_break->class_len), new_break->class_len + 1, (void **)&ce) == FAILURE) {
+ zend_class_entry *ce;
+ if (!(ce = zend_hash_str_find_ptr(EG(class_table), zend_str_tolower_dup(new_break->class_name, new_break->class_len), new_break->class_len))) {
return FAILURE;
}
- func_table = &(*ce)->function_table;
+ func_table = &ce->function_table;
}
- if (zend_hash_find(func_table, zend_str_tolower_dup(new_break->func_name, new_break->func_len), new_break->func_len + 1, (void **)&func) == FAILURE) {
+ if (!(func = zend_hash_str_find_ptr(func_table, zend_str_tolower_dup(new_break->func_name, new_break->func_len), new_break->func_len))) {
if (new_break->class_name != NULL && new_break->func_name != NULL) {
- phpdbg_error("Method %s doesn't exist in class %s", new_break->func_name, new_break->class_name);
+ phpdbg_error("breakpoint", "type=\"nomethod\" method=\"%s::%s\"", "Method %s doesn't exist in class %s", new_break->func_name, new_break->class_name);
return 2;
}
return FAILURE;
@@ -482,21 +594,23 @@ PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRML
if (func->type != ZEND_USER_FUNCTION) {
if (new_break->class_name == NULL) {
- phpdbg_error("%s is not an user defined function, no oplines exist", new_break->func_name);
+ phpdbg_error("breakpoint", "type=\"internalfunction\" function=\"%s\"", "%s is not a user defined function, no oplines exist", new_break->func_name);
} else {
- phpdbg_error("%s::%s is not an user defined method, no oplines exist", new_break->class_name, new_break->func_name);
+ phpdbg_error("breakpoint", "type=\"internalfunction\" method=\"%s::%s\"", "%s::%s is not a user defined method, no oplines exist", new_break->class_name, new_break->func_name);
}
return 2;
}
- if (phpdbg_resolve_op_array_break(new_break, &func->op_array TSRMLS_CC) == FAILURE) {
+ if (phpdbg_resolve_op_array_break(new_break, &func->op_array) == FAILURE) {
return 2;
}
return SUCCESS;
} /* }}} */
-PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, zend_ulong opline TSRMLS_DC) /* {{{ */
+/* TODO ... method/function oplines need to be normalized (leading backslash, lowercase) and file oplines need to be resolved properly */
+
+PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, zend_ulong opline) /* {{{ */
{
phpdbg_breakopline_t new_break;
HashTable class_breaks, *class_table;
@@ -510,39 +624,31 @@ PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const cha
new_break.opline_num = opline;
new_break.opline = 0;
- switch (phpdbg_resolve_opline_break(&new_break TSRMLS_CC)) {
+ switch (phpdbg_resolve_opline_break(&new_break)) {
case FAILURE:
- phpdbg_notice("Pending breakpoint #%d at %s::%s#%ld", new_break.id, new_break.class_name, new_break.func_name, opline);
+ phpdbg_notice("breakpoint", "pending=\"pending\" id=\"%d\" method=\"%::%s\" num=\"%ld\"", "Pending breakpoint #%d at %s::%s#%ld", new_break.id, new_break.class_name, new_break.func_name, opline);
break;
case SUCCESS:
- phpdbg_notice("Breakpoint #%d added at %s::%s#%ld", new_break.id, new_break.class_name, new_break.func_name, opline);
+ phpdbg_notice("breakpoint", "id=\"%d\" method=\"%::%s\" num=\"%ld\"", "Breakpoint #%d added at %s::%s#%ld", new_break.id, new_break.class_name, new_break.func_name, opline);
break;
case 2:
return;
}
- if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], new_break.class_name, new_break.class_len, (void **)&class_table) == FAILURE) {
+ if (!(class_table = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], new_break.class_name, new_break.class_len))) {
zend_hash_init(&class_breaks, 8, NULL, phpdbg_opline_class_breaks_dtor, 0);
- zend_hash_update(
- &PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE],
- new_break.class_name,
- new_break.class_len,
- (void **)&class_breaks, sizeof(HashTable), (void **)&class_table);
+ class_table = zend_hash_str_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], new_break.class_name, new_break.class_len, &class_breaks, sizeof(HashTable));
}
- if (zend_hash_find(class_table, new_break.func_name, new_break.func_len, (void **)&method_table) == FAILURE) {
+ if (!(method_table = zend_hash_str_find_ptr(class_table, new_break.func_name, new_break.func_len))) {
zend_hash_init(&method_breaks, 8, NULL, phpdbg_opline_breaks_dtor, 0);
- zend_hash_update(
- class_table,
- new_break.func_name,
- new_break.func_len,
- (void **)&method_breaks, sizeof(HashTable), (void **)&method_table);
+ method_table = zend_hash_str_update_mem(class_table, new_break.func_name, new_break.func_len, &method_breaks, sizeof(HashTable));
}
if (zend_hash_index_exists(method_table, opline)) {
- phpdbg_notice("Breakpoint already exists for %s::%s#%ld", new_break.class_name, new_break.func_name, opline);
+ phpdbg_error("breakpoint", "type=\"exists\" method=\"%s\" num=\"%ld\"", "Breakpoint already exists for %s::%s#%ld", new_break.class_name, new_break.func_name, opline);
efree((char*)new_break.func_name);
efree((char*)new_break.class_name);
PHPDBG_G(bp_count)--;
@@ -553,10 +659,11 @@ PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const cha
PHPDBG_BREAK_MAPPING(new_break.id, method_table);
- zend_hash_index_update(method_table, opline, &new_break, sizeof(phpdbg_breakopline_t), NULL);
+ zend_hash_index_update_mem(method_table, opline, &new_break, sizeof(phpdbg_breakopline_t));
}
+/* }}} */
-PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend_ulong opline TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend_ulong opline) /* {{{ */
{
phpdbg_breakopline_t new_break;
HashTable func_breaks, *func_table;
@@ -569,30 +676,26 @@ PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend
new_break.opline_num = opline;
new_break.opline = 0;
- switch (phpdbg_resolve_opline_break(&new_break TSRMLS_CC)) {
+ switch (phpdbg_resolve_opline_break(&new_break)) {
case FAILURE:
- phpdbg_notice("Pending breakpoint #%d at %s#%ld", new_break.id, new_break.func_name, opline);
+ phpdbg_notice("breakpoint", "pending=\"pending\" id=\"%d\" function=\"%s\" num=\"%ld\"", "Pending breakpoint #%d at %s#%ld", new_break.id, new_break.func_name, opline);
break;
case SUCCESS:
- phpdbg_notice("Breakpoint #%d added at %s#%ld", new_break.id, new_break.func_name, opline);
+ phpdbg_notice("breakpoint", "id=\"%d\" function=\"%s\" num=\"%ld\"", "Breakpoint #%d added at %s#%ld", new_break.id, new_break.func_name, opline);
break;
case 2:
return;
}
- if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], new_break.func_name, new_break.func_len, (void **)&func_table) == FAILURE) {
+ if (!(func_table = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], new_break.func_name, new_break.func_len))) {
zend_hash_init(&func_breaks, 8, NULL, phpdbg_opline_breaks_dtor, 0);
- zend_hash_update(
- &PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE],
- new_break.func_name,
- new_break.func_len,
- (void **)&func_breaks, sizeof(HashTable), (void **)&func_table);
+ func_table = zend_hash_str_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], new_break.func_name, new_break.func_len, &func_breaks, sizeof(HashTable));
}
if (zend_hash_index_exists(func_table, opline)) {
- phpdbg_notice("Breakpoint already exists for %s#%ld", new_break.func_name, opline);
+ phpdbg_error("breakpoint", "type=\"exists\" function=\"%s\" num=\"%ld\"", "Breakpoint already exists for %s#%ld", new_break.func_name, opline);
efree((char*)new_break.func_name);
PHPDBG_G(bp_count)--;
return;
@@ -602,10 +705,11 @@ PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend
PHPDBG_G(flags) |= PHPDBG_HAS_FUNCTION_OPLINE_BP;
- zend_hash_index_update(func_table, opline, &new_break, sizeof(phpdbg_breakopline_t), NULL);
+ zend_hash_index_update_mem(func_table, opline, &new_break, sizeof(phpdbg_breakopline_t));
}
+/* }}} */
-PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong opline TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong opline) /* {{{ */
{
phpdbg_breakopline_t new_break;
HashTable file_breaks, *file_table;
@@ -618,30 +722,26 @@ PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong o
new_break.opline_num = opline;
new_break.opline = 0;
- switch (phpdbg_resolve_opline_break(&new_break TSRMLS_CC)) {
+ switch (phpdbg_resolve_opline_break(&new_break)) {
case FAILURE:
- phpdbg_notice("Pending breakpoint #%d at %s:%ld", new_break.id, new_break.class_name, opline);
+ phpdbg_notice("breakpoint", "pending=\"pending\" id=\"%d\" file=\"%s\" num=\"%ld\"", "Pending breakpoint #%d at %s:%ld", new_break.id, new_break.class_name, opline);
break;
case SUCCESS:
- phpdbg_notice("Breakpoint #%d added at %s:%ld", new_break.id, new_break.class_name, opline);
+ phpdbg_notice("breakpoint", "id=\"%d\" file=\"%s\" num=\"%ld\"", "Breakpoint #%d added at %s:%ld", new_break.id, new_break.class_name, opline);
break;
case 2:
return;
}
- if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], new_break.class_name, new_break.class_len, (void **)&file_table) == FAILURE) {
+ if (!(file_table = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], new_break.class_name, new_break.class_len))) {
zend_hash_init(&file_breaks, 8, NULL, phpdbg_opline_breaks_dtor, 0);
- zend_hash_update(
- &PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE],
- new_break.class_name,
- new_break.class_len,
- (void **)&file_breaks, sizeof(HashTable), (void **)&file_table);
+ file_table = zend_hash_str_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], new_break.class_name, new_break.class_len, &file_breaks, sizeof(HashTable));
}
if (zend_hash_index_exists(file_table, opline)) {
- phpdbg_notice("Breakpoint already exists for %s:%ld", new_break.class_name, opline);
+ phpdbg_error("breakpoint", "type=\"exists\" file=\"%s\" num=\"%d\"", "Breakpoint already exists for %s:%ld", new_break.class_name, opline);
efree((char*)new_break.class_name);
PHPDBG_G(bp_count)--;
return;
@@ -651,17 +751,17 @@ PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong o
PHPDBG_G(flags) |= PHPDBG_HAS_FILE_OPLINE_BP;
- zend_hash_index_update(file_table, opline, &new_break, sizeof(phpdbg_breakopline_t), NULL);
+ zend_hash_index_update_mem(file_table, opline, &new_break, sizeof(phpdbg_breakopline_t));
}
+/* }}} */
-PHPDBG_API void phpdbg_set_breakpoint_opcode(const char *name, size_t name_len TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_breakpoint_opcode(const char *name, size_t name_len) /* {{{ */
{
phpdbg_breakop_t new_break;
zend_ulong hash = zend_hash_func(name, name_len);
if (zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], hash)) {
- phpdbg_notice(
- "Breakpoint exists for %s", name);
+ phpdbg_error("breakpoint", "type=\"exists\" opcode=\"%s\"", "Breakpoint exists for %s", name);
return;
}
@@ -669,16 +769,15 @@ PHPDBG_API void phpdbg_set_breakpoint_opcode(const char *name, size_t name_len T
new_break.hash = hash;
new_break.name = estrndup(name, name_len);
- zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], hash,
- &new_break, sizeof(phpdbg_breakop_t), NULL);
+ zend_hash_index_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], hash, &new_break, sizeof(phpdbg_breakop_t));
PHPDBG_G(flags) |= PHPDBG_HAS_OPCODE_BP;
- phpdbg_notice("Breakpoint #%d added at %s", new_break.id, name);
+ phpdbg_notice("breakpoint", "id=\"%d\" opcode=\"%s\"", "Breakpoint #%d added at %s", new_break.id, name);
PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE]);
} /* }}} */
-PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline) /* {{{ */
{
if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline)) {
phpdbg_breakline_t new_break;
@@ -689,19 +788,19 @@ PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRML
new_break.opline = (zend_ulong) opline;
new_break.base = NULL;
- zend_hash_index_update(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE],
- (zend_ulong) opline, &new_break, sizeof(phpdbg_breakline_t), NULL);
+ zend_hash_index_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline, &new_break, sizeof(phpdbg_breakline_t));
- phpdbg_notice("Breakpoint #%d added at %#lx",
- new_break.id, new_break.opline);
+ phpdbg_notice("breakpoint", "id=\"%d\" opline=\"%#lx\"", "Breakpoint #%d added at %#lx", new_break.id, new_break.opline);
PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
+ } else {
+ phpdbg_error("breakpoint", "type=\"exists\" opline=\"%#lx\"", "Breakpoint exists for opline %#lx", (zend_ulong) opline);
}
} /* }}} */
-static inline void phpdbg_create_conditional_break(phpdbg_breakcond_t *brake, const phpdbg_param_t *param, const char *expr, size_t expr_len, zend_ulong hash TSRMLS_DC) /* {{{ */
+static inline void phpdbg_create_conditional_break(phpdbg_breakcond_t *brake, const phpdbg_param_t *param, const char *expr, size_t expr_len, zend_ulong hash) /* {{{ */
{
phpdbg_breakcond_t new_break;
- zend_uint cops = CG(compiler_options);
+ uint32_t cops = CG(compiler_options);
zval pv;
PHPDBG_BREAK_INIT(new_break, PHPDBG_BREAK_COND);
@@ -710,7 +809,7 @@ static inline void phpdbg_create_conditional_break(phpdbg_breakcond_t *brake, co
if (param) {
new_break.paramed = 1;
phpdbg_copy_param(
- param, &new_break.param TSRMLS_CC);
+ param, &new_break.param);
} else {
new_break.paramed = 0;
}
@@ -722,176 +821,165 @@ static inline void phpdbg_create_conditional_break(phpdbg_breakcond_t *brake, co
new_break.code = estrndup(expr, expr_len);
new_break.code_len = expr_len;
- Z_STRLEN(pv) = expr_len + sizeof("return ;") - 1;
- Z_STRVAL(pv) = emalloc(Z_STRLEN(pv) + 1);
+ Z_STR(pv) = zend_string_alloc(expr_len + sizeof("return ;") - 1, 0);
memcpy(Z_STRVAL(pv), "return ", sizeof("return ") - 1);
memcpy(Z_STRVAL(pv) + sizeof("return ") - 1, expr, expr_len);
Z_STRVAL(pv)[Z_STRLEN(pv) - 1] = ';';
Z_STRVAL(pv)[Z_STRLEN(pv)] = '\0';
- Z_TYPE(pv) = IS_STRING;
+ Z_TYPE_INFO(pv) = IS_STRING;
- new_break.ops = zend_compile_string(
- &pv, "Conditional Breakpoint Code" TSRMLS_CC);
+ new_break.ops = zend_compile_string(&pv, "Conditional Breakpoint Code");
zval_dtor(&pv);
if (new_break.ops) {
- zend_hash_index_update(
- &PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash, &new_break,
- sizeof(phpdbg_breakcond_t), (void**)&brake);
+ brake = zend_hash_index_update_mem(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash, &new_break, sizeof(phpdbg_breakcond_t));
- phpdbg_notice("Conditional breakpoint #%d added %s/%p",
- brake->id, brake->code, brake->ops);
+ phpdbg_notice("breakpoint", "id=\"%d\" expression=\"%s\" ptr=\"%p\"", "Conditional breakpoint #%d added %s/%p", brake->id, brake->code, brake->ops);
PHPDBG_G(flags) |= PHPDBG_HAS_COND_BP;
PHPDBG_BREAK_MAPPING(new_break.id, &PHPDBG_G(bp)[PHPDBG_BREAK_COND]);
} else {
- phpdbg_error(
- "Failed to compile code for expression %s", expr);
+ phpdbg_error("compile", "expression=\"%s\"", "Failed to compile code for expression %s", expr);
efree((char*)new_break.code);
PHPDBG_G(bp_count)--;
}
+
CG(compiler_options) = cops;
} /* }}} */
-PHPDBG_API void phpdbg_set_breakpoint_expression(const char *expr, size_t expr_len TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_breakpoint_expression(const char *expr, size_t expr_len) /* {{{ */
{
zend_ulong expr_hash = zend_inline_hash_func(expr, expr_len);
phpdbg_breakcond_t new_break;
if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], expr_hash)) {
phpdbg_create_conditional_break(
- &new_break, NULL, expr, expr_len, expr_hash TSRMLS_CC);
+ &new_break, NULL, expr, expr_len, expr_hash);
} else {
- phpdbg_notice("Conditional break %s exists", expr);
+ phpdbg_error("breakpoint", "type=\"exists\" expression=\"%s\"", "Conditional break %s exists", expr);
}
} /* }}} */
-PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param) /* {{{ */
{
phpdbg_breakcond_t new_break;
phpdbg_param_t *condition;
zend_ulong hash = 0L;
-
+
if (param->next) {
condition = param->next;
hash = zend_inline_hash_func(condition->str, condition->len);
-
+
if (!zend_hash_index_exists(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], hash)) {
- phpdbg_create_conditional_break(
- &new_break, param,
- condition->str, condition->len, hash TSRMLS_CC);
+ phpdbg_create_conditional_break(&new_break, param, condition->str, condition->len, hash);
} else {
- phpdbg_notice(
- "Conditional break %s exists at the specified location", condition->str);
- }
+ phpdbg_notice("breakpoint", "type=\"exists\" arg=\"%s\"", "Conditional break %s exists at the specified location", condition->str);
+ }
}
-
+
} /* }}} */
-static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array *op_array TSRMLS_DC) /* {{{ */
+static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_file(zend_op_array *op_array) /* {{{ */
{
HashTable *breaks;
phpdbg_breakbase_t *brake;
- size_t name_len = strlen(op_array->filename);
+ size_t path_len;
+ char realpath[MAXPATHLEN];
+ const char *path = ZSTR_VAL(op_array->filename);
+
+ if (VCWD_REALPATH(path, realpath)) {
+ path = realpath;
+ }
+
+ path_len = strlen(path);
- if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], op_array->filename,
- name_len, (void**)&breaks) == FAILURE) {
+#if 0
+ phpdbg_debug("Op at: %.*s %d\n", path_len, path, (*EG(opline_ptr))->lineno);
+#endif
+
+ if (!(breaks = zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], path, path_len))) {
return NULL;
}
- if (zend_hash_index_find(breaks, (*EG(opline_ptr))->lineno, (void**)&brake) == SUCCESS) {
+ if (EG(current_execute_data) && (brake = zend_hash_index_find_ptr(breaks, EG(current_execute_data)->opline->lineno))) {
return brake;
}
return NULL;
} /* }}} */
-static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_symbol(zend_function *fbc TSRMLS_DC) /* {{{ */
+static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_symbol(zend_function *fbc) /* {{{ */
{
- const char *fname;
zend_op_array *ops;
- phpdbg_breakbase_t *brake;
if (fbc->type != ZEND_USER_FUNCTION) {
return NULL;
}
- ops = (zend_op_array*)fbc;
+ ops = (zend_op_array *) fbc;
if (ops->scope) {
/* find method breaks here */
- return phpdbg_find_breakpoint_method(ops TSRMLS_CC);
+ return phpdbg_find_breakpoint_method(ops);
}
- fname = ops->function_name;
+ if (ops->function_name) {
+ phpdbg_breakbase_t *brake;
+ zend_string *fname = zend_string_tolower(ops->function_name);
- if (!fname) {
- fname = "main";
- }
+ brake = zend_hash_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], fname);
- if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], fname, strlen(fname), (void**)&brake) == SUCCESS) {
+ zend_string_release(fname);
return brake;
+ } else {
+ return zend_hash_str_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], ZEND_STRL("main"));
}
-
- return NULL;
} /* }}} */
-static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_method(zend_op_array *ops TSRMLS_DC) /* {{{ */
+static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_method(zend_op_array *ops) /* {{{ */
{
HashTable *class_table;
- phpdbg_breakbase_t *brake;
+ phpdbg_breakbase_t *brake = NULL;
+ zend_string *class_lcname = zend_string_tolower(ops->scope->name);
- if (zend_hash_find(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], ops->scope->name,
- ops->scope->name_length, (void**)&class_table) == SUCCESS) {
- char *lcname = zend_str_tolower_dup(ops->function_name, strlen(ops->function_name));
- size_t lcname_len = strlen(lcname);
-
- if (zend_hash_find(
- class_table,
- lcname,
- lcname_len, (void**)&brake) == SUCCESS) {
- efree(lcname);
- return brake;
- }
+ if ((class_table = zend_hash_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_lcname))) {
+ zend_string *lcname = zend_string_tolower(ops->function_name);
- efree(lcname);
+ brake = zend_hash_find_ptr(class_table, lcname);
+
+ zend_string_release(lcname);
}
- return NULL;
+ zend_string_release(class_lcname);
+ return brake;
} /* }}} */
-static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t opline TSRMLS_DC) /* {{{ */
+static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opline(phpdbg_opline_ptr_t opline) /* {{{ */
{
phpdbg_breakline_t *brake;
- if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE],
- (zend_ulong) opline, (void**)&brake) == SUCCESS) {
- return (brake->base?(phpdbg_breakbase_t *)brake->base:(phpdbg_breakbase_t *)brake);
+ if ((brake = zend_hash_index_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (zend_ulong) opline)) && brake->base) {
+ return (phpdbg_breakbase_t *)brake->base;
}
- return NULL;
+ return (phpdbg_breakbase_t *) brake;
} /* }}} */
-static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opcode(zend_uchar opcode TSRMLS_DC) /* {{{ */
+static inline phpdbg_breakbase_t *phpdbg_find_breakpoint_opcode(zend_uchar opcode) /* {{{ */
{
- phpdbg_breakbase_t *brake;
- const char *opname = phpdbg_decode_opcode(opcode);
+ const char *opname = zend_get_opcode_name(opcode);
- if (memcmp(opname, PHPDBG_STRL("UNKNOWN")) == 0) {
+ if (!opname) {
return NULL;
}
- if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE],
- zend_hash_func(opname, strlen(opname)), (void**)&brake) == SUCCESS) {
- return brake;
- }
- return NULL;
+ return zend_hash_index_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], zend_hash_func(opname, strlen(opname)));
} /* }}} */
-static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
+static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend_execute_data *execute_data) /* {{{ */
{
- zend_function *function = (zend_function*) execute_data->function_state.function;
+ zend_function *function = execute_data->func;
switch (param->type) {
case NUMERIC_FUNCTION_PARAM:
@@ -906,8 +994,8 @@ static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend
const char *str = NULL;
size_t len = 0L;
zend_op_array *ops = (zend_op_array*)function;
- str = ops->function_name ? ops->function_name : "main";
- len = strlen(str);
+ str = ops->function_name ? ZSTR_VAL(ops->function_name) : "main";
+ len = ops->function_name ? ZSTR_LEN(ops->function_name) : strlen(str);
if (len == param->len && memcmp(param->str, str, len) == SUCCESS) {
return param->type == STR_PARAM || execute_data->opline - ops->opcodes == param->num;
@@ -916,8 +1004,8 @@ static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend
} break;
case FILE_PARAM: {
- if (param->file.line == zend_get_executed_lineno(TSRMLS_C)) {
- const char *str = zend_get_executed_filename(TSRMLS_C);
+ if (param->file.line == zend_get_executed_lineno()) {
+ const char *str = zend_get_executed_filename();
size_t lengths[2] = {strlen(param->file.name), strlen(str)};
if (lengths[0] == lengths[1]) {
@@ -937,10 +1025,10 @@ static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend
zend_op_array *ops = (zend_op_array*) function;
if (ops->scope) {
- size_t lengths[2] = {strlen(param->method.class), ops->scope->name_length};
+ size_t lengths[2] = { strlen(param->method.class), ZSTR_LEN(ops->scope->name) };
if (lengths[0] == lengths[1] && memcmp(param->method.class, ops->scope->name, lengths[0]) == SUCCESS) {
lengths[0] = strlen(param->method.name);
- lengths[1] = strlen(ops->function_name);
+ lengths[1] = ZSTR_LEN(ops->function_name);
if (lengths[0] == lengths[1] && memcmp(param->method.name, ops->function_name, lengths[0]) == SUCCESS) {
return param->type == METHOD_PARAM || (execute_data->opline - ops->opcodes) == param->num;
@@ -961,80 +1049,54 @@ static inline zend_bool phpdbg_find_breakpoint_param(phpdbg_param_t *param, zend
return 0;
} /* }}} */
-static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
+static inline phpdbg_breakbase_t *phpdbg_find_conditional_breakpoint(zend_execute_data *execute_data) /* {{{ */
{
phpdbg_breakcond_t *bp;
- HashPosition position;
int breakpoint = FAILURE;
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], (void*)&bp, &position) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position)) {
- zval *retval = NULL;
- int orig_interactive = CG(interactive);
- zval **orig_retval = EG(return_value_ptr_ptr);
- zend_op_array *orig_ops = EG(active_op_array);
- zend_op **orig_opline = EG(opline_ptr);
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], bp) {
+ zval retval;
+ const zend_op *orig_opline = EG(current_execute_data)->opline;
+ zend_function *orig_func = EG(current_execute_data)->func;
+ zval *orig_retval = EG(current_execute_data)->return_value;
if (((phpdbg_breakbase_t*)bp)->disabled) {
continue;
}
if (bp->paramed) {
- if (!phpdbg_find_breakpoint_param(&bp->param, execute_data TSRMLS_CC)) {
+ if (!phpdbg_find_breakpoint_param(&bp->param, execute_data)) {
continue;
}
}
- ALLOC_INIT_ZVAL(retval);
-
- EG(return_value_ptr_ptr) = &retval;
- EG(active_op_array) = bp->ops;
EG(no_extensions) = 1;
- if (!EG(active_symbol_table)) {
- zend_rebuild_symbol_table(TSRMLS_C);
- }
-
- CG(interactive) = 0;
+ zend_rebuild_symbol_table();
zend_try {
PHPDBG_G(flags) |= PHPDBG_IN_COND_BP;
- zend_execute(EG(active_op_array) TSRMLS_CC);
-#if PHP_VERSION_ID >= 50700
- if (zend_is_true(retval TSRMLS_CC)) {
-#else
- if (zend_is_true(retval)) {
-#endif
+ zend_execute(bp->ops, &retval);
+ if (zend_is_true(&retval)) {
breakpoint = SUCCESS;
}
- } zend_catch {
- CG(interactive) = orig_interactive;
-
- EG(no_extensions)=1;
- EG(return_value_ptr_ptr) = orig_retval;
- EG(active_op_array) = orig_ops;
- EG(opline_ptr) = orig_opline;
- PHPDBG_G(flags) &= ~PHPDBG_IN_COND_BP;
} zend_end_try();
- CG(interactive) = orig_interactive;
-
- EG(no_extensions)=1;
- EG(return_value_ptr_ptr) = orig_retval;
- EG(active_op_array) = orig_ops;
- EG(opline_ptr) = orig_opline;
+ EG(no_extensions) = 1;
+ EG(current_execute_data)->opline = orig_opline;
+ EG(current_execute_data)->func = orig_func;
+ EG(current_execute_data)->return_value = orig_retval;
PHPDBG_G(flags) &= ~PHPDBG_IN_COND_BP;
if (breakpoint == SUCCESS) {
break;
}
- }
+ } ZEND_HASH_FOREACH_END();
- return (breakpoint == SUCCESS) ? ((phpdbg_breakbase_t*)bp) : NULL;
+ return (breakpoint == SUCCESS) ? ((phpdbg_breakbase_t *) bp) : NULL;
} /* }}} */
-PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakpoint(zend_execute_data* execute_data TSRMLS_DC) /* {{{ */
+PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakpoint(zend_execute_data *execute_data) /* {{{ */
{
phpdbg_breakbase_t *base = NULL;
@@ -1045,32 +1107,29 @@ PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakpoint(zend_execute_data* execute
/* conditions cannot be executed by eval()'d code */
if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL) &&
(PHPDBG_G(flags) & PHPDBG_HAS_COND_BP) &&
- (base = phpdbg_find_conditional_breakpoint(execute_data TSRMLS_CC))) {
+ (base = phpdbg_find_conditional_breakpoint(execute_data))) {
goto result;
}
- if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP) &&
- (base = phpdbg_find_breakpoint_file(execute_data->op_array TSRMLS_CC))) {
+ if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP) && (base = phpdbg_find_breakpoint_file(&execute_data->func->op_array))) {
goto result;
}
if (PHPDBG_G(flags) & (PHPDBG_HAS_METHOD_BP|PHPDBG_HAS_SYM_BP)) {
- /* check we are at the beginning of the stack */
- if (execute_data->opline == EG(active_op_array)->opcodes) {
- if ((base = phpdbg_find_breakpoint_symbol(
- execute_data->function_state.function TSRMLS_CC))) {
+ zend_op_array *op_array = &execute_data->func->op_array;
+ /* check we are at the beginning of the stack, but after argument RECV */
+ if (execute_data->opline == op_array->opcodes + op_array->num_args + !!(op_array->fn_flags & ZEND_ACC_VARIADIC)) {
+ if ((base = phpdbg_find_breakpoint_symbol(execute_data->func))) {
goto result;
}
}
}
- if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP) &&
- (base = phpdbg_find_breakpoint_opline(execute_data->opline TSRMLS_CC))) {
+ if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP) && (base = phpdbg_find_breakpoint_opline((phpdbg_opline_ptr_t) execute_data->opline))) {
goto result;
}
- if ((PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP) &&
- (base = phpdbg_find_breakpoint_opcode(execute_data->opline->opcode TSRMLS_CC))) {
+ if ((PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP) && (base = phpdbg_find_breakpoint_opcode(execute_data->opline->opcode))) {
goto result;
}
@@ -1085,16 +1144,14 @@ result:
return base;
} /* }}} */
-PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num) /* {{{ */
{
- HashTable **table;
- HashPosition position;
+ HashTable *table;
phpdbg_breakbase_t *brake;
+ zend_string *strkey;
+ zend_ulong numkey;
- if ((brake = phpdbg_find_breakbase_ex(num, &table, &position TSRMLS_CC))) {
- char *key;
- zend_uint klen;
- zend_ulong idx;
+ if ((brake = phpdbg_find_breakbase_ex(num, &table, &numkey, &strkey))) {
int type = brake->type;
char *name = NULL;
size_t name_len = 0L;
@@ -1102,7 +1159,7 @@ PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC) /* {{{ */
switch (type) {
case PHPDBG_BREAK_FILE:
case PHPDBG_BREAK_METHOD:
- if (zend_hash_num_elements((*table)) == 1) {
+ if (zend_hash_num_elements(table) == 1) {
name = estrdup(brake->name);
name_len = strlen(name);
if (zend_hash_num_elements(&PHPDBG_G(bp)[type]) == 1) {
@@ -1112,7 +1169,7 @@ PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC) /* {{{ */
break;
default: {
- if (zend_hash_num_elements((*table)) == 1) {
+ if (zend_hash_num_elements(table) == 1) {
PHPDBG_G(flags) &= ~(1<<(brake->type+1));
}
}
@@ -1125,40 +1182,36 @@ PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC) /* {{{ */
if (zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]) == 1) {
PHPDBG_G(flags) &= PHPDBG_HAS_OPLINE_BP;
}
- zend_hash_index_del(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], ((phpdbg_breakopline_t*)brake)->opline);
+ zend_hash_index_del(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], ((phpdbg_breakopline_t *) brake)->opline);
}
- switch (zend_hash_get_current_key_ex(
- (*table), &key, &klen, &idx, 0, &position)) {
-
- case HASH_KEY_IS_STRING:
- zend_hash_del((*table), key, klen);
- break;
-
- default:
- zend_hash_index_del((*table), idx);
+ if (strkey) {
+ zend_hash_del(table, strkey);
+ } else {
+ zend_hash_index_del(table, numkey);
}
switch (type) {
case PHPDBG_BREAK_FILE:
case PHPDBG_BREAK_METHOD:
if (name) {
- zend_hash_del(&PHPDBG_G(bp)[type], name, name_len);
+ zend_hash_str_del(&PHPDBG_G(bp)[type], name, name_len);
efree(name);
}
break;
}
- phpdbg_notice("Deleted breakpoint #%ld", num);
+ phpdbg_notice("breakpoint", "deleted=\"success\" id=\"%ld\"", "Deleted breakpoint #%ld", num);
PHPDBG_BREAK_UNMAPPING(num);
} else {
- phpdbg_error("Failed to find breakpoint #%ld", num);
+ phpdbg_error("breakpoint", "type=\"nobreakpoint\" deleted=\"fail\" id=\"%ld\"", "Failed to find breakpoint #%ld", num);
}
} /* }}} */
-PHPDBG_API void phpdbg_clear_breakpoints(TSRMLS_D) /* {{{ */
+PHPDBG_API void phpdbg_clear_breakpoints(void) /* {{{ */
{
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]);
+ zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING]);
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]);
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]);
zend_hash_clean(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE]);
@@ -1174,23 +1227,23 @@ PHPDBG_API void phpdbg_clear_breakpoints(TSRMLS_D) /* {{{ */
PHPDBG_G(bp_count) = 0;
} /* }}} */
-PHPDBG_API void phpdbg_hit_breakpoint(phpdbg_breakbase_t *brake, zend_bool output TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_hit_breakpoint(phpdbg_breakbase_t *brake, zend_bool output) /* {{{ */
{
brake->hits++;
if (output) {
- phpdbg_print_breakpoint(brake TSRMLS_CC);
+ phpdbg_print_breakpoint(brake);
}
} /* }}} */
-PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t *brake TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t *brake) /* {{{ */
{
if (!brake)
goto unknown;
switch (brake->type) {
case PHPDBG_BREAK_FILE: {
- phpdbg_notice("Breakpoint #%d at %s:%ld, hits: %lu",
+ phpdbg_notice("breakpoint", "id=\"%d\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d at %s:%ld, hits: %lu",
((phpdbg_breakfile_t*)brake)->id,
((phpdbg_breakfile_t*)brake)->filename,
((phpdbg_breakfile_t*)brake)->line,
@@ -1198,91 +1251,90 @@ PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t *brake TSRMLS_DC) /*
} break;
case PHPDBG_BREAK_SYM: {
- phpdbg_notice("Breakpoint #%d in %s() at %s:%u, hits: %lu",
+ phpdbg_notice("breakpoint", "id=\"%d\" function=\"%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %s() at %s:%u, hits: %lu",
((phpdbg_breaksymbol_t*)brake)->id,
((phpdbg_breaksymbol_t*)brake)->symbol,
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C),
+ zend_get_executed_filename(),
+ zend_get_executed_lineno(),
((phpdbg_breakfile_t*)brake)->hits);
} break;
case PHPDBG_BREAK_OPLINE: {
- phpdbg_notice("Breakpoint #%d in %#lx at %s:%u, hits: %lu",
+ phpdbg_notice("breakpoint", "id=\"%d\" opline=\"%#lx\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %#lx at %s:%u, hits: %lu",
((phpdbg_breakline_t*)brake)->id,
((phpdbg_breakline_t*)brake)->opline,
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C),
+ zend_get_executed_filename(),
+ zend_get_executed_lineno(),
((phpdbg_breakline_t*)brake)->hits);
} break;
case PHPDBG_BREAK_METHOD_OPLINE: {
- phpdbg_notice("Breakpoint #%d in %s::%s()#%lu at %s:%u, hits: %lu",
+ phpdbg_notice("breakpoint", "id=\"%d\" method=\"%s::%s\" num=\"%lu\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %s::%s()#%lu at %s:%u, hits: %lu",
((phpdbg_breakopline_t*)brake)->id,
((phpdbg_breakopline_t*)brake)->class_name,
((phpdbg_breakopline_t*)brake)->func_name,
((phpdbg_breakopline_t*)brake)->opline_num,
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C),
+ zend_get_executed_filename(),
+ zend_get_executed_lineno(),
((phpdbg_breakopline_t*)brake)->hits);
} break;
case PHPDBG_BREAK_FUNCTION_OPLINE: {
- phpdbg_notice("Breakpoint #%d in %s()#%lu at %s:%u, hits: %lu",
+ phpdbg_notice("breakpoint", "id=\"%d\" num=\"%lu\" function=\"%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %s()#%lu at %s:%u, hits: %lu",
((phpdbg_breakopline_t*)brake)->id,
((phpdbg_breakopline_t*)brake)->func_name,
((phpdbg_breakopline_t*)brake)->opline_num,
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C),
+ zend_get_executed_filename(),
+ zend_get_executed_lineno(),
((phpdbg_breakopline_t*)brake)->hits);
} break;
case PHPDBG_BREAK_FILE_OPLINE: {
- phpdbg_notice("Breakpoint #%d in %s:%lu at %s:%u, hits: %lu",
+ phpdbg_notice("breakpoint", "id=\"%d\" num=\"%lu\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in #%lu at %s:%u, hits: %lu",
((phpdbg_breakopline_t*)brake)->id,
- ((phpdbg_breakopline_t*)brake)->class_name,
((phpdbg_breakopline_t*)brake)->opline_num,
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C),
+ zend_get_executed_filename(),
+ zend_get_executed_lineno(),
((phpdbg_breakopline_t*)brake)->hits);
} break;
case PHPDBG_BREAK_OPCODE: {
- phpdbg_notice("Breakpoint #%d in %s at %s:%u, hits: %lu",
+ phpdbg_notice("breakpoint", "id=\"%d\" opcode=\"%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %s at %s:%u, hits: %lu",
((phpdbg_breakop_t*)brake)->id,
((phpdbg_breakop_t*)brake)->name,
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C),
+ zend_get_executed_filename(),
+ zend_get_executed_lineno(),
((phpdbg_breakop_t*)brake)->hits);
} break;
case PHPDBG_BREAK_METHOD: {
- phpdbg_notice("Breakpoint #%d in %s::%s() at %s:%u, hits: %lu",
+ phpdbg_notice("breakpoint", "id=\"%d\" method=\"%s::%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Breakpoint #%d in %s::%s() at %s:%u, hits: %lu",
((phpdbg_breakmethod_t*)brake)->id,
((phpdbg_breakmethod_t*)brake)->class_name,
((phpdbg_breakmethod_t*)brake)->func_name,
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C),
+ zend_get_executed_filename(),
+ zend_get_executed_lineno(),
((phpdbg_breakmethod_t*)brake)->hits);
} break;
case PHPDBG_BREAK_COND: {
if (((phpdbg_breakcond_t*)brake)->paramed) {
char *param;
- phpdbg_notice("Conditional breakpoint #%d: at %s if %s %s:%u, hits: %lu",
+ phpdbg_notice("breakpoint", "id=\"%d\" location=\"%s\" eval=\"%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Conditional breakpoint #%d: at %s if %s at %s:%u, hits: %lu",
((phpdbg_breakcond_t*)brake)->id,
- phpdbg_param_tostring(&((phpdbg_breakcond_t*)brake)->param, &param TSRMLS_CC),
+ phpdbg_param_tostring(&((phpdbg_breakcond_t*)brake)->param, &param),
((phpdbg_breakcond_t*)brake)->code,
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C),
+ zend_get_executed_filename(),
+ zend_get_executed_lineno(),
((phpdbg_breakcond_t*)brake)->hits);
if (param)
free(param);
} else {
- phpdbg_notice("Conditional breakpoint #%d: on %s == true %s:%u, hits: %lu",
+ phpdbg_notice("breakpoint", "id=\"%d\" eval=\"%s\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Conditional breakpoint #%d: on %s == true at %s:%u, hits: %lu",
((phpdbg_breakcond_t*)brake)->id,
((phpdbg_breakcond_t*)brake)->code,
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C),
+ zend_get_executed_filename(),
+ zend_get_executed_lineno(),
((phpdbg_breakcond_t*)brake)->hits);
}
@@ -1290,349 +1342,285 @@ PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t *brake TSRMLS_DC) /*
default: {
unknown:
- phpdbg_notice("Unknown breakpoint at %s:%u",
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C));
+ phpdbg_notice("breakpoint", "id=\"\" file=\"%s\" line=\"%ld\" hits=\"%lu\"", "Unknown breakpoint at %s:%u",
+ zend_get_executed_filename(),
+ zend_get_executed_lineno());
}
}
} /* }}} */
-PHPDBG_API void phpdbg_enable_breakpoint(zend_ulong id TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_enable_breakpoint(zend_ulong id) /* {{{ */
{
- phpdbg_breakbase_t *brake = phpdbg_find_breakbase(id TSRMLS_CC);
+ phpdbg_breakbase_t *brake = phpdbg_find_breakbase(id);
if (brake) {
brake->disabled = 0;
}
} /* }}} */
-PHPDBG_API void phpdbg_disable_breakpoint(zend_ulong id TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_disable_breakpoint(zend_ulong id) /* {{{ */
{
- phpdbg_breakbase_t *brake = phpdbg_find_breakbase(id TSRMLS_CC);
+ phpdbg_breakbase_t *brake = phpdbg_find_breakbase(id);
if (brake) {
brake->disabled = 1;
}
} /* }}} */
-PHPDBG_API void phpdbg_enable_breakpoints(TSRMLS_D) /* {{{ */
+PHPDBG_API void phpdbg_enable_breakpoints(void) /* {{{ */
{
PHPDBG_G(flags) |= PHPDBG_IS_BP_ENABLED;
} /* }}} */
-PHPDBG_API void phpdbg_disable_breakpoints(TSRMLS_D) { /* {{{ */
+PHPDBG_API void phpdbg_disable_breakpoints(void) { /* {{{ */
PHPDBG_G(flags) &= ~PHPDBG_IS_BP_ENABLED;
} /* }}} */
-PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase(zend_ulong id TSRMLS_DC) /* {{{ */
+PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase(zend_ulong id) /* {{{ */
{
- HashTable **table;
- HashPosition position;
+ HashTable *table;
+ zend_string *strkey;
+ zend_ulong numkey;
- return phpdbg_find_breakbase_ex(id, &table, &position TSRMLS_CC);
+ return phpdbg_find_breakbase_ex(id, &table, &numkey, &strkey);
} /* }}} */
-PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable ***table, HashPosition *position TSRMLS_DC) /* {{{ */
+PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable **table, zend_ulong *numkey, zend_string **strkey) /* {{{ */
{
- if (zend_hash_index_find(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id, (void**)table) == SUCCESS) {
+ if ((*table = zend_hash_index_find_ptr(&PHPDBG_G(bp)[PHPDBG_BREAK_MAP], id))) {
phpdbg_breakbase_t *brake;
- for (zend_hash_internal_pointer_reset_ex((**table), position);
- zend_hash_get_current_data_ex((**table), (void**)&brake, position) == SUCCESS;
- zend_hash_move_forward_ex((**table), position)) {
-
+ ZEND_HASH_FOREACH_KEY_PTR(*table, *numkey, *strkey, brake) {
if (brake->id == id) {
return brake;
}
- }
+ } ZEND_HASH_FOREACH_END();
}
+
return NULL;
} /* }}} */
-PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type) /* {{{ */
{
+ phpdbg_xml("<breakpoints %r>");
+
switch (type) {
case PHPDBG_BREAK_SYM: if ((PHPDBG_G(flags) & PHPDBG_HAS_SYM_BP)) {
- HashPosition position;
phpdbg_breaksymbol_t *brake;
- phpdbg_writeln(SEPARATE);
- phpdbg_writeln("Function Breakpoints:");
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], (void**) &brake, &position) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], &position)) {
- phpdbg_writeln("#%d\t\t%s%s",
+ phpdbg_out(SEPARATE "\n");
+ phpdbg_out("Function Breakpoints:\n");
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM], brake) {
+ phpdbg_writeln("function", "id=\"%d\" name=\"%s\" disabled=\"%s\"", "#%d\t\t%s%s",
brake->id, brake->symbol,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
- }
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
+ } ZEND_HASH_FOREACH_END();
} break;
case PHPDBG_BREAK_METHOD: if ((PHPDBG_G(flags) & PHPDBG_HAS_METHOD_BP)) {
- HashPosition position[2];
HashTable *class_table;
- char *class_name = NULL;
- zend_uint class_len = 0;
- zend_ulong class_idx = 0L;
-
- phpdbg_writeln(SEPARATE);
- phpdbg_writeln("Method Breakpoints:");
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], &position[0]);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], (void**) &class_table, &position[0]) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], &position[0])) {
-
- if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD],
- &class_name, &class_len, &class_idx, 0, &position[0]) == HASH_KEY_IS_STRING) {
- phpdbg_breakmethod_t *brake;
-
- for (zend_hash_internal_pointer_reset_ex(class_table, &position[1]);
- zend_hash_get_current_data_ex(class_table, (void**)&brake, &position[1]) == SUCCESS;
- zend_hash_move_forward_ex(class_table, &position[1])) {
- phpdbg_writeln("#%d\t\t%s::%s%s",
- brake->id, brake->class_name, brake->func_name,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
- }
- }
- }
+ phpdbg_out(SEPARATE "\n");
+ phpdbg_out("Method Breakpoints:\n");
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD], class_table) {
+ phpdbg_breakmethod_t *brake;
+
+ ZEND_HASH_FOREACH_PTR(class_table, brake) {
+ phpdbg_writeln("method", "id=\"%d\" name=\"%s::%s\" disabled=\"%s\"", "#%d\t\t%s::%s%s",
+ brake->id, brake->class_name, brake->func_name,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
+ } ZEND_HASH_FOREACH_END();
+ } ZEND_HASH_FOREACH_END();
} break;
case PHPDBG_BREAK_FILE: if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_BP)) {
- HashPosition position[2];
HashTable *points;
- phpdbg_writeln(SEPARATE);
- phpdbg_writeln("File Breakpoints:");
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position[0]);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], (void**) &points, &position[0]) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], &position[0])) {
+ phpdbg_out(SEPARATE "\n");
+ phpdbg_out("File Breakpoints:\n");
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE], points) {
phpdbg_breakfile_t *brake;
- for (zend_hash_internal_pointer_reset_ex(points, &position[1]);
- zend_hash_get_current_data_ex(points, (void**)&brake, &position[1]) == SUCCESS;
- zend_hash_move_forward_ex(points, &position[1])) {
- phpdbg_writeln("#%d\t\t%s:%lu%s",
+ ZEND_HASH_FOREACH_PTR(points, brake) {
+ phpdbg_writeln("file", "id=\"%d\" name=\"%s\" line=\"%lu\" disabled=\"%s\"", "#%d\t\t%s:%lu%s",
brake->id, brake->filename, brake->line,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
- }
- }
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
+ } ZEND_HASH_FOREACH_END();
+ } ZEND_HASH_FOREACH_END();
+ } if ((PHPDBG_G(flags) & PHPDBG_HAS_PENDING_FILE_BP)) {
+ HashTable *points;
+ phpdbg_out(SEPARATE "\n");
+ phpdbg_out("Pending File Breakpoints:\n");
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_PENDING], points) {
+ phpdbg_breakfile_t *brake;
+
+ ZEND_HASH_FOREACH_PTR(points, brake) {
+ phpdbg_writeln("file", "id=\"%d\" name=\"%s\" line=\"%lu\" disabled=\"%s\" pending=\"pending\"", "#%d\t\t%s:%lu%s",
+ brake->id, brake->filename, brake->line,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
+ } ZEND_HASH_FOREACH_END();
+ } ZEND_HASH_FOREACH_END();
} break;
case PHPDBG_BREAK_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_OPLINE_BP)) {
- HashPosition position;
phpdbg_breakline_t *brake;
- phpdbg_writeln(SEPARATE);
- phpdbg_writeln("Opline Breakpoints:");
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], (void**) &brake, &position) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], &position)) {
+ phpdbg_out(SEPARATE "\n");
+ phpdbg_out("Opline Breakpoints:\n");
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE], brake) {
+ const char *type;
switch (brake->type) {
case PHPDBG_BREAK_METHOD_OPLINE:
+ type = "method";
+ goto print_opline;
case PHPDBG_BREAK_FUNCTION_OPLINE:
+ type = "function";
+ goto print_opline;
case PHPDBG_BREAK_FILE_OPLINE:
- phpdbg_writeln("#%d\t\t%#lx\t\t(%s breakpoint)%s", brake->id, brake->opline,
- brake->type == PHPDBG_BREAK_METHOD_OPLINE?"method":
- brake->type == PHPDBG_BREAK_FUNCTION_OPLINE?"function":
- brake->type == PHPDBG_BREAK_FILE_OPLINE?"file":
- "--- error ---",
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
- break;
+ type = "method";
+
+ print_opline: {
+ if (brake->type == PHPDBG_BREAK_METHOD_OPLINE) {
+ type = "method";
+ } else if (brake->type == PHPDBG_BREAK_FUNCTION_OPLINE) {
+ type = "function";
+ } else if (brake->type == PHPDBG_BREAK_FILE_OPLINE) {
+ type = "file";
+ }
+
+ phpdbg_writeln("opline", "id=\"%d\" num=\"%#lx\" type=\"%s\" disabled=\"%s\"", "#%d\t\t%#lx\t\t(%s breakpoint)%s",
+ brake->id, brake->opline, type,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
+ } break;
default:
- phpdbg_writeln("#%d\t\t%#lx", brake->id, brake->opline);
+ phpdbg_writeln("opline", "id=\"%d\" num=\"%#lx\" disabled=\"%s\"", "#%d\t\t%#lx%s",
+ brake->id, brake->opline,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
break;
}
- }
+ } ZEND_HASH_FOREACH_END();
} break;
case PHPDBG_BREAK_METHOD_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_METHOD_OPLINE_BP)) {
- HashPosition position[3];
HashTable *class_table, *method_table;
- char *class_name = NULL, *method_name = NULL;
- zend_uint class_len = 0, method_len = 0;
- zend_ulong class_idx = 0L, method_idx = 0L;
-
- phpdbg_writeln(SEPARATE);
- phpdbg_writeln("Method opline Breakpoints:");
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], &position[0]);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], (void**) &class_table, &position[0]) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], &position[0])) {
-
- if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE],
- &class_name, &class_len, &class_idx, 0, &position[0]) == HASH_KEY_IS_STRING) {
-
- for (zend_hash_internal_pointer_reset_ex(class_table, &position[1]);
- zend_hash_get_current_data_ex(class_table, (void**) &method_table, &position[1]) == SUCCESS;
- zend_hash_move_forward_ex(class_table, &position[1])) {
-
- if (zend_hash_get_current_key_ex(class_table,
- &method_name, &method_len, &method_idx, 0, &position[0]) == HASH_KEY_IS_STRING) {
-
- phpdbg_breakopline_t *brake;
-
- for (zend_hash_internal_pointer_reset_ex(method_table, &position[2]);
- zend_hash_get_current_data_ex(method_table, (void**)&brake, &position[2]) == SUCCESS;
- zend_hash_move_forward_ex(method_table, &position[2])) {
- phpdbg_writeln("#%d\t\t%s::%s opline %ld%s",
- brake->id, brake->class_name, brake->func_name, brake->opline_num,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
- }
- }
- }
- }
- }
+ phpdbg_out(SEPARATE "\n");
+ phpdbg_out("Method opline Breakpoints:\n");
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE], class_table) {
+ ZEND_HASH_FOREACH_PTR(class_table, method_table) {
+ phpdbg_breakopline_t *brake;
+
+ ZEND_HASH_FOREACH_PTR(method_table, brake) {
+ phpdbg_writeln("methodopline", "id=\"%d\" name=\"%s::%s\" num=\"%ld\" disabled=\"%s\"", "#%d\t\t%s::%s opline %ld%s",
+ brake->id, brake->class_name, brake->func_name, brake->opline_num,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
+ } ZEND_HASH_FOREACH_END();
+ } ZEND_HASH_FOREACH_END();
+ } ZEND_HASH_FOREACH_END();
} break;
case PHPDBG_BREAK_FUNCTION_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_FUNCTION_OPLINE_BP)) {
- HashPosition position[2];
HashTable *function_table;
- char *function_name = NULL;
- zend_uint function_len = 0;
- zend_ulong function_idx = 0L;
-
- phpdbg_writeln(SEPARATE);
- phpdbg_writeln("Function opline Breakpoints:");
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], &position[0]);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], (void**) &function_table, &position[0]) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], &position[0])) {
-
- if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE],
- &function_name, &function_len, &function_idx, 0, &position[0]) == HASH_KEY_IS_STRING) {
- phpdbg_breakopline_t *brake;
-
- for (zend_hash_internal_pointer_reset_ex(function_table, &position[1]);
- zend_hash_get_current_data_ex(function_table, (void**)&brake, &position[1]) == SUCCESS;
- zend_hash_move_forward_ex(function_table, &position[1])) {
- phpdbg_writeln("#%d\t\t%s opline %ld%s",
- brake->id, brake->func_name, brake->opline_num,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
- }
- }
-
- }
+ phpdbg_out(SEPARATE "\n");
+ phpdbg_out("Function opline Breakpoints:\n");
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE], function_table) {
+ phpdbg_breakopline_t *brake;
+
+ ZEND_HASH_FOREACH_PTR(function_table, brake) {
+ phpdbg_writeln("functionopline", "id=\"%d\" name=\"%s\" num=\"%ld\" disabled=\"%s\"", "#%d\t\t%s opline %ld%s",
+ brake->id, brake->func_name, brake->opline_num,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
+ } ZEND_HASH_FOREACH_END();
+ } ZEND_HASH_FOREACH_END();
} break;
case PHPDBG_BREAK_FILE_OPLINE: if ((PHPDBG_G(flags) & PHPDBG_HAS_FILE_OPLINE_BP)) {
- HashPosition position[2];
HashTable *file_table;
- char *file_name = NULL;
- zend_uint file_len = 0;
- zend_ulong file_idx = 0L;
- phpdbg_writeln(SEPARATE);
- phpdbg_writeln("File opline Breakpoints:");
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], &position[0]);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], (void**) &file_table, &position[0]) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], &position[0])) {
-
- if (zend_hash_get_current_key_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE],
- &file_name, &file_len, &file_idx, 0, &position[0]) == HASH_KEY_IS_STRING) {
-
- phpdbg_breakopline_t *brake;
-
- for (zend_hash_internal_pointer_reset_ex(file_table, &position[1]);
- zend_hash_get_current_data_ex(file_table, (void**)&brake, &position[1]) == SUCCESS;
- zend_hash_move_forward_ex(file_table, &position[1])) {
- phpdbg_writeln("#%d\t\t%s opline %ld%s",
- brake->id, brake->class_name, brake->opline_num,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
- }
- }
- }
+ phpdbg_out(SEPARATE "\n");
+ phpdbg_out("File opline Breakpoints:\n");
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE], file_table) {
+ phpdbg_breakopline_t *brake;
+
+ ZEND_HASH_FOREACH_PTR(file_table, brake) {
+ phpdbg_writeln("fileopline", "id=\"%d\" name=\"%s\" num=\"%ld\" disabled=\"%s\"", "#%d\t\t%s opline %ld%s",
+ brake->id, brake->class_name, brake->opline_num,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
+ } ZEND_HASH_FOREACH_END();
+ } ZEND_HASH_FOREACH_END();
} break;
case PHPDBG_BREAK_COND: if ((PHPDBG_G(flags) & PHPDBG_HAS_COND_BP)) {
- HashPosition position;
phpdbg_breakcond_t *brake;
- phpdbg_writeln(SEPARATE);
- phpdbg_writeln("Conditional Breakpoints:");
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], (void**) &brake, &position) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], &position)) {
+ phpdbg_out(SEPARATE "\n");
+ phpdbg_out("Conditional Breakpoints:\n");
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_COND], brake) {
if (brake->paramed) {
switch (brake->param.type) {
case STR_PARAM:
- phpdbg_writeln("#%d\t\tat %s if %s%s",
- brake->id,
- brake->param.str,
- brake->code,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
+ phpdbg_writeln("evalfunction", "id=\"%d\" name=\"%s\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat %s if %s%s",
+ brake->id, brake->param.str, brake->code,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
break;
case NUMERIC_FUNCTION_PARAM:
- phpdbg_writeln("#%d\t\tat %s#%ld if %s%s",
- brake->id,
- brake->param.str,
- brake->param.num,
- brake->code,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
+ phpdbg_writeln("evalfunctionopline", "id=\"%d\" name=\"%s\" num=\"%ld\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat %s#%ld if %s%s",
+ brake->id, brake->param.str, brake->param.num, brake->code,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
break;
case METHOD_PARAM:
- phpdbg_writeln("#%d\t\tat %s::%s if %s%s",
- brake->id,
- brake->param.method.class,
- brake->param.method.name,
- brake->code,
+ phpdbg_writeln("evalmethod", "id=\"%d\" name=\"%s::%s\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat %s::%s if %s%s",
+ brake->id, brake->param.method.class, brake->param.method.name, brake->code,
((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
break;
case NUMERIC_METHOD_PARAM:
- phpdbg_writeln("#%d\t\tat %s::%s#%ld if %s%s",
- brake->id,
- brake->param.method.class,
- brake->param.method.name,
- brake->param.num,
- brake->code,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
+ phpdbg_writeln("evalmethodopline", "id=\"%d\" name=\"%s::%s\" num=\"%d\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat %s::%s#%ld if %s%s",
+ brake->id, brake->param.method.class, brake->param.method.name, brake->param.num, brake->code,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
break;
case FILE_PARAM:
- phpdbg_writeln("#%d\t\tat %s:%lu if %s%s",
- brake->id,
- brake->param.file.name,
- brake->param.file.line,
- brake->code,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
+ phpdbg_writeln("evalfile", "id=\"%d\" name=\"%s\" line=\"%d\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat %s:%lu if %s%s",
+ brake->id, brake->param.file.name, brake->param.file.line, brake->code,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
break;
case ADDR_PARAM:
- phpdbg_writeln("#%d\t\tat #%lx if %s%s",
- brake->id,
- brake->param.addr,
- brake->code,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
+ phpdbg_writeln("evalopline", "id=\"%d\" opline=\"%#lx\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tat #%lx if %s%s",
+ brake->id, brake->param.addr, brake->code,
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
break;
default:
- phpdbg_error("Invalid parameter type for conditional breakpoint");
+ phpdbg_error("eval", "type=\"invalidparameter\"", "Invalid parameter type for conditional breakpoint");
return;
}
} else {
- phpdbg_writeln("#%d\t\tif %s%s",
+ phpdbg_writeln("eval", "id=\"%d\" eval=\"%s\" disabled=\"%s\"", "#%d\t\tif %s%s",
brake->id, brake->code,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
}
- }
+ } ZEND_HASH_FOREACH_END();
} break;
case PHPDBG_BREAK_OPCODE: if (PHPDBG_G(flags) & PHPDBG_HAS_OPCODE_BP) {
- HashPosition position;
phpdbg_breakop_t *brake;
- phpdbg_writeln(SEPARATE);
- phpdbg_writeln("Opcode Breakpoints:");
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], &position);
- zend_hash_get_current_data_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], (void**) &brake, &position) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], &position)) {
- phpdbg_writeln("#%d\t\t%s%s",
+ phpdbg_out(SEPARATE "\n");
+ phpdbg_out("Opcode Breakpoints:\n");
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(bp)[PHPDBG_BREAK_OPCODE], brake) {
+ phpdbg_writeln("opcode", "id=\"%d\" name=\"%s\" disabled=\"%s\"", "#%d\t\t%s%s",
brake->id, brake->name,
- ((phpdbg_breakbase_t*)brake)->disabled ? " [disabled]" : "");
- }
+ ((phpdbg_breakbase_t *) brake)->disabled ? " [disabled]" : "");
+ } ZEND_HASH_FOREACH_END();
} break;
}
+
+ phpdbg_xml("</breakpoints>");
} /* }}} */
diff --git a/sapi/phpdbg/phpdbg_bp.h b/sapi/phpdbg/phpdbg_bp.h
index 3b75db952e..5cf3f5631d 100644
--- a/sapi/phpdbg/phpdbg_bp.h
+++ b/sapi/phpdbg/phpdbg_bp.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -21,6 +21,20 @@
#ifndef PHPDBG_BP_H
#define PHPDBG_BP_H
+/* {{{ defines */
+#define PHPDBG_BREAK_FILE 0
+#define PHPDBG_BREAK_FILE_PENDING 1
+#define PHPDBG_BREAK_SYM 2
+#define PHPDBG_BREAK_OPLINE 3
+#define PHPDBG_BREAK_METHOD 4
+#define PHPDBG_BREAK_COND 5
+#define PHPDBG_BREAK_OPCODE 6
+#define PHPDBG_BREAK_FUNCTION_OPLINE 7
+#define PHPDBG_BREAK_METHOD_OPLINE 8
+#define PHPDBG_BREAK_FILE_OPLINE 9
+#define PHPDBG_BREAK_MAP 10
+#define PHPDBG_BREAK_TABLES 11 /* }}} */
+
/* {{{ */
typedef struct _zend_op *phpdbg_opline_ptr_t; /* }}} */
@@ -103,44 +117,47 @@ typedef struct _phpdbg_breakcond_t {
zend_op_array *ops;
} phpdbg_breakcond_t;
-/* {{{ Opline breaks API */
-PHPDBG_API void phpdbg_resolve_op_array_breaks(zend_op_array *op_array TSRMLS_DC);
-PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_op_array *op_array TSRMLS_DC);
-PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break TSRMLS_DC); /* }}} */
+/* {{{ Resolving breaks API */
+PHPDBG_API void phpdbg_resolve_op_array_breaks(zend_op_array *op_array);
+PHPDBG_API int phpdbg_resolve_op_array_break(phpdbg_breakopline_t *brake, zend_op_array *op_array);
+PHPDBG_API int phpdbg_resolve_opline_break(phpdbg_breakopline_t *new_break);
+PHPDBG_API HashTable *phpdbg_resolve_pending_file_break_ex(const char *file, uint filelen, zend_string *cur, HashTable *fileht);
+PHPDBG_API void phpdbg_resolve_pending_file_break(const char *file); /* }}} */
/* {{{ Breakpoint Creation API */
-PHPDBG_API void phpdbg_set_breakpoint_file(const char* filename, long lineno TSRMLS_DC);
-PHPDBG_API void phpdbg_set_breakpoint_symbol(const char* func_name, size_t func_name_len TSRMLS_DC);
-PHPDBG_API void phpdbg_set_breakpoint_method(const char* class_name, const char* func_name TSRMLS_DC);
-PHPDBG_API void phpdbg_set_breakpoint_opcode(const char* opname, size_t opname_len TSRMLS_DC);
-PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline TSRMLS_DC);
-PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline TSRMLS_DC);
-PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, zend_ulong opline TSRMLS_DC);
-PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend_ulong opline TSRMLS_DC);
-PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong opline TSRMLS_DC);
-PHPDBG_API void phpdbg_set_breakpoint_expression(const char* expression, size_t expression_len TSRMLS_DC);
-PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param TSRMLS_DC); /* }}} */
+PHPDBG_API void phpdbg_set_breakpoint_file(const char* filename, long lineno);
+PHPDBG_API void phpdbg_set_breakpoint_symbol(const char* func_name, size_t func_name_len);
+PHPDBG_API void phpdbg_set_breakpoint_method(const char* class_name, const char* func_name);
+PHPDBG_API void phpdbg_set_breakpoint_opcode(const char* opname, size_t opname_len);
+PHPDBG_API void phpdbg_set_breakpoint_opline(zend_ulong opline);
+PHPDBG_API void phpdbg_set_breakpoint_opline_ex(phpdbg_opline_ptr_t opline);
+PHPDBG_API void phpdbg_set_breakpoint_method_opline(const char *class, const char *method, zend_ulong opline);
+PHPDBG_API void phpdbg_set_breakpoint_function_opline(const char *function, zend_ulong opline);
+PHPDBG_API void phpdbg_set_breakpoint_file_opline(const char *file, zend_ulong opline);
+PHPDBG_API void phpdbg_set_breakpoint_expression(const char* expression, size_t expression_len);
+PHPDBG_API void phpdbg_set_breakpoint_at(const phpdbg_param_t *param); /* }}} */
/* {{{ Breakpoint Detection API */
-PHPDBG_API phpdbg_breakbase_t* phpdbg_find_breakpoint(zend_execute_data* TSRMLS_DC); /* }}} */
+PHPDBG_API phpdbg_breakbase_t* phpdbg_find_breakpoint(zend_execute_data*); /* }}} */
/* {{{ Misc Breakpoint API */
-PHPDBG_API void phpdbg_hit_breakpoint(phpdbg_breakbase_t* brake, zend_bool output TSRMLS_DC);
-PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type TSRMLS_DC);
-PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t* brake TSRMLS_DC);
-PHPDBG_API void phpdbg_reset_breakpoints(TSRMLS_D);
-PHPDBG_API void phpdbg_clear_breakpoints(TSRMLS_D);
-PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num TSRMLS_DC);
-PHPDBG_API void phpdbg_enable_breakpoints(TSRMLS_D);
-PHPDBG_API void phpdbg_enable_breakpoint(zend_ulong id TSRMLS_DC);
-PHPDBG_API void phpdbg_disable_breakpoint(zend_ulong id TSRMLS_DC);
-PHPDBG_API void phpdbg_disable_breakpoints(TSRMLS_D); /* }}} */
+PHPDBG_API void phpdbg_hit_breakpoint(phpdbg_breakbase_t* brake, zend_bool output);
+PHPDBG_API void phpdbg_print_breakpoints(zend_ulong type);
+PHPDBG_API void phpdbg_print_breakpoint(phpdbg_breakbase_t* brake);
+PHPDBG_API void phpdbg_reset_breakpoints(void);
+PHPDBG_API void phpdbg_clear_breakpoints(void);
+PHPDBG_API void phpdbg_delete_breakpoint(zend_ulong num);
+PHPDBG_API void phpdbg_enable_breakpoints(void);
+PHPDBG_API void phpdbg_enable_breakpoint(zend_ulong id);
+PHPDBG_API void phpdbg_disable_breakpoint(zend_ulong id);
+PHPDBG_API void phpdbg_disable_breakpoints(void); /* }}} */
/* {{{ Breakbase API */
-PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase(zend_ulong id TSRMLS_DC);
-PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable ***table, HashPosition *position TSRMLS_DC); /* }}} */
+PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase(zend_ulong id);
+PHPDBG_API phpdbg_breakbase_t *phpdbg_find_breakbase_ex(zend_ulong id, HashTable **table, zend_ulong *numkey, zend_string **strkey); /* }}} */
/* {{{ Breakpoint Exportation API */
-PHPDBG_API void phpdbg_export_breakpoints(FILE *handle TSRMLS_DC); /* }}} */
+PHPDBG_API void phpdbg_export_breakpoints(FILE *handle);
+PHPDBG_API void phpdbg_export_breakpoints_to_string(char **str); /* }}} */
#endif /* PHPDBG_BP_H */
diff --git a/sapi/phpdbg/phpdbg_break.c b/sapi/phpdbg/phpdbg_break.c
index 470c31b01e..c0465ff417 100644
--- a/sapi/phpdbg/phpdbg_break.c
+++ b/sapi/phpdbg/phpdbg_break.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -28,28 +28,28 @@
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-#define PHPDBG_BREAK_COMMAND_D(f, h, a, m, l, s) \
- PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[10])
+#define PHPDBG_BREAK_COMMAND_D(f, h, a, m, l, s, flags) \
+ PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[9], flags)
/**
* Commands
*/
const phpdbg_command_t phpdbg_break_commands[] = {
- PHPDBG_BREAK_COMMAND_D(at, "specify breakpoint by location and condition", '@', break_at, NULL, "*c"),
- PHPDBG_BREAK_COMMAND_D(del, "delete breakpoint by identifier number", '~', break_del, NULL, "n"),
+ PHPDBG_BREAK_COMMAND_D(at, "specify breakpoint by location and condition", '@', break_at, NULL, "*c", 0),
+ PHPDBG_BREAK_COMMAND_D(del, "delete breakpoint by identifier number", '~', break_del, NULL, "n", 0),
PHPDBG_END_COMMAND
};
PHPDBG_BREAK(at) /* {{{ */
{
- phpdbg_set_breakpoint_at(param TSRMLS_CC);
+ phpdbg_set_breakpoint_at(param);
return SUCCESS;
} /* }}} */
PHPDBG_BREAK(del) /* {{{ */
{
- phpdbg_delete_breakpoint(param->num TSRMLS_CC);
+ phpdbg_delete_breakpoint(param->num);
return SUCCESS;
} /* }}} */
diff --git a/sapi/phpdbg/phpdbg_break.h b/sapi/phpdbg/phpdbg_break.h
index 2b6adea4a9..deb5031a12 100644
--- a/sapi/phpdbg/phpdbg_break.h
+++ b/sapi/phpdbg/phpdbg_break.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
diff --git a/sapi/phpdbg/phpdbg_btree.c b/sapi/phpdbg/phpdbg_btree.c
index fb42e6a47d..99ea7c0a0f 100644
--- a/sapi/phpdbg/phpdbg_btree.c
+++ b/sapi/phpdbg/phpdbg_btree.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -66,7 +66,6 @@ phpdbg_btree_result *phpdbg_btree_find(phpdbg_btree *tree, zend_ulong idx) {
phpdbg_btree_result *phpdbg_btree_find_closest(phpdbg_btree *tree, zend_ulong idx) {
phpdbg_btree_branch *branch = tree->branch;
int i = tree->depth - 1, last_superior_i = -1;
- zend_bool had_alternative_branch = 0;
if (branch == NULL) {
return NULL;
@@ -74,30 +73,33 @@ phpdbg_btree_result *phpdbg_btree_find_closest(phpdbg_btree *tree, zend_ulong id
/* find nearest watchpoint */
do {
- /* an impossible branch was found if: */
- if (!had_alternative_branch && (idx >> i) % 2 == 0 && !branch->branches[0]) {
- /* there's no lower branch than idx */
- if (last_superior_i == -1) {
- /* failure */
- return NULL;
- }
- /* reset state */
- branch = tree->branch;
- i = tree->depth - 1;
- /* follow branch according to bits in idx until the last lower branch before the impossible branch */
- do {
- CHOOSE_BRANCH((idx >> i) % 2 == 1 && branch->branches[1]);
- } while (--i > last_superior_i);
- /* use now the lower branch of which we can be sure that it contains only branches lower than idx */
- CHOOSE_BRANCH(0);
- /* and choose the highest possible branch in the branch containing only branches lower than idx */
- while (i--) {
- CHOOSE_BRANCH(branch->branches[1]);
+ if ((idx >> i) % 2 == 0) {
+ if (branch->branches[0]) {
+ CHOOSE_BRANCH(0);
+ /* an impossible branch was found if: */
+ } else {
+ /* there's no lower branch than idx */
+ if (last_superior_i == -1) {
+ /* failure */
+ return NULL;
+ }
+ /* reset state */
+ branch = tree->branch;
+ i = tree->depth - 1;
+ /* follow branch according to bits in idx until the last lower branch before the impossible branch */
+ do {
+ CHOOSE_BRANCH((idx >> i) % 2 == 1 && branch->branches[1]);
+ } while (--i > last_superior_i);
+ /* use now the lower branch of which we can be sure that it contains only branches lower than idx */
+ CHOOSE_BRANCH(0);
+ /* and choose the highest possible branch in the branch containing only branches lower than idx */
+ while (i--) {
+ CHOOSE_BRANCH(branch->branches[1]);
+ }
+ break;
}
- break;
- }
/* follow branch according to bits in idx until having found an impossible branch */
- if (had_alternative_branch || (idx >> i) % 2 == 1) {
+ } else {
if (branch->branches[1]) {
if (branch->branches[0]) {
last_superior_i = i;
@@ -105,10 +107,11 @@ phpdbg_btree_result *phpdbg_btree_find_closest(phpdbg_btree *tree, zend_ulong id
CHOOSE_BRANCH(1);
} else {
CHOOSE_BRANCH(0);
- had_alternative_branch = 1;
+ while (i--) {
+ CHOOSE_BRANCH(branch->branches[1]);
+ }
+ break;
}
- } else {
- CHOOSE_BRANCH(0);
}
} while (i--);
@@ -219,3 +222,18 @@ check_branch_existence:
return SUCCESS;
}
+
+void phpdbg_btree_branch_dump(phpdbg_btree_branch *branch, zend_ulong depth) {
+ if (branch) {
+ if (depth--) {
+ phpdbg_btree_branch_dump(branch->branches[0], depth);
+ phpdbg_btree_branch_dump(branch->branches[1], depth);
+ } else {
+ fprintf(stderr, "%p: %p\n", (void *) branch->result.idx, branch->result.ptr);
+ }
+ }
+}
+
+void phpdbg_btree_dump(phpdbg_btree *tree) {
+ phpdbg_btree_branch_dump(tree->branch, tree->depth);
+}
diff --git a/sapi/phpdbg/phpdbg_btree.h b/sapi/phpdbg/phpdbg_btree.h
index 3ea1ebd4dc..08b645ede4 100644
--- a/sapi/phpdbg/phpdbg_btree.h
+++ b/sapi/phpdbg/phpdbg_btree.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -62,4 +62,9 @@ int phpdbg_btree_insert_or_update(phpdbg_btree *tree, zend_ulong idx, void *ptr,
#define phpdbg_btree_update(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_UPDATE)
#define phpdbg_btree_overwrite(tree, idx, ptr) phpdbg_btree_insert_or_update(tree, idx, ptr, PHPDBG_BTREE_OWERWRITE)
+
+/* debugging functions */
+void phpdbg_btree_branch_dump(phpdbg_btree_branch *branch, zend_ulong depth);
+void phpdbg_btree_dump(phpdbg_btree *tree);
+
#endif
diff --git a/sapi/phpdbg/phpdbg_cmd.c b/sapi/phpdbg/phpdbg_cmd.c
index 27335b0f1b..d71ac4181c 100644
--- a/sapi/phpdbg/phpdbg_cmd.c
+++ b/sapi/phpdbg/phpdbg_cmd.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -23,6 +23,7 @@
#include "phpdbg_utils.h"
#include "phpdbg_set.h"
#include "phpdbg_prompt.h"
+#include "phpdbg_io.h"
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
@@ -39,11 +40,11 @@ static inline const char *phpdbg_command_name(const phpdbg_command_t *command, c
memcpy(&buffer[pos], command->name, command->name_len);
pos += command->name_len;
buffer[pos] = 0;
-
+
return buffer;
}
-PHPDBG_API const char *phpdbg_get_param_type(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */
+PHPDBG_API const char *phpdbg_get_param_type(const phpdbg_param_t *param) /* {{{ */
{
switch (param->type) {
case STACK_PARAM:
@@ -69,7 +70,7 @@ PHPDBG_API const char *phpdbg_get_param_type(const phpdbg_param_t *param TSRMLS_
}
}
-PHPDBG_API void phpdbg_clear_param(phpdbg_param_t *param TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_clear_param(phpdbg_param_t *param) /* {{{ */
{
if (param) {
switch (param->type) {
@@ -90,80 +91,60 @@ PHPDBG_API void phpdbg_clear_param(phpdbg_param_t *param TSRMLS_DC) /* {{{ */
} /* }}} */
-PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer TSRMLS_DC) /* {{{ */
+PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer) /* {{{ */
{
switch (param->type) {
case STR_PARAM:
- asprintf(pointer,
- "%s", param->str);
+ ZEND_IGNORE_VALUE(asprintf(pointer, "%s", param->str));
break;
case ADDR_PARAM:
- asprintf(pointer,
- "%#lx", param->addr);
+ ZEND_IGNORE_VALUE(asprintf(pointer, ZEND_ULONG_FMT, param->addr));
break;
case NUMERIC_PARAM:
- asprintf(pointer,
- "%li",
- param->num);
+ ZEND_IGNORE_VALUE(asprintf(pointer, "%li", param->num));
break;
case METHOD_PARAM:
- asprintf(pointer,
- "%s::%s",
- param->method.class,
- param->method.name);
+ ZEND_IGNORE_VALUE(asprintf(pointer, "%s::%s", param->method.class, param->method.name));
break;
case FILE_PARAM:
if (param->num) {
- asprintf(pointer,
- "%s:%lu#%lu",
- param->file.name,
- param->file.line,
- param->num);
+ ZEND_IGNORE_VALUE(asprintf(pointer, "%s:%lu#%lu", param->file.name, param->file.line, param->num));
} else {
- asprintf(pointer,
- "%s:%lu",
- param->file.name,
- param->file.line);
+ ZEND_IGNORE_VALUE(asprintf(pointer, "%s:%lu", param->file.name, param->file.line));
}
break;
case NUMERIC_FUNCTION_PARAM:
- asprintf(pointer,
- "%s#%lu", param->str, param->num);
+ ZEND_IGNORE_VALUE(asprintf(pointer, "%s#%lu", param->str, param->num));
break;
case NUMERIC_METHOD_PARAM:
- asprintf(pointer,
- "%s::%s#%lu",
- param->method.class,
- param->method.name,
- param->num);
+ ZEND_IGNORE_VALUE(asprintf(pointer, "%s::%s#%lu", param->method.class, param->method.name, param->num));
break;
default:
- asprintf(pointer,
- "%s", "unknown");
+ *pointer = strdup("unknown");
}
return *pointer;
} /* }}} */
-PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t* src, phpdbg_param_t* dest TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t* src, phpdbg_param_t* dest) /* {{{ */
{
switch ((dest->type = src->type)) {
case STACK_PARAM:
/* nope */
break;
-
+
case STR_PARAM:
dest->str = estrndup(src->str, src->len);
dest->len = src->len;
break;
-
+
case OP_PARAM:
dest->str = estrndup(src->str, src->len);
dest->len = src->len;
@@ -203,14 +184,14 @@ PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t* src, phpdbg_param_t* des
break;
case EMPTY_PARAM: { /* do nothing */ } break;
-
+
default: {
/* not yet */
}
}
} /* }}} */
-PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) /* {{{ */
+PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param) /* {{{ */
{
zend_ulong hash = param->type;
@@ -218,7 +199,7 @@ PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) /
case STACK_PARAM:
/* nope */
break;
-
+
case STR_PARAM:
hash += zend_inline_hash_func(param->str, param->len);
break;
@@ -256,7 +237,7 @@ PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) /
break;
case EMPTY_PARAM: { /* do nothing */ } break;
-
+
default: {
/* not yet */
}
@@ -265,7 +246,7 @@ PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *param TSRMLS_DC) /
return hash;
} /* }}} */
-PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *l, const phpdbg_param_t *r TSRMLS_DC) /* {{{ */
+PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *l, const phpdbg_param_t *r) /* {{{ */
{
if (l && r) {
if (l->type == r->type) {
@@ -274,7 +255,7 @@ PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *l, const phpdbg_pa
/* nope, or yep */
return 1;
break;
-
+
case NUMERIC_FUNCTION_PARAM:
if (l->num != r->num) {
break;
@@ -329,7 +310,7 @@ PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *l, const phpdbg_pa
case EMPTY_PARAM:
return 1;
-
+
default: {
/* not yet */
}
@@ -344,45 +325,45 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg)
if (param && param->type) {
switch (param->type) {
case STR_PARAM:
- fprintf(stderr, "%s STR_PARAM(%s=%lu)\n", msg, param->str, param->len);
+ fprintf(stderr, "%s STR_PARAM(%s=%zu)\n", msg, param->str, param->len);
break;
-
+
case ADDR_PARAM:
- fprintf(stderr, "%s ADDR_PARAM(%lu)\n", msg, param->addr);
+ fprintf(stderr, "%s ADDR_PARAM(" ZEND_ULONG_FMT ")\n", msg, param->addr);
break;
-
+
case NUMERIC_FILE_PARAM:
fprintf(stderr, "%s NUMERIC_FILE_PARAM(%s:#%lu)\n", msg, param->file.name, param->file.line);
break;
-
+
case FILE_PARAM:
fprintf(stderr, "%s FILE_PARAM(%s:%lu)\n", msg, param->file.name, param->file.line);
break;
-
+
case METHOD_PARAM:
fprintf(stderr, "%s METHOD_PARAM(%s::%s)\n", msg, param->method.class, param->method.name);
break;
-
+
case NUMERIC_METHOD_PARAM:
fprintf(stderr, "%s NUMERIC_METHOD_PARAM(%s::%s)\n", msg, param->method.class, param->method.name);
break;
-
+
case NUMERIC_FUNCTION_PARAM:
fprintf(stderr, "%s NUMERIC_FUNCTION_PARAM(%s::%ld)\n", msg, param->str, param->num);
break;
-
+
case NUMERIC_PARAM:
fprintf(stderr, "%s NUMERIC_PARAM(%ld)\n", msg, param->num);
break;
-
+
case COND_PARAM:
- fprintf(stderr, "%s COND_PARAM(%s=%lu)\n", msg, param->str, param->len);
+ fprintf(stderr, "%s COND_PARAM(%s=%zu)\n", msg, param->str, param->len);
break;
-
+
case OP_PARAM:
- fprintf(stderr, "%s OP_PARAM(%s=%lu)\n", msg, param->str, param->len);
+ fprintf(stderr, "%s OP_PARAM(%s=%zu)\n", msg, param->str, param->len);
break;
-
+
default: {
/* not yet */
}
@@ -394,49 +375,58 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg)
PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack) {
if (stack && stack->next) {
phpdbg_param_t *remove = stack->next;
-
+
while (remove) {
phpdbg_param_t *next = NULL;
-
+
if (remove->next)
next = remove->next;
-
+
switch (remove->type) {
case NUMERIC_METHOD_PARAM:
case METHOD_PARAM:
- if (remove->method.class)
- free(remove->method.class);
- if (remove->method.name)
- free(remove->method.name);
+ if (remove->method.class) {
+ efree(remove->method.class);
+ }
+ if (remove->method.name) {
+ efree(remove->method.name);
+ }
break;
case NUMERIC_FUNCTION_PARAM:
case STR_PARAM:
case OP_PARAM:
- if (remove->str)
- free(remove->str);
+ case EVAL_PARAM:
+ case SHELL_PARAM:
+ case COND_PARAM:
+ case RUN_PARAM:
+ if (remove->str) {
+ efree(remove->str);
+ }
break;
-
+
case NUMERIC_FILE_PARAM:
case FILE_PARAM:
- if (remove->file.name)
- free(remove->file.name);
+ if (remove->file.name) {
+ efree(remove->file.name);
+ }
break;
-
+
default: {
/* nothing */
}
}
-
+
free(remove);
remove = NULL;
-
+
if (next)
- remove = next;
+ remove = next;
else break;
}
}
-
+
+
stack->next = NULL;
} /* }}} */
@@ -444,8 +434,9 @@ PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack) {
PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param) {
phpdbg_param_t *next = calloc(1, sizeof(phpdbg_param_t));
- if (!next)
+ if (!next) {
return;
+ }
*(next) = *(param);
@@ -464,30 +455,39 @@ PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param)
stack->len++;
} /* }}} */
-PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack, char **why TSRMLS_DC) {
+/* {{{ */
+PHPDBG_API void phpdbg_stack_separate(phpdbg_param_t *param) {
+ phpdbg_param_t *stack = calloc(1, sizeof(phpdbg_param_t));
+
+ stack->type = STACK_PARAM;
+ stack->next = param->next;
+ param->next = stack;
+ stack->top = param->top;
+} /* }}} */
+
+PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack) {
if (command) {
char buffer[128] = {0,};
const phpdbg_param_t *top = (stack != NULL) ? *stack : NULL;
const char *arg = command->args;
size_t least = 0L,
- received = 0L,
- current = 0L;
+ received = 0L,
+ current = 0L;
zend_bool optional = 0;
-
+
/* check for arg spec */
if (!(arg) || !(*arg)) {
- if (!top) {
+ if (!top || top->type == STACK_PARAM) {
return SUCCESS;
}
-
- asprintf(why,
- "The command \"%s\" expected no arguments",
+
+ phpdbg_error("command", "type=\"toomanyargs\" command=\"%s\" expected=\"0\"", "The command \"%s\" expected no arguments",
phpdbg_command_name(command, buffer));
return FAILURE;
}
-
+
least = 0L;
-
+
/* count least amount of arguments */
while (arg && *arg) {
if (arg[0] == '|') {
@@ -496,38 +496,40 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param
least++;
arg++;
}
-
+
arg = command->args;
#define verify_arg(e, a, t) if (!(a)) { \
if (!optional) { \
- asprintf(why, \
- "The command \"%s\" expected %s and got nothing at parameter %lu", \
+ phpdbg_error("command", "type=\"noarg\" command=\"%s\" expected=\"%s\" num=\"%lu\"", "The command \"%s\" expected %s and got nothing at parameter %lu", \
phpdbg_command_name(command, buffer), \
(e), \
current); \
return FAILURE;\
} \
} else if ((a)->type != (t)) { \
- asprintf(why, \
- "The command \"%s\" expected %s and got %s at parameter %lu", \
+ phpdbg_error("command", "type=\"wrongarg\" command=\"%s\" expected=\"%s\" got=\"%s\" num=\"%lu\"", "The command \"%s\" expected %s and got %s at parameter %lu", \
phpdbg_command_name(command, buffer), \
(e),\
- phpdbg_get_param_type((a) TSRMLS_CC), \
+ phpdbg_get_param_type((a)), \
current); \
return FAILURE; \
}
while (arg && *arg) {
+ if (top && top->type == STACK_PARAM) {
+ break;
+ }
+
current++;
-
+
switch (*arg) {
case '|': {
current--;
optional = 1;
arg++;
} continue;
-
+
case 'i': verify_arg("raw input", top, STR_PARAM); break;
case 's': verify_arg("string", top, STR_PARAM); break;
case 'n': verify_arg("number", top, NUMERIC_PARAM); break;
@@ -537,14 +539,16 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param
case 'c': verify_arg("condition", top, COND_PARAM); break;
case 'o': verify_arg("opcode", top, OP_PARAM); break;
case 'b': verify_arg("boolean", top, NUMERIC_PARAM); break;
-
+
case '*': { /* do nothing */ } break;
}
-
- if (top ) {
+
+ if (top) {
top = top->next;
- } else break;
-
+ } else {
+ break;
+ }
+
received++;
arg++;
}
@@ -552,28 +556,27 @@ PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param
#undef verify_arg
if ((received < least)) {
- asprintf(why,
- "The command \"%s\" expected at least %lu arguments (%s) and received %lu",
+ phpdbg_error("command", "type=\"toofewargs\" command=\"%s\" expected=\"%d\" argtypes=\"%s\" got=\"%d\"", "The command \"%s\" expected at least %lu arguments (%s) and received %lu",
phpdbg_command_name(command, buffer),
least,
- command->args,
+ command->args,
received);
return FAILURE;
}
}
-
+
return SUCCESS;
}
/* {{{ */
-PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top, char **why) {
+PHPDBG_API const phpdbg_command_t *phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top) {
const phpdbg_command_t *command = commands;
phpdbg_param_t *name = *top;
const phpdbg_command_t *matched[3] = {NULL, NULL, NULL};
ulong matches = 0L;
-
+
while (command && command->name && command->handler) {
- if ((name->len == 1) || (command->name_len >= name->len)) {
+ if (name->len == 1 || command->name_len >= name->len) {
/* match single letter alias */
if (command->alias && (name->len == 1)) {
if (command->alias == (*name->str)) {
@@ -581,85 +584,76 @@ PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t *
matches++;
}
} else {
-
/* match full, case insensitive, command name */
if (strncasecmp(command->name, name->str, name->len) == SUCCESS) {
if (matches < 3) {
-
/* only allow abbreviating commands that can be aliased */
- if (((name->len != command->name_len) && command->alias) ||
- (name->len == command->name_len)) {
+ if ((name->len != command->name_len && command->alias) || name->len == command->name_len) {
matched[matches] = command;
matches++;
}
-
-
+
/* exact match */
- if (name->len == command->name_len)
+ if (name->len == command->name_len) {
break;
- } else break;
+ }
+ } else {
+ break;
+ }
}
}
}
-
+
command++;
}
-
+
switch (matches) {
- case 0: {
+ case 0:
if (parent) {
- asprintf(
- why,
- "The command \"%s %s\" could not be found",
- parent->name, name->str);
- } else asprintf(
- why,
- "The command \"%s\" could not be found",
- name->str);
- } return parent;
-
- case 1: {
+ phpdbg_error("command", "type=\"notfound\" command=\"%s\" subcommand=\"%s\"", "The command \"%s %s\" could not be found", parent->name, name->str);
+ } else {
+ phpdbg_error("command", "type=\"notfound\" command=\"%s\"", "The command \"%s\" could not be found", name->str);
+ }
+ return parent;
+
+ case 1:
(*top) = (*top)->next;
command = matched[0];
- } break;
-
+ break;
+
default: {
char *list = NULL;
- zend_uint it = 0;
+ uint32_t it = 0;
size_t pos = 0;
-
+
while (it < matches) {
if (!list) {
- list = malloc(
- matched[it]->name_len + 1 +
- ((it+1) < matches ? sizeof(", ")-1 : 0));
+ list = emalloc(matched[it]->name_len + 1 + (it + 1 < matches ? sizeof(", ") - 1 : 0));
} else {
- list = realloc(list,
- (pos + matched[it]->name_len) + 1 +
- ((it+1) < matches ? sizeof(", ")-1 : 0));
+ list = erealloc(list, (pos + matched[it]->name_len) + 1 + (it + 1 < matches ? sizeof(", ") - 1 : 0));
}
memcpy(&list[pos], matched[it]->name, matched[it]->name_len);
pos += matched[it]->name_len;
- if ((it+1) < matches) {
- memcpy(&list[pos], ", ", sizeof(", ")-1);
+ if ((it + 1) < matches) {
+ memcpy(&list[pos], ", ", sizeof(", ") - 1);
pos += (sizeof(", ") - 1);
}
-
+
list[pos] = 0;
it++;
}
-
- asprintf(
- why,
- "The command \"%s\" is ambigious, matching %lu commands (%s)",
- name->str, matches, list);
- free(list);
- } return NULL;
+
+ /* ", " separated matches */
+ phpdbg_error("command", "type=\"ambiguous\" command=\"%s\" matches=\"%lu\" matched=\"%s\"", "The command \"%s\" is ambigious, matching %lu commands (%s)", name->str, matches, list);
+ efree(list);
+
+ return NULL;
+ }
}
if (command->subs && (*top) && ((*top)->type == STR_PARAM)) {
- return phpdbg_stack_resolve(command->subs, command, top, why);
+ return phpdbg_stack_resolve(command->subs, command, top);
} else {
return command;
}
@@ -667,119 +661,126 @@ PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t *
return NULL;
} /* }}} */
-/* {{{ */
-PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, char **why TSRMLS_DC) {
- phpdbg_param_t *top = NULL;
+static int phpdbg_internal_stack_execute(phpdbg_param_t *stack, zend_bool allow_async_unsafe) {
const phpdbg_command_t *handler = NULL;
-
- if (stack->type != STACK_PARAM) {
- asprintf(
- why, "The passed argument was not a stack !!");
- return FAILURE;
- }
-
- if (!stack->len) {
- asprintf(
- why, "The stack contains nothing !!");
- return FAILURE;
- }
-
- top = (phpdbg_param_t*) stack->next;
-
+ phpdbg_param_t *top = (phpdbg_param_t *) stack->next;
+
switch (top->type) {
case EVAL_PARAM:
- return PHPDBG_COMMAND_HANDLER(ev)(top TSRMLS_CC);
+ phpdbg_activate_err_buf(0);
+ phpdbg_free_err_buf();
+ return PHPDBG_COMMAND_HANDLER(ev)(top);
case RUN_PARAM:
- return PHPDBG_COMMAND_HANDLER(run)(top TSRMLS_CC);
-
+ if (!allow_async_unsafe) {
+ phpdbg_error("signalsegv", "command=\"run\"", "run command is disallowed during hard interrupt");
+ }
+ phpdbg_activate_err_buf(0);
+ phpdbg_free_err_buf();
+ return PHPDBG_COMMAND_HANDLER(run)(top);
+
case SHELL_PARAM:
- return PHPDBG_COMMAND_HANDLER(sh)(top TSRMLS_CC);
-
+ if (!allow_async_unsafe) {
+ phpdbg_error("signalsegv", "command=\"sh\"", "sh command is disallowed during hard interrupt");
+ return FAILURE;
+ }
+ phpdbg_activate_err_buf(0);
+ phpdbg_free_err_buf();
+ return PHPDBG_COMMAND_HANDLER(sh)(top);
+
case STR_PARAM: {
- handler = phpdbg_stack_resolve(
- phpdbg_prompt_commands, NULL, &top, why);
-
+ handler = phpdbg_stack_resolve(phpdbg_prompt_commands, NULL, &top);
+
if (handler) {
- if (phpdbg_stack_verify(handler, &top, why TSRMLS_CC) == SUCCESS) {
- return handler->handler(top TSRMLS_CC);
+ if (!allow_async_unsafe && !(handler->flags & PHPDBG_ASYNC_SAFE)) {
+ phpdbg_error("signalsegv", "command=\"%s\"", "%s command is disallowed during hard interrupt", handler->name);
+ return FAILURE;
+ }
+
+ if (phpdbg_stack_verify(handler, &top) == SUCCESS) {
+ phpdbg_activate_err_buf(0);
+ phpdbg_free_err_buf();
+ return handler->handler(top);
}
}
} return FAILURE;
-
+
default:
- asprintf(
- why, "The first parameter makes no sense !!");
+ phpdbg_error("command", "type=\"invalidcommand\"", "The first parameter makes no sense !");
return FAILURE;
}
-
+
+ return SUCCESS;
+} /* }}} */
+
+/* {{{ */
+PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async_unsafe) {
+ phpdbg_param_t *top = stack;
+
+ if (stack->type != STACK_PARAM) {
+ phpdbg_error("command", "type=\"nostack\"", "The passed argument was not a stack !");
+ return FAILURE;
+ }
+
+ if (!stack->len) {
+ phpdbg_error("command", "type=\"emptystack\"", "The stack contains nothing !");
+ return FAILURE;
+ }
+
+ do {
+ if (top->type == STACK_PARAM) {
+ int result;
+ if ((result = phpdbg_internal_stack_execute(top, allow_async_unsafe)) != SUCCESS) {
+ return result;
+ }
+ }
+ } while ((top = top->next));
+
return SUCCESS;
} /* }}} */
-PHPDBG_API char* phpdbg_read_input(char *buffered TSRMLS_DC) /* {{{ */
+PHPDBG_API char *phpdbg_read_input(char *buffered) /* {{{ */
{
- char *cmd = NULL;
-#if !defined(HAVE_LIBREADLINE) && !defined(HAVE_LIBEDIT)
char buf[PHPDBG_MAX_CMD];
-#endif
+ char *cmd = NULL;
char *buffer = NULL;
- if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
- if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE) &&
- (buffered == NULL)) {
- fflush(PHPDBG_G(io)[PHPDBG_STDOUT]);
+ if ((PHPDBG_G(flags) & (PHPDBG_IS_STOPPING | PHPDBG_IS_RUNNING)) != PHPDBG_IS_STOPPING) {
+ if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE) && (buffered == NULL) && !phpdbg_active_sigsafe_mem()) {
+ fflush(PHPDBG_G(io)[PHPDBG_STDOUT].ptr);
}
if (buffered == NULL) {
-disconnect:
- if (0) {
- PHPDBG_G(flags) |= (PHPDBG_IS_QUITTING|PHPDBG_IS_DISCONNECTED);
- zend_bailout();
- return NULL;
+#define USE_LIB_STAR (defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT))
+ /* note: EOF makes readline write prompt again in local console mode - and ignored if compiled without readline */
+#if USE_LIB_STAR
+ if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE) || !isatty(PHPDBG_G(io)[PHPDBG_STDIN].fd))
+#endif
+ {
+ phpdbg_write("prompt", "", "%s", phpdbg_get_prompt());
+ phpdbg_consume_stdin_line(cmd = buf);
}
-
-#if !defined(HAVE_LIBREADLINE) && !defined(HAVE_LIBEDIT)
- if (!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
- if (!phpdbg_write("%s", phpdbg_get_prompt(TSRMLS_C))) {
- goto disconnect;
+#if USE_LIB_STAR
+ else {
+ cmd = readline(phpdbg_get_prompt());
+ PHPDBG_G(last_was_newline) = 1;
+
+ if (!cmd) {
+ PHPDBG_G(flags) |= PHPDBG_IS_QUITTING | PHPDBG_IS_DISCONNECTED;
+ zend_bailout();
}
- }
-
- /* note: EOF is ignored */
-readline:
- if (!fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
- /* the user has gone away */
- if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
- goto disconnect;
- } else goto readline;
- }
-
- cmd = buf;
-#else
- /* note: EOF makes readline write prompt again in local console mode */
-readline:
- if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
- char buf[PHPDBG_MAX_CMD];
- if (fgets(buf, PHPDBG_MAX_CMD, PHPDBG_G(io)[PHPDBG_STDIN])) {
- cmd = buf;
- } else goto disconnect;
- } else cmd = readline(phpdbg_get_prompt(TSRMLS_C));
-
- if (!cmd) {
- goto readline;
- }
- if (!(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
add_history(cmd);
}
#endif
- } else cmd = buffered;
-
+ } else {
+ cmd = buffered;
+ }
+
buffer = estrdup(cmd);
-#if defined(HAVE_LIBREADLINE) || defined(HAVE_LIBEDIT)
- if (!buffered && cmd &&
- !(PHPDBG_G(flags) & PHPDBG_IS_REMOTE)) {
+#if USE_LIB_STAR
+ if (!buffered && cmd && !(PHPDBG_G(flags) & PHPDBG_IS_REMOTE) && isatty(PHPDBG_G(io)[PHPDBG_STDIN].fd)) {
free(cmd);
}
#endif
@@ -797,20 +798,41 @@ readline:
if (buffer && strlen(buffer)) {
if (PHPDBG_G(buffer)) {
- efree(PHPDBG_G(buffer));
+ free(PHPDBG_G(buffer));
}
- PHPDBG_G(buffer) = estrdup(buffer);
- } else {
- if (PHPDBG_G(buffer)) {
- buffer = estrdup(PHPDBG_G(buffer));
+ PHPDBG_G(buffer) = strdup(buffer);
+ } else if (PHPDBG_G(buffer)) {
+ if (buffer) {
+ efree(buffer);
}
+ buffer = estrdup(PHPDBG_G(buffer));
}
-
+
return buffer;
} /* }}} */
-PHPDBG_API void phpdbg_destroy_input(char **input TSRMLS_DC) /*{{{ */
+PHPDBG_API void phpdbg_destroy_input(char **input) /*{{{ */
{
efree(*input);
} /* }}} */
+PHPDBG_API int phpdbg_ask_user_permission(const char *question) {
+ if (!(PHPDBG_G(flags) & PHPDBG_WRITE_XML)) {
+ char buf[PHPDBG_MAX_CMD];
+ phpdbg_out("%s", question);
+ phpdbg_out(" (type y or n): ");
+
+ while (1) {
+ phpdbg_consume_stdin_line(buf);
+ if (buf[1] == '\n' && (buf[0] == 'y' || buf[0] == 'n')) {
+ if (buf[0] == 'y') {
+ return SUCCESS;
+ }
+ return FAILURE;
+ }
+ phpdbg_out("Please enter either y (yes) or n (no): ");
+ }
+ }
+
+ return SUCCESS;
+}
diff --git a/sapi/phpdbg/phpdbg_cmd.h b/sapi/phpdbg/phpdbg_cmd.h
index d779da548e..e09c2a2116 100644
--- a/sapi/phpdbg/phpdbg_cmd.h
+++ b/sapi/phpdbg/phpdbg_cmd.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -86,7 +86,9 @@ struct _phpdbg_param {
#define YYSTYPE phpdbg_param_t
#endif
-typedef int (*phpdbg_command_handler_t)(const phpdbg_param_t* TSRMLS_DC);
+#define PHPDBG_ASYNC_SAFE 1
+
+typedef int (*phpdbg_command_handler_t)(const phpdbg_param_t*);
typedef struct _phpdbg_command_t phpdbg_command_t;
struct _phpdbg_command_t {
@@ -97,8 +99,9 @@ struct _phpdbg_command_t {
char alias; /* Alias */
phpdbg_command_handler_t handler; /* Command handler */
const phpdbg_command_t *subs; /* Sub Commands */
- char *args; /* Argument Spec */
- const phpdbg_command_t *parent; /* Parent Command */
+ char *args; /* Argument Spec */
+ const phpdbg_command_t *parent; /* Parent Command */
+ zend_bool flags; /* General flags */
};
/* }}} */
@@ -106,7 +109,7 @@ struct _phpdbg_command_t {
#define PHPDBG_STRL(s) s, sizeof(s)-1
#define PHPDBG_MAX_CMD 500
#define PHPDBG_FRAME(v) (PHPDBG_G(frame).v)
-#define PHPDBG_EX(v) (EG(current_execute_data)->v)
+#define PHPDBG_EX(v) (EG(current_execute_data)->v)
typedef struct {
int num;
@@ -126,27 +129,29 @@ typedef struct {
/*
* Input Management
*/
-PHPDBG_API char* phpdbg_read_input(char *buffered TSRMLS_DC);
-PHPDBG_API void phpdbg_destroy_input(char** TSRMLS_DC);
+PHPDBG_API char* phpdbg_read_input(char *buffered);
+PHPDBG_API void phpdbg_destroy_input(char**);
+PHPDBG_API int phpdbg_ask_user_permission(const char *question);
/**
* Stack Management
*/
PHPDBG_API void phpdbg_stack_push(phpdbg_param_t *stack, phpdbg_param_t *param);
-PHPDBG_API const phpdbg_command_t* phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top, char **why);
-PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack, char **why TSRMLS_DC);
-PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, char **why TSRMLS_DC);
+PHPDBG_API void phpdbg_stack_separate(phpdbg_param_t *param);
+PHPDBG_API const phpdbg_command_t *phpdbg_stack_resolve(const phpdbg_command_t *commands, const phpdbg_command_t *parent, phpdbg_param_t **top);
+PHPDBG_API int phpdbg_stack_verify(const phpdbg_command_t *command, phpdbg_param_t **stack);
+PHPDBG_API int phpdbg_stack_execute(phpdbg_param_t *stack, zend_bool allow_async_unsafe);
PHPDBG_API void phpdbg_stack_free(phpdbg_param_t *stack);
/*
* Parameter Management
*/
-PHPDBG_API void phpdbg_clear_param(phpdbg_param_t* TSRMLS_DC);
-PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t*, phpdbg_param_t* TSRMLS_DC);
-PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *, const phpdbg_param_t * TSRMLS_DC);
-PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t * TSRMLS_DC);
-PHPDBG_API const char* phpdbg_get_param_type(const phpdbg_param_t* TSRMLS_DC);
-PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer TSRMLS_DC);
+PHPDBG_API void phpdbg_clear_param(phpdbg_param_t*);
+PHPDBG_API void phpdbg_copy_param(const phpdbg_param_t*, phpdbg_param_t*);
+PHPDBG_API zend_bool phpdbg_match_param(const phpdbg_param_t *, const phpdbg_param_t *);
+PHPDBG_API zend_ulong phpdbg_hash_param(const phpdbg_param_t *);
+PHPDBG_API const char* phpdbg_get_param_type(const phpdbg_param_t*);
+PHPDBG_API char* phpdbg_param_tostring(const phpdbg_param_t *param, char **pointer);
PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg);
/**
@@ -154,27 +159,27 @@ PHPDBG_API void phpdbg_param_debug(const phpdbg_param_t *param, const char *msg)
*/
#define PHPDBG_COMMAND_HANDLER(name) phpdbg_do_##name
-#define PHPDBG_COMMAND_D_EXP(name, tip, alias, handler, children, args, parent) \
- {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, parent}
+#define PHPDBG_COMMAND_D_EXP(name, tip, alias, handler, children, args, parent, flags) \
+ {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, parent, flags}
-#define PHPDBG_COMMAND_D_EX(name, tip, alias, handler, children, args) \
- {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, NULL}
+#define PHPDBG_COMMAND_D_EX(name, tip, alias, handler, children, args, flags) \
+ {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##handler, children, args, NULL, flags}
-#define PHPDBG_COMMAND_D(name, tip, alias, children, args) \
- {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##name, children, args, NULL}
+#define PHPDBG_COMMAND_D(name, tip, alias, children, args, flags) \
+ {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, phpdbg_do_##name, children, args, NULL, flags}
-#define PHPDBG_COMMAND(name) int phpdbg_do_##name(const phpdbg_param_t *param TSRMLS_DC)
+#define PHPDBG_COMMAND(name) int phpdbg_do_##name(const phpdbg_param_t *param)
-#define PHPDBG_COMMAND_ARGS param TSRMLS_CC
+#define PHPDBG_COMMAND_ARGS param
-#define PHPDBG_END_COMMAND {NULL, 0, NULL, 0, '\0', NULL, NULL, '\0', NULL}
+#define PHPDBG_END_COMMAND {NULL, 0, NULL, 0, '\0', NULL, NULL, NULL, NULL, 0}
/*
* Default Switch Case
*/
#define phpdbg_default_switch_case() \
default: \
- phpdbg_error("Unsupported parameter type (%s) for command", phpdbg_get_param_type(param TSRMLS_CC)); \
+ phpdbg_error("command", "type=\"wrongarg\" got=\"%s\"", "Unsupported parameter type (%s) for command", phpdbg_get_param_type(param)); \
break
#endif /* PHPDBG_CMD_H */
diff --git a/sapi/phpdbg/phpdbg_eol.c b/sapi/phpdbg/phpdbg_eol.c
new file mode 100644
index 0000000000..4cc6ef1679
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_eol.c
@@ -0,0 +1,172 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Anatol Belski <ab@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "phpdbg.h"
+#include "phpdbg_eol.h"
+
+ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+
+#define EOL_LIST_LEN 4
+struct phpdbg_eol_rep phpdbg_eol_list[EOL_LIST_LEN] = {
+ {"CRLF", "\r\n", PHPDBG_EOL_CRLF},
+/* {"LFCR", "\n\r", PHPDBG_EOL_LFCR},*/
+ {"LF", "\n", PHPDBG_EOL_LF},
+ {"CR", "\r", PHPDBG_EOL_CR},
+};
+
+int phpdbg_eol_global_update(char *name)
+{
+
+ if (0 == memcmp(name, "CRLF", 4) || 0 == memcmp(name, "crlf", 4) || 0 == memcmp(name, "DOS", 3) || 0 == memcmp(name, "dos", 3)) {
+ PHPDBG_G(eol) = PHPDBG_EOL_CRLF;
+ } else if (0 == memcmp(name, "LF", 2) || 0 == memcmp(name, "lf", 2) || 0 == memcmp(name, "UNIX", 4) || 0 == memcmp(name, "unix", 4)) {
+ PHPDBG_G(eol) = PHPDBG_EOL_LF;
+ } else if (0 == memcmp(name, "CR", 2) || 0 == memcmp(name, "cr", 2) || 0 == memcmp(name, "MAC", 3) || 0 == memcmp(name, "mac", 3)) {
+ PHPDBG_G(eol) = PHPDBG_EOL_CR;
+ } else {
+ return FAILURE;
+ }
+
+ return SUCCESS;
+}
+
+char *phpdbg_eol_name(int id)
+{
+ size_t i = 0;
+
+ while (i < EOL_LIST_LEN) {
+
+ if (id == phpdbg_eol_list[i].id) {
+ return phpdbg_eol_list[i].name;
+ }
+
+ i++;
+ }
+
+ return NULL;
+}
+
+char *phpdbg_eol_rep(int id)
+{
+ size_t i = 0;
+
+ while (i < EOL_LIST_LEN) {
+
+ if (id == phpdbg_eol_list[i].id) {
+ return phpdbg_eol_list[i].rep;
+ }
+
+ i++;
+ }
+
+ return NULL;
+}
+
+
+/* Inspired by https://ccrma.stanford.edu/~craig/utility/flip/flip.cpp */
+void phpdbg_eol_convert(char **str, int *len)
+{
+ char *in = *str, *out ;
+ int in_len = *len, out_len, cursor, i;
+ char last, cur;
+
+ if ((PHPDBG_G(flags) & PHPDBG_IS_REMOTE) != PHPDBG_IS_REMOTE) {
+ return;
+ }
+
+ out_len = *len;
+ if (PHPDBG_EOL_CRLF == PHPDBG_G(eol)) { /* XXX add LFCR case if it's gonna be needed */
+ /* depending on the source EOL the out str will have all CR/LF duplicated */
+ for (i = 0; i < in_len; i++) {
+ if (0x0a == in[i] || 0x0d == in[i]) {
+ out_len++;
+ }
+ }
+ out = (char *)emalloc(out_len);
+
+ last = cur = in[0];
+ i = cursor = 0;
+ for (; i < in_len;) {
+ if (0x0a == cur && last != 0x0d) {
+ out[cursor] = 0x0d;
+ cursor++;
+ out[cursor] = cur;
+ } else if(0x0d == cur) {
+ if (i + 1 < in_len && 0x0a != in[i+1]) {
+ out[cursor] = cur;
+ cursor++;
+ out[cursor] = 0x0a;
+ last = 0x0a;
+ } else {
+ out[cursor] = 0x0d;
+ last = 0x0d;
+ }
+ } else {
+ out[cursor] = cur;
+ last = cur;
+ }
+
+ i++;
+ cursor++;
+ cur = in[i];
+ }
+
+ } else if (PHPDBG_EOL_LF == PHPDBG_G(eol) || PHPDBG_EOL_CR == PHPDBG_G(eol)) {
+ char want, kick;
+
+ if (PHPDBG_EOL_LF == PHPDBG_G(eol)) {
+ want = 0x0a;
+ kick = 0x0d;
+ } else {
+ want = 0x0d;
+ kick = 0x0a;
+ }
+
+ /* We gonna have a smaller or equally long string, estimation is almost neglecting */
+ out = (char *)emalloc(out_len);
+
+ last = cur = in[0];
+ i = cursor = 0;
+ for (; cursor < in_len;) {
+ if (kick == cur) {
+ out[cursor] = want;
+ } else if (want == cur) {
+ if (kick != last) {
+ out[cursor] = want;
+ }
+ } else {
+ out[cursor] = cur;
+ }
+
+ last = cur;
+ cursor++;
+ cur = in[cursor];
+ }
+ } else {
+ return;
+ }
+
+ efree(*str);
+ *str = erealloc(out, cursor);
+ *len = cursor;
+ in = NULL;
+}
diff --git a/sapi/phpdbg/phpdbg_eol.h b/sapi/phpdbg/phpdbg_eol.h
new file mode 100644
index 0000000000..e8dd27c971
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_eol.h
@@ -0,0 +1,46 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Anatol Belski <ab@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#ifndef PHPDBG_EOL_H
+#define PHPDBG_EOL_H
+
+#include "phpdbg.h"
+
+struct phpdbg_eol_rep {
+ char *name;
+ char *rep;
+ int id;
+};
+
+enum {
+ PHPDBG_EOL_CRLF, /* DOS */
+ /*PHPDBG_EOL_LFCR,*/ /* for Risc OS? */
+ PHPDBG_EOL_LF, /* UNIX */
+ PHPDBG_EOL_CR /* MAC */
+};
+
+int phpdbg_eol_global_update(char *name);
+
+char *phpdbg_eol_name(int id);
+
+char *phpdbg_eol_rep(int id);
+
+void phpdbg_eol_convert(char **str, int *len);
+
+#endif /* PHPDBG_EOL_H */
+
diff --git a/sapi/phpdbg/phpdbg_frame.c b/sapi/phpdbg/phpdbg_frame.c
index f4d2fcc5dc..4f0e5e88b0 100644
--- a/sapi/phpdbg/phpdbg_frame.c
+++ b/sapi/phpdbg/phpdbg_frame.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -26,7 +26,7 @@
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-void phpdbg_restore_frame(TSRMLS_D) /* {{{ */
+void phpdbg_restore_frame(void) /* {{{ */
{
if (PHPDBG_FRAME(num) == 0) {
return;
@@ -37,41 +37,40 @@ void phpdbg_restore_frame(TSRMLS_D) /* {{{ */
/* move things back */
EG(current_execute_data) = PHPDBG_FRAME(execute_data);
- EG(opline_ptr) = &PHPDBG_EX(opline);
- EG(active_op_array) = PHPDBG_EX(op_array);
- EG(return_value_ptr_ptr) = PHPDBG_EX(original_return_value);
- EG(active_symbol_table) = PHPDBG_EX(symbol_table);
- EG(This) = PHPDBG_EX(current_this);
- EG(scope) = PHPDBG_EX(current_scope);
- EG(called_scope) = PHPDBG_EX(current_called_scope);
+ EG(scope) = PHPDBG_EX(func)->op_array.scope;
} /* }}} */
-void phpdbg_switch_frame(int frame TSRMLS_DC) /* {{{ */
+void phpdbg_switch_frame(int frame) /* {{{ */
{
zend_execute_data *execute_data = PHPDBG_FRAME(num)?PHPDBG_FRAME(execute_data):EG(current_execute_data);
int i = 0;
if (PHPDBG_FRAME(num) == frame) {
- phpdbg_notice("Already in frame #%d", frame);
+ phpdbg_notice("frame", "id=\"%d\"", "Already in frame #%d", frame);
return;
}
- while (execute_data) {
- if (i++ == frame) {
- break;
- }
+ phpdbg_try_access {
+ while (execute_data) {
+ if (i++ == frame) {
+ break;
+ }
- do {
- execute_data = execute_data->prev_execute_data;
- } while (execute_data && execute_data->opline == NULL);
- }
+ do {
+ execute_data = execute_data->prev_execute_data;
+ } while (execute_data && execute_data->opline == NULL);
+ }
+ } phpdbg_catch_access {
+ phpdbg_error("signalsegv", "", "Couldn't switch frames, invalid data source");
+ return;
+ } phpdbg_end_try_access();
if (execute_data == NULL) {
- phpdbg_error("No frame #%d", frame);
+ phpdbg_error("frame", "type=\"maxnum\" id=\"%d\"", "No frame #%d", frame);
return;
}
- phpdbg_restore_frame(TSRMLS_C);
+ phpdbg_restore_frame();
if (frame > 0) {
PHPDBG_FRAME(num) = frame;
@@ -80,127 +79,166 @@ void phpdbg_switch_frame(int frame TSRMLS_DC) /* {{{ */
PHPDBG_FRAME(execute_data) = EG(current_execute_data);
EG(current_execute_data) = execute_data;
- EG(opline_ptr) = &PHPDBG_EX(opline);
- EG(active_op_array) = PHPDBG_EX(op_array);
- PHPDBG_FRAME(execute_data)->original_return_value = EG(return_value_ptr_ptr);
- EG(return_value_ptr_ptr) = PHPDBG_EX(original_return_value);
- EG(active_symbol_table) = PHPDBG_EX(symbol_table);
- EG(This) = PHPDBG_EX(current_this);
- EG(scope) = PHPDBG_EX(current_scope);
- EG(called_scope) = PHPDBG_EX(current_called_scope);
+ EG(scope) = PHPDBG_EX(func)->op_array.scope;
}
- phpdbg_notice("Switched to frame #%d", frame);
- phpdbg_list_file(
- zend_get_executed_filename(TSRMLS_C),
- 3,
- zend_get_executed_lineno(TSRMLS_C)-1,
- zend_get_executed_lineno(TSRMLS_C)
- TSRMLS_CC
- );
+ phpdbg_notice("frame", "id=\"%d\"", "Switched to frame #%d", frame);
+
+ {
+ const char *file_chr = zend_get_executed_filename();
+ zend_string *file = zend_string_init(file_chr, strlen(file_chr), 0);
+ phpdbg_list_file(file, 3, zend_get_executed_lineno() - 1, zend_get_executed_lineno());
+ efree(file);
+ }
} /* }}} */
-static void phpdbg_dump_prototype(zval **tmp TSRMLS_DC) /* {{{ */
+static void phpdbg_dump_prototype(zval *tmp) /* {{{ */
{
- zval **funcname, **class, **type, **args, **argstmp;
- char is_class;
+ zval *funcname, *class, class_zv, *type, *args, *argstmp;
- zend_hash_find(Z_ARRVAL_PP(tmp), "function", sizeof("function"),
- (void **)&funcname);
+ funcname = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("function"));
- if ((is_class = zend_hash_find(Z_ARRVAL_PP(tmp),
- "object", sizeof("object"), (void **)&class)) == FAILURE) {
- is_class = zend_hash_find(Z_ARRVAL_PP(tmp), "class", sizeof("class"),
- (void **)&class);
+ if ((class = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("object")))) {
+ ZVAL_NEW_STR(&class_zv, Z_OBJCE_P(class)->name);
+ class = &class_zv;
} else {
- zend_get_object_classname(*class, (const char **)&Z_STRVAL_PP(class),
- (zend_uint *)&Z_STRLEN_PP(class) TSRMLS_CC);
+ class = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("class"));
}
- if (is_class == SUCCESS) {
- zend_hash_find(Z_ARRVAL_PP(tmp), "type", sizeof("type"), (void **)&type);
+ if (class) {
+ type = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("type"));
}
- phpdbg_write("%s%s%s(",
- is_class == FAILURE?"":Z_STRVAL_PP(class),
- is_class == FAILURE?"":Z_STRVAL_PP(type),
- Z_STRVAL_PP(funcname)
- );
-
- if (zend_hash_find(Z_ARRVAL_PP(tmp), "args", sizeof("args"),
- (void **)&args) == SUCCESS) {
- HashPosition iterator;
- const zend_function *func = phpdbg_get_function(
- Z_STRVAL_PP(funcname), is_class == FAILURE ? NULL : Z_STRVAL_PP(class) TSRMLS_CC);
- const zend_arg_info *arginfo = func ? func->common.arg_info : NULL;
- int j = 0, m = func ? func->common.num_args : 0;
+ args = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("args"));
+
+ phpdbg_xml(" symbol=\"%s%s%s\"", class ? Z_STRVAL_P(class) : "", class ? Z_STRVAL_P(type) : "", Z_STRVAL_P(funcname));
+
+ if (args) {
+ phpdbg_xml(">");
+ } else {
+ phpdbg_xml(" />");
+ }
+
+ phpdbg_out("%s%s%s(", class ? Z_STRVAL_P(class) : "", class ? Z_STRVAL_P(type) : "", Z_STRVAL_P(funcname));
+
+ if (args) {
+ const zend_function *func = NULL;
+ const zend_arg_info *arginfo = NULL;
zend_bool is_variadic = 0;
+ int j = 0, m;
+
+ phpdbg_try_access {
+ /* assuming no autoloader call is necessary, class should have been loaded if it's in backtrace ... */
+ if ((func = phpdbg_get_function(Z_STRVAL_P(funcname), class ? Z_STRVAL_P(class) : NULL))) {
+ arginfo = func->common.arg_info;
+ }
+ } phpdbg_end_try_access();
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL_PP(args), &iterator);
- while (zend_hash_get_current_data_ex(Z_ARRVAL_PP(args),
- (void **) &argstmp, &iterator) == SUCCESS) {
+ m = func ? func->common.num_args : 0;
+
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(args), argstmp) {
if (j) {
- phpdbg_write(", ");
+ phpdbg_out(", ");
}
+ phpdbg_xml("<arg %r");
if (m && j < m) {
-#if PHP_VERSION_ID >= 50600
- is_variadic = arginfo[j].is_variadic;
-#endif
- phpdbg_write("%s=%s",
- arginfo[j].name, is_variadic ? "[": "");
+ char *arg_name = NULL;
+
+ if (arginfo) {
+ if (func->type == ZEND_INTERNAL_FUNCTION) {
+ arg_name = (char *)((zend_internal_arg_info *)&arginfo[j])->name;
+ } else {
+ arg_name = ZSTR_VAL(arginfo[j].name);
+ }
+ }
+
+ if (!is_variadic) {
+ is_variadic = arginfo ? arginfo[j].is_variadic : 0;
+ }
+
+ phpdbg_xml(" variadic=\"%s\" name=\"%s\">", is_variadic ? "variadic" : "", arg_name ? arg_name : "");
+ phpdbg_out("%s=%s", arg_name ? arg_name : "?", is_variadic ? "[": "");
+
+ } else {
+ phpdbg_xml(">");
}
++j;
- zend_print_flat_zval_r(*argstmp TSRMLS_CC);
- zend_hash_move_forward_ex(Z_ARRVAL_PP(args), &iterator);
- }
+ {
+ char *arg_print = phpdbg_short_zval_print(argstmp, 40);
+ php_printf("%s", arg_print);
+ efree(arg_print);
+ }
+
+ phpdbg_xml("</arg>");
+ } ZEND_HASH_FOREACH_END();
+
if (is_variadic) {
- phpdbg_write("]");
+ phpdbg_out("]");
}
+ phpdbg_xml("</frame>");
}
- phpdbg_write(")");
+ phpdbg_out(")");
}
-void phpdbg_dump_backtrace(size_t num TSRMLS_DC) /* {{{ */
+void phpdbg_dump_backtrace(size_t num) /* {{{ */
{
- zval zbacktrace;
- zval **tmp;
- zval **file, **line;
HashPosition position;
+ zval zbacktrace;
+ zval *tmp;
+ zval startline, startfile;
+ const char *startfilename;
+ zval *file = &startfile, *line = &startline;
int i = 0, limit = num;
- int user_defined;
+
+ PHPDBG_OUTPUT_BACKUP();
if (limit < 0) {
- phpdbg_error("Invalid backtrace size %d", limit);
+ phpdbg_error("backtrace", "type=\"minnum\"", "Invalid backtrace size %d", limit);
+
+ PHPDBG_OUTPUT_BACKUP_RESTORE();
+ return;
}
- zend_fetch_debug_backtrace(
- &zbacktrace, 0, 0, limit TSRMLS_CC);
+ phpdbg_try_access {
+ zend_fetch_debug_backtrace(&zbacktrace, 0, 0, limit);
+ } phpdbg_catch_access {
+ phpdbg_error("signalsegv", "", "Couldn't fetch backtrace, invalid data source");
+ return;
+ } phpdbg_end_try_access();
- zend_hash_internal_pointer_reset_ex(Z_ARRVAL(zbacktrace), &position);
- zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), (void**)&tmp, &position);
- while (1) {
- user_defined = zend_hash_find(Z_ARRVAL_PP(tmp), "file", sizeof("file"), (void **)&file);
- zend_hash_find(Z_ARRVAL_PP(tmp), "line", sizeof("line"), (void **)&line);
- zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position);
+ phpdbg_xml("<backtrace %r>");
- if (zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace),
- (void**)&tmp, &position) == FAILURE) {
- phpdbg_write("frame #%d: {main} at %s:%ld", i, Z_STRVAL_PP(file), Z_LVAL_PP(line));
- break;
- }
+ Z_LVAL(startline) = zend_get_executed_lineno();
+ startfilename = zend_get_executed_filename();
+ Z_STR(startfile) = zend_string_init(startfilename, strlen(startfilename), 0);
- if (user_defined == SUCCESS) {
- phpdbg_write("frame #%d: ", i++);
- phpdbg_dump_prototype(tmp TSRMLS_CC);
- phpdbg_writeln(" at %s:%ld", Z_STRVAL_PP(file), Z_LVAL_PP(line));
+ zend_hash_internal_pointer_reset_ex(Z_ARRVAL(zbacktrace), &position);
+ tmp = zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), &position);
+ while ((tmp = zend_hash_get_current_data_ex(Z_ARRVAL(zbacktrace), &position))) {
+ if (file) { /* userland */
+ phpdbg_out("frame #%d: ", i);
+ phpdbg_xml("<frame %r id=\"%d\" file=\"%s\" line=\"%d\"", i, Z_STRVAL_P(file), Z_LVAL_P(line));
+ phpdbg_dump_prototype(tmp);
+ phpdbg_out(" at %s:%ld\n", Z_STRVAL_P(file), Z_LVAL_P(line));
+ i++;
} else {
- phpdbg_write(" => ");
- phpdbg_dump_prototype(tmp TSRMLS_CC);
- phpdbg_writeln(" (internal function)");
+ phpdbg_out(" => ");
+ phpdbg_xml("<frame %r id=\"%d\" internal=\"internal\"", i);
+ phpdbg_dump_prototype(tmp);
+ phpdbg_out(" (internal function)\n");
}
+
+ file = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("file"));
+ line = zend_hash_str_find(Z_ARRVAL_P(tmp), ZEND_STRL("line"));
+ zend_hash_move_forward_ex(Z_ARRVAL(zbacktrace), &position);
}
- phpdbg_writeln(EMPTY);
+ phpdbg_writeln("frame", "id=\"%d\" symbol=\"{main}\" file=\"%s\" line=\"%d\"", "frame #%d: {main} at %s:%ld", i, Z_STRVAL_P(file), Z_LVAL_P(line));
+ phpdbg_xml("</backtrace>");
+
zval_dtor(&zbacktrace);
+ zend_string_release(Z_STR(startfile));
+
+ PHPDBG_OUTPUT_BACKUP_RESTORE();
} /* }}} */
diff --git a/sapi/phpdbg/phpdbg_frame.h b/sapi/phpdbg/phpdbg_frame.h
index d43d229a31..04d636ba4e 100644
--- a/sapi/phpdbg/phpdbg_frame.h
+++ b/sapi/phpdbg/phpdbg_frame.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -23,8 +23,8 @@
#include "TSRM.h"
-void phpdbg_restore_frame(TSRMLS_D);
-void phpdbg_switch_frame(int TSRMLS_DC);
-void phpdbg_dump_backtrace(size_t TSRMLS_DC);
+void phpdbg_restore_frame(void);
+void phpdbg_switch_frame(int);
+void phpdbg_dump_backtrace(size_t);
#endif /* PHPDBG_FRAME_H */
diff --git a/sapi/phpdbg/phpdbg_help.c b/sapi/phpdbg/phpdbg_help.c
index e71b3b5dc3..a99191d510 100644
--- a/sapi/phpdbg/phpdbg_help.c
+++ b/sapi/phpdbg/phpdbg_help.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -22,13 +22,14 @@
#include "phpdbg.h"
#include "phpdbg_help.h"
#include "phpdbg_prompt.h"
+#include "phpdbg_eol.h"
#include "zend.h"
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
/* {{{ Commands Table */
#define PHPDBG_COMMAND_HELP_D(name, tip, alias, action) \
- {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, action, NULL, 0}
+ {PHPDBG_STRL(#name), tip, sizeof(tip)-1, alias, action, &phpdbg_prompt_commands[16], 0}
const phpdbg_command_t phpdbg_help_commands[] = {
PHPDBG_COMMAND_HELP_D(aliases, "show alias list", 'a', phpdbg_do_help_aliases),
@@ -40,11 +41,11 @@ const phpdbg_command_t phpdbg_help_commands[] = {
}; /* }}} */
/* {{{ pretty_print. Formatting escapes and wrapping text in a string before printing it. */
-void pretty_print(char *text TSRMLS_DC)
+void pretty_print(char *text)
{
char *new, *p, *q;
- const char *prompt_escape = phpdbg_get_prompt(TSRMLS_C);
+ const char *prompt_escape = phpdbg_get_prompt();
unsigned int prompt_escape_len = strlen(prompt_escape);
unsigned int prompt_len = strlen(PHPDBG_G(prompt)[0]);
@@ -52,7 +53,7 @@ void pretty_print(char *text TSRMLS_DC)
const char *bold_off_escape = PHPDBG_G(flags) & PHPDBG_IS_COLOURED ? "\033[0m" : "";
unsigned int bold_escape_len = strlen(bold_on_escape);
- unsigned int term_width = phpdbg_get_terminal_width(TSRMLS_C);
+ unsigned int term_width = phpdbg_get_terminal_width();
unsigned int size = 0;
int in_bold = 0;
@@ -61,6 +62,11 @@ void pretty_print(char *text TSRMLS_DC)
unsigned int last_blank_count = 0; /* printable char offset of last blank char */
unsigned int line_count = 0; /* number printable chars on current line */
+ if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+ phpdbg_xml("<help %r msg=\"%s\" />", text);
+ return;
+ }
+
/* First pass calculates a safe size for the pretty print version */
for (p = text; *p; p++) {
if (UNEXPECTED(p[0] == '*') && p[1] == '*') {
@@ -128,24 +134,24 @@ void pretty_print(char *text TSRMLS_DC)
*q++ = '\0';
if ((q-new)>size) {
- phpdbg_error("Output overrun of %lu bytes", ((q-new) - size));
+ phpdbg_error("help", "overrun=\"%lu\"", "Output overrun of %lu bytes", ((q - new) - size));
}
- phpdbg_write("%s\n", new);
+ phpdbg_out("%s\n", new);
efree(new);
} /* }}} */
/* {{{ summary_print. Print a summary line giving, the command, its alias and tip */
-void summary_print(phpdbg_command_t const * const cmd TSRMLS_DC)
+void summary_print(phpdbg_command_t const * const cmd)
{
char *summary;
spprintf(&summary, 0, "Command: **%s** Alias: **%c** **%s**\n", cmd->name, cmd->alias, cmd->tip);
- pretty_print(summary TSRMLS_CC);
+ pretty_print(summary);
efree(summary);
}
/* {{{ get_help. Retries and formats text from the phpdbg help text table */
-static char *get_help(const char * const key TSRMLS_DC)
+static char *get_help(const char * const key)
{
phpdbg_help_text_t *p;
@@ -174,7 +180,7 @@ static int get_command(
const char *key, size_t len, /* pointer and length of key */
phpdbg_command_t const **command, /* address of first matching command */
phpdbg_command_t const * commands /* command table to be scanned */
- TSRMLS_DC)
+ )
{
const phpdbg_command_t *c;
unsigned int num_matches = 0;
@@ -201,7 +207,7 @@ static int get_command(
return num_matches;
-} /* }}} */
+} /* }}} */
PHPDBG_COMMAND(help) /* {{{ */
{
@@ -209,40 +215,40 @@ PHPDBG_COMMAND(help) /* {{{ */
int n;
if (!param || param->type == EMPTY_PARAM) {
- pretty_print(get_help("overview!" TSRMLS_CC) TSRMLS_CC);
+ pretty_print(get_help("overview!"));
return SUCCESS;
}
if (param && param->type == STR_PARAM) {
- n = get_command(param->str, param->len, &cmd, phpdbg_prompt_commands TSRMLS_CC);
+ n = get_command(param->str, param->len, &cmd, phpdbg_prompt_commands);
if (n==1) {
- summary_print(cmd TSRMLS_CC);
- pretty_print(get_help(cmd->name TSRMLS_CC) TSRMLS_CC);
+ summary_print(cmd);
+ pretty_print(get_help(cmd->name));
return SUCCESS;
} else if (n>1) {
if (param->len > 1) {
for (cmd=phpdbg_prompt_commands; cmd->name; cmd++) {
if (!strncmp(cmd->name, param->str, param->len)) {
- summary_print(cmd TSRMLS_CC);
+ summary_print(cmd);
}
}
- pretty_print(get_help("duplicate!" TSRMLS_CC) TSRMLS_CC);
+ pretty_print(get_help("duplicate!"));
return SUCCESS;
} else {
- phpdbg_error("Internal help error, non-unique alias \"%c\"", param->str[0]);
+ phpdbg_error("help", "type=\"ambiguousalias\" alias=\"%s\"", "Internal help error, non-unique alias \"%c\"", param->str[0]);
return FAILURE;
}
} else { /* no prompt command found so try help topic */
- n = get_command( param->str, param->len, &cmd, phpdbg_help_commands TSRMLS_CC);
+ n = get_command( param->str, param->len, &cmd, phpdbg_help_commands);
if (n>0) {
- if (cmd->alias == 'a') { /* help aliases executes a canned routine */
- return cmd->handler(param TSRMLS_CC);
+ if (cmd->alias == 'a') { /* help aliases executes a canned routine */
+ return cmd->handler(param);
} else {
- pretty_print(get_help(cmd->name TSRMLS_CC) TSRMLS_CC);
+ pretty_print(get_help(cmd->name));
return SUCCESS;
}
}
@@ -259,35 +265,42 @@ PHPDBG_HELP(aliases) /* {{{ */
int len;
/* Print out aliases for all commands except help as this one comes last */
- phpdbg_writeln("Below are the aliased, short versions of all supported commands");
+ phpdbg_writeln("help", "", "Below are the aliased, short versions of all supported commands");
+ phpdbg_xml("<helpcommands %r>");
for(c = phpdbg_prompt_commands; c->name; c++) {
if (c->alias && c->alias != 'h') {
- phpdbg_writeln(" %c %-20s %s", c->alias, c->name, c->tip);
+ phpdbg_writeln("command", "alias=\"%c\" name=\"%s\" tip=\"%s\"", " %c %-20s %s", c->alias, c->name, c->tip);
if (c->subs) {
len = 20 - 1 - c->name_len;
for(c_sub = c->subs; c_sub->alias; c_sub++) {
if (c_sub->alias) {
- phpdbg_writeln(" %c %c %s %-*s %s",
- c->alias, c_sub->alias, (char *)c->name, len, c_sub->name, c_sub->tip);
+ phpdbg_writeln("subcommand", "parent_alias=\"%c\" alias=\"%c\" parent=\"%s\" name=\"%-*s\" tip=\"%s\"", " %c %c %s %-*s %s",
+ c->alias, c_sub->alias, c->name, len, c_sub->name, c_sub->tip);
}
}
}
}
}
+ phpdbg_xml("</helpcommands>");
+
/* Print out aliases for help as this one comes last, with the added text on how aliases are used */
- get_command("h", 1, &c, phpdbg_prompt_commands TSRMLS_CC);
- phpdbg_writeln(" %c %-20s %s\n", c->alias, c->name, c->tip);
+ get_command("h", 1, &c, phpdbg_prompt_commands);
+ phpdbg_writeln("aliasinfo", "alias=\"%c\" name=\"%s\" tip=\"%s\"", " %c %-20s %s\n", c->alias, c->name, c->tip);
+
+ phpdbg_xml("<helpaliases>");
len = 20 - 1 - c->name_len;
for(c_sub = c->subs; c_sub->alias; c_sub++) {
if (c_sub->alias) {
- phpdbg_writeln(" %c %c %s %-*s %s",
+ phpdbg_writeln("alias", "parent_alias=\"%c\" alias=\"%c\" parent=\"%s\" name=\"%-*s\" tip=\"%s\"", " %c %c %s %-*s %s",
c->alias, c_sub->alias, c->name, len, c_sub->name, c_sub->tip);
}
}
- pretty_print(get_help("aliases!" TSRMLS_CC) TSRMLS_CC);
+ phpdbg_xml("</helpaliases>");
+
+ pretty_print(get_help("aliases!"));
return SUCCESS;
} /* }}} */
@@ -319,7 +332,7 @@ phpdbg_help_text_t phpdbg_help_text[] = {
" **list** list PHP source" CR
" **info** displays information on the debug session" CR
" **print** show opcodes" CR
-" **frame** select a stack frame and print a stack frame summary" CR
+" **frame** select a stack frame and print a stack frame summary" CR
" **back** shows the current backtrace" CR
" **help** provide help on a topic" CR CR
@@ -329,6 +342,7 @@ phpdbg_help_text_t phpdbg_help_text[] = {
" **step** continue execution until other line is reached" CR
" **continue** continue execution" CR
" **until** continue execution up to the given location" CR
+" **next** continue execution up to the given location and halt on the first line after it" CR
" **finish** continue up to end of the current execution frame" CR
" **leave** continue up to end of the current execution frame and halt after the calling instruction" CR
" **break** set a breakpoint at the specified target" CR
@@ -362,33 +376,43 @@ phpdbg_help_text_t phpdbg_help_text[] = {
" **-c** **-c**/my/php.ini Set php.ini file to load" CR
" **-d** **-d**memory_limit=4G Set a php.ini directive" CR
" **-n** Disable default php.ini" CR
-" **-q** Supress welcome banner" CR
+" **-q** Suppress welcome banner" CR
" **-v** Enable oplog output" CR
-" **-s** Enable stepping" CR
" **-b** Disable colour" CR
" **-i** **-i**my.init Set .phpdbginit file" CR
" **-I** Ignore default .phpdbginit" CR
" **-O** **-O**my.oplog Sets oplog output file" CR
" **-r** Run execution context" CR
-" **-rr** Run execution context and quit after execution" CR
+" **-rr** Run execution context and quit after execution (not respecting breakpoints)" CR
+" **-e** Generate extended information for debugger/profiler" CR
" **-E** Enable step through eval, careful!" CR
" **-S** **-S**cli Override SAPI name, careful!" CR
" **-l** **-l**4000 Setup remote console ports" CR
" **-a** **-a**192.168.0.3 Setup remote console bind address" CR
+" **-x** Enable xml output (instead of normal text output)" CR
+" **-p** **-p**, **-p=func**, **-p* ** Output opcodes and quit" CR
+" **-h** Print the help overview" CR
" **-V** Print version number" CR
" **--** **--** arg1 arg2 Use to delimit phpdbg arguments and php $argv; append any $argv "
"argument after it" CR CR
"**Remote Console Mode**" CR CR
-"This mode is enabled by specifying the **-a** option. Phpdbg will bind only to the loopback "
+"This mode is enabled by specifying the **-a** option. Phpdbg will bind only to the loopback "
"interface by default, and this can only be overridden by explicitly setting the remote console "
"bind address using the **-a** option. If **-a** is specied without an argument, then phpdbg "
"will bind to all available interfaces. You should be aware of the security implications of "
"doing this, so measures should be taken to secure this service if bound to a publicly accessible "
"interface/port." CR CR
-"Specify both stdin and stdout with -lstdin/stdout; by default stdout is stdin * 2."
+"**Opcode output**" CR CR
+
+"Outputting opcodes requires that a file path is passed as last argument. Modes of execution:" CR
+"**-p** Outputs the main execution context" CR
+"**-p* **Outputs all opcodes in the whole file (including classes and functions)" CR
+"**-p=function_name** Outputs opcodes of a given function in the file" CR
+"**-p=class_name::** Outputs opcodes of all the methods of a given class" CR
+"**-p=class_name::method** Outputs opcodes of a given method"
},
{"phpdbginit", CR
@@ -400,10 +424,10 @@ phpdbg_help_text_t phpdbg_help_text[] = {
"Debugger scripts can also be executed using the **source** command." CR CR
"A script file can contain a sequence of valid debugger commands, comments and embedded PHP "
-"code. " CR CR
+"code. " CR CR
"Comment lines are prefixed by the **#** character. Note that comments are only allowed in script "
-"files and not in interactive sessions." CR CR
+"files and not in interactive sessions." CR CR
"PHP code is delimited by the start and end escape tags **<:** and **:>**. PHP code can be used "
"to define application context for a debugging session and also to extend the debugger by defining "
@@ -545,7 +569,7 @@ phpdbg_help_text_t phpdbg_help_text[] = {
" $P break ZEND_ADD" CR
" $P b ZEND_ADD" CR
-" Break on any occurence of the opcode ZEND_ADD" CR CR
+" Break on any occurrence of the opcode ZEND_ADD" CR CR
" $P break del 2" CR
" $P b ~ 2" CR
@@ -596,7 +620,7 @@ phpdbg_help_text_t phpdbg_help_text[] = {
},
{"exec",
-"The **exec** command sets the execution context, that is the script to be executed. The "
+"The **exec** command sets the execution context, that is the script to be executed. The "
"execution context must be defined either by executing the **exec** command or by using the "
"**-e** command line option." CR CR
@@ -625,8 +649,8 @@ phpdbg_help_text_t phpdbg_help_text[] = {
{"frame",
"The **frame** takes an optional integer argument. If omitted, then the current frame is displayed "
-"If specified then the current scope is set to the corresponding frame listed in a **back** trace. " "This can be used to allowing access to the variables in a higher stack frame than that currently "
-"being executed." CR CR
+"If specified then the current scope is set to the corresponding frame listed in a **back** trace. "
+"This can be used to allowing access to the variables in a higher stack frame than that currently being executed." CR CR
"**Examples**" CR CR
" $P frame 2" CR
@@ -639,17 +663,20 @@ phpdbg_help_text_t phpdbg_help_text[] = {
{"info",
"**info** commands provide quick access to various types of information about the PHP environment" CR
+"By default general information about environment and PHP build is shown." CR
"Specific info commands are show below:" CR CR
" **Target** **Alias** **Purpose**" CR
-" **break** **b** show current breakpoints" CR
-" **files** **F** show included files" CR
-" **classes** **c** show loaded classes" CR
-" **funcs** **f** show loaded classes" CR
-" **error** **e** show last error" CR
-" **vars** **v** show active variables" CR
-" **literal** **l** show active literal constants" CR
-" **memory** **m** show memory manager stats"
+" **break** **b** show current breakpoints" CR
+" **files** **F** show included files" CR
+" **classes** **c** show loaded classes" CR
+" **funcs** **f** show loaded functions" CR
+" **error** **e** show last error" CR
+" **constants** **d** show user-defined constants" CR
+" **vars** **v** show active variables" CR
+" **globals** **g** show superglobal variables" CR
+" **literal** **l** show active literal constants" CR
+" **memory** **m** show memory manager stats"
},
// ******** same issue about breakpoints in called frames
@@ -724,7 +751,7 @@ phpdbg_help_text_t phpdbg_help_text[] = {
},
{"print",
-"By default, print will show information about the current execution context." CR
+"By default, print will show the opcodes of the current execution context." CR
"Other printing commands give access to instruction information." CR
"Specific printers loaded are show below:" CR CR
@@ -736,6 +763,8 @@ phpdbg_help_text_t phpdbg_help_text[] = {
" **func** **f** print out the instructions in the specified function" CR
" **stack** **s** print out the instructions in the current stack" CR CR
+"In case passed argument does not match a specific printing command, it will treat it as function or method name and print its opcodes" CR CR
+
"**Examples**" CR CR
" $P print class \\\\my\\\\class" CR
" $P p c \\\\my\\\\class" CR
@@ -873,10 +902,22 @@ phpdbg_help_text_t phpdbg_help_text[] = {
" $P s" CR
" Will continue and break again in the next encountered line" CR CR
},
+{"next",
+"The **next** command causes control to be passed back to the vm, continuing execution. Any "
+"breakpoints that are encountered before the next source line will be skipped. Execution will"
+"be stopped when that line is left." CR CR
+"Note when **step**ping is enabled, any opcode steps within the current line are also skipped. "CR CR
+
+"Note that if the next line is **not** executed then **all** subsequent breakpoints will be "
+"skipped. " CR CR
+
+"Note **next** will trigger a \"not executing\" error if not executing."
+
+},
{"until",
-"The **until** command causes control to be passed back to the vm, continuing execution. Any "
-"breakpoints that are encountered before the next source line will be skipped. Execution "
+"The **until** command causes control to be passed back to the vm, continuing execution. Any "
+"breakpoints that are encountered before the next source line will be skipped. Execution "
"will then continue until the next breakpoint or completion of the script" CR CR
"Note when **step**ping is enabled, any opcode steps within the current line are also skipped. "CR CR
diff --git a/sapi/phpdbg/phpdbg_help.h b/sapi/phpdbg/phpdbg_help.h
index d59010e1bd..a2db10880e 100644
--- a/sapi/phpdbg/phpdbg_help.h
+++ b/sapi/phpdbg/phpdbg_help.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -35,9 +35,9 @@ PHPDBG_HELP(aliases);
extern const phpdbg_command_t phpdbg_help_commands[];
#define phpdbg_help_header() \
- phpdbg_notice("Welcome to phpdbg, the interactive PHP debugger, v%s", PHPDBG_VERSION);
+ phpdbg_notice("version", "version=\"%s\"", "Welcome to phpdbg, the interactive PHP debugger, v%s", PHPDBG_VERSION);
#define phpdbg_help_footer() \
- phpdbg_notice("Please report bugs to <%s>", PHPDBG_ISSUES);
+ phpdbg_notice("issues", "url=\"%s\"", "Please report bugs to <%s>", PHPDBG_ISSUES);
typedef struct _phpdbg_help_text_t {
char *key;
diff --git a/sapi/phpdbg/phpdbg_info.c b/sapi/phpdbg/phpdbg_info.c
index 6c5b9b02d5..f947dc4864 100644
--- a/sapi/phpdbg/phpdbg_info.c
+++ b/sapi/phpdbg/phpdbg_info.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -27,50 +27,56 @@
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-#define PHPDBG_INFO_COMMAND_D(f, h, a, m, l, s) \
- PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[14])
+#define PHPDBG_INFO_COMMAND_D(f, h, a, m, l, s, flags) \
+ PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[13], flags)
const phpdbg_command_t phpdbg_info_commands[] = {
- PHPDBG_INFO_COMMAND_D(break, "show breakpoints", 'b', info_break, NULL, 0),
- PHPDBG_INFO_COMMAND_D(files, "show included files", 'F', info_files, NULL, 0),
- PHPDBG_INFO_COMMAND_D(classes, "show loaded classes", 'c', info_classes, NULL, 0),
- PHPDBG_INFO_COMMAND_D(funcs, "show loaded classes", 'f', info_funcs, NULL, 0),
- PHPDBG_INFO_COMMAND_D(error, "show last error", 'e', info_error, NULL, 0),
- PHPDBG_INFO_COMMAND_D(vars, "show active variables", 'v', info_vars, NULL, 0),
- PHPDBG_INFO_COMMAND_D(literal, "show active literal constants", 'l', info_literal, NULL, 0),
- PHPDBG_INFO_COMMAND_D(memory, "show memory manager stats", 'm', info_memory, NULL, 0),
+ PHPDBG_INFO_COMMAND_D(break, "show breakpoints", 'b', info_break, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(files, "show included files", 'F', info_files, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(classes, "show loaded classes", 'c', info_classes, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(funcs, "show loaded classes", 'f', info_funcs, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(error, "show last error", 'e', info_error, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(constants, "show user defined constants", 'd', info_constants, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(vars, "show active variables", 'v', info_vars, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(globals, "show superglobals", 'g', info_globals, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(literal, "show active literal constants", 'l', info_literal, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_INFO_COMMAND_D(memory, "show memory manager stats", 'm', info_memory, NULL, 0, PHPDBG_ASYNC_SAFE),
PHPDBG_END_COMMAND
};
PHPDBG_INFO(break) /* {{{ */
{
- phpdbg_print_breakpoints(PHPDBG_BREAK_FILE TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_SYM TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_OPLINE TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_FILE_OPLINE TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_FUNCTION_OPLINE TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD_OPLINE TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_COND TSRMLS_CC);
- phpdbg_print_breakpoints(PHPDBG_BREAK_OPCODE TSRMLS_CC);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_FILE);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_SYM);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_OPLINE);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_FILE_OPLINE);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_FUNCTION_OPLINE);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_METHOD_OPLINE);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_COND);
+ phpdbg_print_breakpoints(PHPDBG_BREAK_OPCODE);
return SUCCESS;
} /* }}} */
PHPDBG_INFO(files) /* {{{ */
{
- HashPosition pos;
- char *fname;
+ zend_string *fname;
- phpdbg_notice("Included files: %d",
- zend_hash_num_elements(&EG(included_files)));
+ phpdbg_try_access {
+ phpdbg_notice("includedfilecount", "num=\"%d\"", "Included files: %d", zend_hash_num_elements(&EG(included_files)));
+ } phpdbg_catch_access {
+ phpdbg_error("signalsegv", "", "Could not fetch included file count, invalid data source");
+ return SUCCESS;
+ } phpdbg_end_try_access();
- zend_hash_internal_pointer_reset_ex(&EG(included_files), &pos);
- while (zend_hash_get_current_key_ex(&EG(included_files), &fname,
- NULL, NULL, 0, &pos) == HASH_KEY_IS_STRING) {
- phpdbg_writeln("File: %s", fname);
- zend_hash_move_forward_ex(&EG(included_files), &pos);
- }
+ phpdbg_try_access {
+ ZEND_HASH_FOREACH_STR_KEY(&EG(included_files), fname) {
+ phpdbg_writeln("includedfile", "name=\"%s\"", "File: %s", ZSTR_VAL(fname));
+ } ZEND_HASH_FOREACH_END();
+ } phpdbg_catch_access {
+ phpdbg_error("signalsegv", "", "Could not fetch file name, invalid data source, aborting included file listing");
+ } phpdbg_end_try_access();
return SUCCESS;
} /* }}} */
@@ -78,125 +84,199 @@ PHPDBG_INFO(files) /* {{{ */
PHPDBG_INFO(error) /* {{{ */
{
if (PG(last_error_message)) {
- phpdbg_writeln("Last error: %s at %s line %d",
- PG(last_error_message), PG(last_error_file), PG(last_error_lineno));
+ phpdbg_try_access {
+ phpdbg_writeln("lasterror", "error=\"%s\" file=\"%s\" line=\"%d\"", "Last error: %s at %s line %d", PG(last_error_message), PG(last_error_file), PG(last_error_lineno));
+ } phpdbg_catch_access {
+ phpdbg_notice("lasterror", "error=\"\"", "No error found!");
+ } phpdbg_end_try_access();
} else {
- phpdbg_notice("No error found!");
+ phpdbg_notice("lasterror", "error=\"\"", "No error found!");
}
return SUCCESS;
} /* }}} */
-PHPDBG_INFO(vars) /* {{{ */
+PHPDBG_INFO(constants) /* {{{ */
{
- HashTable vars;
- HashPosition pos;
- char *var;
- zval **data;
+ HashTable consts;
+ zend_constant *data;
- if (!EG(active_op_array)) {
- phpdbg_error("No active op array!");
- return SUCCESS;
+ zend_hash_init(&consts, 8, NULL, NULL, 0);
+
+ if (EG(zend_constants)) {
+ phpdbg_try_access {
+ ZEND_HASH_FOREACH_PTR(EG(zend_constants), data) {
+ if (data->module_number == PHP_USER_CONSTANT) {
+ zend_hash_update_ptr(&consts, data->name, data);
+ }
+ } ZEND_HASH_FOREACH_END();
+ } phpdbg_catch_access {
+ phpdbg_error("signalsegv", "", "Cannot fetch all the constants, invalid data source");
+ } phpdbg_end_try_access();
}
- if (!EG(active_symbol_table)) {
- zend_rebuild_symbol_table(TSRMLS_C);
+ phpdbg_notice("constantinfo", "num=\"%d\"", "User-defined constants (%d)", zend_hash_num_elements(&consts));
+
+ if (zend_hash_num_elements(&consts)) {
+ phpdbg_out("Address Refs Type Constant\n");
+ ZEND_HASH_FOREACH_PTR(&consts, data) {
+
+#define VARIABLEINFO(attrs, msg, ...) phpdbg_writeln("constant", "address=\"%p\" refcount=\"%d\" type=\"%s\" name=\"%.*s\" " attrs, "%-18p %-7d %-9s %.*s" msg, &data->value, Z_REFCOUNTED(data->value) ? Z_REFCOUNT(data->value) : 1, zend_zval_type_name(&data->value), ZSTR_LEN(data->name), ZSTR_VAL(data->name), ##__VA_ARGS__)
+
+ switch (Z_TYPE(data->value)) {
+ case IS_STRING:
+ phpdbg_try_access {
+ VARIABLEINFO("length=\"%d\" value=\"%.*s\"", "\nstring (%d) \"%.*s%s\"", Z_STRLEN(data->value), Z_STRLEN(data->value) < 255 ? Z_STRLEN(data->value) : 255, Z_STRVAL(data->value), Z_STRLEN(data->value) > 255 ? "..." : "");
+ } phpdbg_catch_access {
+ VARIABLEINFO("", "");
+ } phpdbg_end_try_access();
+ break;
+ case IS_TRUE:
+ VARIABLEINFO("value=\"true\"", "\nbool (true)");
+ break;
+ case IS_FALSE:
+ VARIABLEINFO("value=\"false\"", "\nbool (false)");
+ break;
+ case IS_LONG:
+ VARIABLEINFO("value=\"%ld\"", "\nint (%ld)", Z_LVAL(data->value));
+ break;
+ case IS_DOUBLE:
+ VARIABLEINFO("value=\"%lf\"", "\ndouble (%lf)", Z_DVAL(data->value));
+ break;
+ default:
+ VARIABLEINFO("", "");
+
+#undef VARIABLEINFO
+ }
+ } ZEND_HASH_FOREACH_END();
+ }
- if (!EG(active_symbol_table)) {
- phpdbg_error("No active symbol table!");
- return SUCCESS;
+ return SUCCESS;
+} /* }}} */
+
+static int phpdbg_arm_auto_global(zval *ptrzv) {
+ zend_auto_global *auto_global = Z_PTR_P(ptrzv);
+
+ if (auto_global->armed) {
+ if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
+ phpdbg_notice("variableinfo", "unreachable=\"%.*s\"", "Cannot show information about superglobal variable %.*s", ZSTR_LEN(auto_global->name), ZSTR_VAL(auto_global->name));
+ } else {
+ auto_global->armed = auto_global->auto_global_callback(auto_global->name);
}
}
- zend_hash_init(&vars, 8, NULL, NULL, 0);
+ return 0;
+}
- zend_hash_internal_pointer_reset_ex(EG(active_symbol_table), &pos);
- while (zend_hash_get_current_key_ex(EG(active_symbol_table), &var,
- NULL, NULL, 0, &pos) == HASH_KEY_IS_STRING) {
- zend_hash_get_current_data_ex(EG(active_symbol_table), (void **)&data, &pos);
- if (*var != '_') {
- zend_hash_update(
- &vars, var, strlen(var)+1, (void**)data, sizeof(zval*), NULL);
- }
- zend_hash_move_forward_ex(EG(active_symbol_table), &pos);
+static int phpdbg_print_symbols(zend_bool show_globals) {
+ HashTable vars;
+ zend_array *symtable;
+ zend_string *var;
+ zval *data;
+
+ if (!EG(current_execute_data) || !EG(current_execute_data)->func) {
+ phpdbg_error("inactive", "type=\"op_array\"", "No active op array!");
+ return SUCCESS;
+ }
+
+ if (show_globals) {
+ /* that array should only be manipulated during init, so safe for async access during execution */
+ zend_hash_apply(CG(auto_globals), (apply_func_t) phpdbg_arm_auto_global);
+ symtable = &EG(symbol_table);
+ } else if (!(symtable = zend_rebuild_symbol_table())) {
+ phpdbg_error("inactive", "type=\"symbol_table\"", "No active symbol table!");
+ return SUCCESS;
}
- {
- zend_op_array *ops = EG(active_op_array);
-
+ zend_hash_init(&vars, 8, NULL, NULL, 0);
+
+ phpdbg_try_access {
+ ZEND_HASH_FOREACH_STR_KEY_VAL(symtable, var, data) {
+ if (zend_is_auto_global(var) ^ !show_globals) {
+ zend_hash_update(&vars, var, data);
+ }
+ } ZEND_HASH_FOREACH_END();
+ } phpdbg_catch_access {
+ phpdbg_error("signalsegv", "", "Cannot fetch all data from the symbol table, invalid data source");
+ } phpdbg_end_try_access();
+
+ if (show_globals) {
+ phpdbg_notice("variableinfo", "num=\"%d\"", "Superglobal variables (%d)", zend_hash_num_elements(&vars));
+ } else {
+ zend_op_array *ops = &EG(current_execute_data)->func->op_array;
+
if (ops->function_name) {
if (ops->scope) {
- phpdbg_notice(
- "Variables in %s::%s() (%d)", ops->scope->name, ops->function_name, zend_hash_num_elements(&vars));
+ phpdbg_notice("variableinfo", "method=\"%s::%s\" num=\"%d\"", "Variables in %s::%s() (%d)", ops->scope->name->val, ops->function_name->val, zend_hash_num_elements(&vars));
} else {
- phpdbg_notice(
- "Variables in %s() (%d)", ops->function_name, zend_hash_num_elements(&vars));
+ phpdbg_notice("variableinfo", "function=\"%s\" num=\"%d\"", "Variables in %s() (%d)", ZSTR_VAL(ops->function_name), zend_hash_num_elements(&vars));
}
} else {
if (ops->filename) {
- phpdbg_notice(
- "Variables in %s (%d)", ops->filename, zend_hash_num_elements(&vars));
+ phpdbg_notice("variableinfo", "file=\"%s\" num=\"%d\"", "Variables in %s (%d)", ZSTR_VAL(ops->filename), zend_hash_num_elements(&vars));
} else {
- phpdbg_notice(
- "Variables @ %p (%d)", ops, zend_hash_num_elements(&vars));
+ phpdbg_notice("variableinfo", "opline=\"%p\" num=\"%d\"", "Variables @ %p (%d)", ops, zend_hash_num_elements(&vars));
}
}
}
if (zend_hash_num_elements(&vars)) {
- phpdbg_writeln("Address\t\tRefs\tType\t\tVariable");
- for (zend_hash_internal_pointer_reset_ex(&vars, &pos);
- zend_hash_get_current_data_ex(&vars, (void**) &data, &pos) == SUCCESS;
- zend_hash_move_forward_ex(&vars, &pos)) {
- char *var;
-
- zend_hash_get_current_key_ex(&vars, &var, NULL, NULL, 0, &pos);
-
- if (*data) {
- phpdbg_write(
- "%p\t%d\t",
- *data,
- Z_REFCOUNT_PP(data));
-
- switch (Z_TYPE_PP(data)) {
- case IS_STRING: phpdbg_write("(string)\t"); break;
- case IS_LONG: phpdbg_write("(integer)\t"); break;
- case IS_DOUBLE: phpdbg_write("(float)\t"); break;
- case IS_RESOURCE: phpdbg_write("(resource)\t"); break;
- case IS_ARRAY: phpdbg_write("(array)\t"); break;
- case IS_OBJECT: phpdbg_write("(object)\t"); break;
- case IS_NULL: phpdbg_write("(null)\t"); break;
+ phpdbg_out("Address Refs Type Variable\n");
+ ZEND_HASH_FOREACH_STR_KEY_VAL(&vars, var, data) {
+ phpdbg_try_access {
+ const char *isref = "";
+#define VARIABLEINFO(attrs, msg, ...) phpdbg_writeln("variable", "address=\"%p\" refcount=\"%d\" type=\"%s\" refstatus=\"%s\" name=\"%.*s\" " attrs, "%-18p %-7d %-9s %s$%.*s" msg, data, Z_REFCOUNTED_P(data) ? Z_REFCOUNT_P(data) : 1, zend_zval_type_name(data), isref, ZSTR_LEN(var), ZSTR_VAL(var), ##__VA_ARGS__)
+retry_switch:
+ switch (Z_TYPE_P(data)) {
+ case IS_RESOURCE:
+ phpdbg_try_access {
+ const char *type = zend_rsrc_list_get_rsrc_type(Z_RES_P(data));
+ VARIABLEINFO("type=\"%s\"", "\n|-------(typeof)------> (%s)\n", type ? type : "unknown");
+ } phpdbg_catch_access {
+ VARIABLEINFO("type=\"unknown\"", "\n|-------(typeof)------> (unknown)\n");
+ } phpdbg_end_try_access();
+ break;
+ case IS_OBJECT:
+ phpdbg_try_access {
+ VARIABLEINFO("instanceof=\"%s\"", "\n|-----(instanceof)----> (%s)\n", Z_OBJCE_P(data)->name);
+ } phpdbg_catch_access {
+ VARIABLEINFO("instanceof=\"%s\"", "\n|-----(instanceof)----> (unknown)\n");
+ } phpdbg_end_try_access();
+ break;
+ case IS_STRING:
+ phpdbg_try_access {
+ VARIABLEINFO("length=\"%d\" value=\"%.*s\"", "\nstring (%d) \"%.*s%s\"", Z_STRLEN_P(data), Z_STRLEN_P(data) < 255 ? Z_STRLEN_P(data) : 255, Z_STRVAL_P(data), Z_STRLEN_P(data) > 255 ? "..." : "");
+ } phpdbg_catch_access {
+ VARIABLEINFO("", "");
+ } phpdbg_end_try_access();
+ break;
+ case IS_TRUE:
+ VARIABLEINFO("value=\"true\"", "\nbool (true)");
+ break;
+ case IS_FALSE:
+ VARIABLEINFO("value=\"false\"", "\nbool (false)");
+ break;
+ case IS_LONG:
+ VARIABLEINFO("value=\"%ld\"", "\nint (%ld)", Z_LVAL_P(data));
+ break;
+ case IS_DOUBLE:
+ VARIABLEINFO("value=\"%lf\"", "\ndouble (%lf)", Z_DVAL_P(data));
+ break;
+ case IS_REFERENCE:
+ isref = "&";
+ data = Z_REFVAL_P(data);
+ goto retry_switch;
+ case IS_INDIRECT:
+ data = Z_INDIRECT_P(data);
+ goto retry_switch;
+ default:
+ VARIABLEINFO("", "");
}
- if (Z_TYPE_PP(data) == IS_RESOURCE) {
- int type;
-
- phpdbg_writeln(
- "%s$%s", Z_ISREF_PP(data) ? "&": "", var);
- if (zend_list_find(Z_RESVAL_PP(data), &type)) {
- phpdbg_write(
- "|-------(typeof)------> (%s)",
- zend_rsrc_list_get_rsrc_type(type TSRMLS_CC));
- } else {
- phpdbg_write(
- "|-------(typeof)------> (unknown)");
- }
- phpdbg_writeln(EMPTY);
- } else if (Z_TYPE_PP(data) == IS_OBJECT) {
- phpdbg_writeln(
- "%s$%s", Z_ISREF_PP(data) ? "&": "", var);
- phpdbg_write(
- "|-----(instanceof)----> (%s)", Z_OBJCE_PP(data)->name);
- phpdbg_writeln(EMPTY);
- } else {
- phpdbg_write(
- "%s$%s", Z_ISREF_PP(data) ? "&": "", var);
- }
- } else {
- phpdbg_write(
- "n/a\tn/a\tn/a\t$%s", var);
- }
- phpdbg_writeln(EMPTY);
- }
+#undef VARIABLEINFO
+ } phpdbg_catch_access {
+ phpdbg_writeln("variable", "address=\"%p\" name=\"%s\"", "%p\tn/a\tn/a\t$%s", data, ZSTR_VAL(var));
+ } phpdbg_end_try_access();
+ } ZEND_HASH_FOREACH_END();
}
zend_hash_destroy(&vars);
@@ -204,42 +284,48 @@ PHPDBG_INFO(vars) /* {{{ */
return SUCCESS;
} /* }}} */
+PHPDBG_INFO(vars) /* {{{ */
+{
+ return phpdbg_print_symbols(0);
+}
+
+PHPDBG_INFO(globals) /* {{{ */
+{
+ return phpdbg_print_symbols(1);
+}
+
PHPDBG_INFO(literal) /* {{{ */
{
- if ((EG(in_execution) && EG(active_op_array)) || PHPDBG_G(ops)) {
- zend_op_array *ops = EG(active_op_array) ? EG(active_op_array) : PHPDBG_G(ops);
- int literal = 0, count = ops->last_literal-1;
+ /* literals are assumed to not be manipulated during executing of their op_array and as such async safe */
+ zend_bool in_executor = PHPDBG_G(in_execution) && EG(current_execute_data) && EG(current_execute_data)->func;
+ if (in_executor || PHPDBG_G(ops)) {
+ zend_op_array *ops = in_executor ? &EG(current_execute_data)->func->op_array : PHPDBG_G(ops);
+ int literal = 0, count = ops->last_literal - 1;
if (ops->function_name) {
if (ops->scope) {
- phpdbg_notice(
- "Literal Constants in %s::%s() (%d)", ops->scope->name, ops->function_name, count);
+ phpdbg_notice("literalinfo", "method=\"%s::%s\" num=\"%d\"", "Literal Constants in %s::%s() (%d)", ops->scope->name->val, ops->function_name->val, count);
} else {
- phpdbg_notice(
- "Literal Constants in %s() (%d)", ops->function_name, count);
+ phpdbg_notice("literalinfo", "function=\"%s\" num=\"%d\"", "Literal Constants in %s() (%d)", ops->function_name->val, count);
}
} else {
if (ops->filename) {
- phpdbg_notice(
- "Literal Constants in %s (%d)", ops->filename, count);
+ phpdbg_notice("literalinfo", "file=\"%s\" num=\"%d\"", "Literal Constants in %s (%d)", ZSTR_VAL(ops->filename), count);
} else {
- phpdbg_notice(
- "Literal Constants @ %p (%d)", ops, count);
+ phpdbg_notice("literalinfo", "opline=\"%p\" num=\"%d\"", "Literal Constants @ %p (%d)", ops, count);
}
}
while (literal < ops->last_literal) {
- if (Z_TYPE(ops->literals[literal].constant) != IS_NULL) {
- phpdbg_write("|-------- C%u -------> [", literal);
- zend_print_zval(
- &ops->literals[literal].constant, 0);
- phpdbg_write("]");
- phpdbg_writeln(EMPTY);
+ if (Z_TYPE(ops->literals[literal]) != IS_NULL) {
+ phpdbg_write("literal", "id=\"%u\"", "|-------- C%u -------> [", literal);
+ zend_print_zval(&ops->literals[literal], 0);
+ phpdbg_out("]\n");
}
literal++;
}
} else {
- phpdbg_error("Not executing!");
+ phpdbg_error("inactive", "type=\"execution\"", "Not executing!");
}
return SUCCESS;
@@ -247,85 +333,85 @@ PHPDBG_INFO(literal) /* {{{ */
PHPDBG_INFO(memory) /* {{{ */
{
- if (is_zend_mm(TSRMLS_C)) {
- phpdbg_notice("Memory Manager Information");
- phpdbg_notice("Current");
- phpdbg_writeln("|-------> Used:\t%.3f kB",
- (float) (zend_memory_usage(0 TSRMLS_CC)/1024));
- phpdbg_writeln("|-------> Real:\t%.3f kB",
- (float) (zend_memory_usage(1 TSRMLS_CC)/1024));
- phpdbg_notice("Peak");
- phpdbg_writeln("|-------> Used:\t%.3f kB",
- (float) (zend_memory_peak_usage(0 TSRMLS_CC)/1024));
- phpdbg_writeln("|-------> Real:\t%.3f kB",
- (float) (zend_memory_peak_usage(1 TSRMLS_CC)/1024));
+ size_t used, real, peak_used, peak_real;
+ zend_mm_heap *heap;
+ zend_bool is_mm;
+
+ if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
+ heap = zend_mm_set_heap(phpdbg_original_heap_sigsafe_mem());
+ }
+ if ((is_mm = is_zend_mm())) {
+ used = zend_memory_usage(0);
+ real = zend_memory_usage(1);
+ peak_used = zend_memory_peak_usage(0);
+ peak_real = zend_memory_peak_usage(1);
+ }
+ if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
+ zend_mm_set_heap(heap);
+ }
+
+ if (is_mm) {
+ phpdbg_notice("meminfo", "", "Memory Manager Information");
+ phpdbg_notice("current", "", "Current");
+ phpdbg_writeln("used", "mem=\"%.3f\"", "|-------> Used:\t%.3f kB", (float) (used / 1024));
+ phpdbg_writeln("real", "mem=\"%.3f\"", "|-------> Real:\t%.3f kB", (float) (real / 1024));
+ phpdbg_notice("peak", "", "Peak");
+ phpdbg_writeln("used", "mem=\"%.3f\"", "|-------> Used:\t%.3f kB", (float) (peak_used / 1024));
+ phpdbg_writeln("real", "mem=\"%.3f\"", "|-------> Real:\t%.3f kB", (float) (peak_real / 1024));
} else {
- phpdbg_error("Memory Manager Disabled!");
+ phpdbg_error("inactive", "type=\"memory_manager\"", "Memory Manager Disabled!");
}
return SUCCESS;
} /* }}} */
-static inline void phpdbg_print_class_name(zend_class_entry **ce TSRMLS_DC) /* {{{ */
+static inline void phpdbg_print_class_name(zend_class_entry *ce) /* {{{ */
{
- phpdbg_write(
- "%s %s %s (%d)",
- ((*ce)->type == ZEND_USER_CLASS) ?
- "User" : "Internal",
- ((*ce)->ce_flags & ZEND_ACC_INTERFACE) ?
- "Interface" :
- ((*ce)->ce_flags & ZEND_ACC_ABSTRACT) ?
- "Abstract Class" :
- "Class",
- (*ce)->name, zend_hash_num_elements(&(*ce)->function_table));
+ const char *visibility = ce->type == ZEND_USER_CLASS ? "User" : "Internal";
+ const char *type = (ce->ce_flags & ZEND_ACC_INTERFACE) ? "Interface" : (ce->ce_flags & ZEND_ACC_ABSTRACT) ? "Abstract Class" : "Class";
+
+ phpdbg_writeln("class", "type=\"%s\" flags=\"%s\" name=\"%.*s\" methodcount=\"%d\"", "%s %s %.*s (%d)", visibility, type, ZSTR_LEN(ce->name), ZSTR_VAL(ce->name), zend_hash_num_elements(&ce->function_table));
} /* }}} */
PHPDBG_INFO(classes) /* {{{ */
{
- HashPosition position;
- zend_class_entry **ce;
+ zend_class_entry *ce;
HashTable classes;
zend_hash_init(&classes, 8, NULL, NULL, 0);
- for (zend_hash_internal_pointer_reset_ex(EG(class_table), &position);
- zend_hash_get_current_data_ex(EG(class_table), (void**)&ce, &position) == SUCCESS;
- zend_hash_move_forward_ex(EG(class_table), &position)) {
-
- if ((*ce)->type == ZEND_USER_CLASS) {
- zend_hash_next_index_insert(
- &classes, ce, sizeof(ce), NULL);
- }
- }
-
- phpdbg_notice("User Classes (%d)",
- zend_hash_num_elements(&classes));
+ phpdbg_try_access {
+ ZEND_HASH_FOREACH_PTR(EG(class_table), ce) {
+ if (ce->type == ZEND_USER_CLASS) {
+ zend_hash_next_index_insert_ptr(&classes, ce);
+ }
+ } ZEND_HASH_FOREACH_END();
+ } phpdbg_catch_access {
+ phpdbg_notice("signalsegv", "", "Not all classes could be fetched, possibly invalid data source");
+ } phpdbg_end_try_access();
- for (zend_hash_internal_pointer_reset_ex(&classes, &position);
- zend_hash_get_current_data_ex(&classes, (void**)&ce, &position) == SUCCESS;
- zend_hash_move_forward_ex(&classes, &position)) {
+ phpdbg_notice("classinfo", "num=\"%d\"", "User Classes (%d)", zend_hash_num_elements(&classes));
- phpdbg_print_class_name(ce TSRMLS_CC);
- phpdbg_writeln(EMPTY);
+ /* once added, assume that classes are stable... until shutdown. */
+ ZEND_HASH_FOREACH_PTR(&classes, ce) {
+ phpdbg_print_class_name(ce);
- if ((*ce)->parent) {
- zend_class_entry *pce = (*ce)->parent;
+ if (ce->parent) {
+ zend_class_entry *pce;
+ phpdbg_xml("<parents %r>");
+ pce = ce->parent;
do {
- phpdbg_write("|-------- ");
- phpdbg_print_class_name(&pce TSRMLS_CC);
- phpdbg_writeln(EMPTY);
+ phpdbg_out("|-------- ");
+ phpdbg_print_class_name(pce);
} while ((pce = pce->parent));
+ phpdbg_xml("</parents>");
}
- if ((*ce)->info.user.filename) {
- phpdbg_writeln(
- "|---- in %s on line %u",
- (*ce)->info.user.filename,
- (*ce)->info.user.line_start);
+ if (ce->info.user.filename) {
+ phpdbg_writeln("classsource", "file=\"%s\" line=\"%u\"", "|---- in %s on line %u", ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start);
} else {
- phpdbg_writeln("|---- no source code");
+ phpdbg_writeln("classsource", "", "|---- no source code");
}
- phpdbg_writeln(EMPTY);
- }
+ } ZEND_HASH_FOREACH_END();
zend_hash_destroy(&classes);
@@ -334,36 +420,34 @@ PHPDBG_INFO(classes) /* {{{ */
PHPDBG_INFO(funcs) /* {{{ */
{
- HashPosition position;
- zend_function *zf, **pzf;
+ zend_function *zf;
HashTable functions;
zend_hash_init(&functions, 8, NULL, NULL, 0);
- for (zend_hash_internal_pointer_reset_ex(EG(function_table), &position);
- zend_hash_get_current_data_ex(EG(function_table), (void**)&zf, &position) == SUCCESS;
- zend_hash_move_forward_ex(EG(function_table), &position)) {
+ phpdbg_try_access {
+ ZEND_HASH_FOREACH_PTR(EG(function_table), zf) {
+ if (zf->type == ZEND_USER_FUNCTION) {
+ zend_hash_next_index_insert_ptr(&functions, zf);
+ }
+ } ZEND_HASH_FOREACH_END();
+ } phpdbg_catch_access {
+ phpdbg_notice("signalsegv", "", "Not all functions could be fetched, possibly invalid data source");
+ } phpdbg_end_try_access();
- if (zf->type == ZEND_USER_FUNCTION) {
- zend_hash_next_index_insert(
- &functions, (void**) &zf, sizeof(zend_function), NULL);
- }
- }
+ phpdbg_notice("functioninfo", "num=\"%d\"", "User Functions (%d)", zend_hash_num_elements(&functions));
- phpdbg_notice("User Functions (%d)",
- zend_hash_num_elements(&functions));
+ ZEND_HASH_FOREACH_PTR(&functions, zf) {
+ zend_op_array *op_array = &zf->op_array;
- for (zend_hash_internal_pointer_reset_ex(&functions, &position);
- zend_hash_get_current_data_ex(&functions, (void**)&pzf, &position) == SUCCESS;
- zend_hash_move_forward_ex(&functions, &position)) {
- zend_op_array *op_array = &((*pzf)->op_array);
+ phpdbg_write("function", "name=\"%s\"", "|-------- %s", op_array->function_name ? ZSTR_VAL(op_array->function_name) : "{main}");
- phpdbg_writeln(
- "|-------- %s in %s on line %d",
- op_array->function_name ? op_array->function_name : "{main}",
- op_array->filename ? op_array->filename : "(no source code)",
- op_array->line_start);
- }
+ if (op_array->filename) {
+ phpdbg_writeln("functionsource", "file=\"%s\" line=\"%d\"", " in %s on line %d", ZSTR_VAL(op_array->filename), op_array->line_start);
+ } else {
+ phpdbg_writeln("functionsource", "", " (no source code)");
+ }
+ } ZEND_HASH_FOREACH_END();
zend_hash_destroy(&functions);
diff --git a/sapi/phpdbg/phpdbg_info.h b/sapi/phpdbg/phpdbg_info.h
index 36b34738b1..cc0d624755 100644
--- a/sapi/phpdbg/phpdbg_info.h
+++ b/sapi/phpdbg/phpdbg_info.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -30,7 +30,9 @@ PHPDBG_INFO(break);
PHPDBG_INFO(classes);
PHPDBG_INFO(funcs);
PHPDBG_INFO(error);
+PHPDBG_INFO(constants);
PHPDBG_INFO(vars);
+PHPDBG_INFO(globals);
PHPDBG_INFO(literal);
PHPDBG_INFO(memory);
diff --git a/sapi/phpdbg/phpdbg_io.c b/sapi/phpdbg/phpdbg_io.c
new file mode 100644
index 0000000000..98628b77f9
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_io.c
@@ -0,0 +1,361 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Anatol Belski <ab@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "phpdbg_io.h"
+
+#ifdef PHP_WIN32
+#undef UNICODE
+#include "win32/inet.h"
+#include <winsock2.h>
+#include <windows.h>
+#include <Ws2tcpip.h>
+#include "win32/sockets.h"
+
+#else
+
+#if HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#include <sys/socket.h>
+#include <netinet/in.h>
+#if HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+#include <netdb.h>
+#include <fcntl.h>
+#include <poll.h>
+#endif
+
+ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+
+/* is easy to generalize ... but not needed for now */
+PHPDBG_API int phpdbg_consume_stdin_line(char *buf) {
+ int bytes = PHPDBG_G(input_buflen), len = 0;
+
+ if (PHPDBG_G(input_buflen)) {
+ memcpy(buf, PHPDBG_G(input_buffer), bytes);
+ }
+
+ PHPDBG_G(last_was_newline) = 1;
+
+ do {
+ int i;
+ if (bytes <= 0) {
+ continue;
+ }
+
+ for (i = len; i < len + bytes; i++) {
+ if (buf[i] == '\x03') {
+ if (i != len + bytes - 1) {
+ memmove(buf + i, buf + i + 1, len + bytes - i - 1);
+ }
+ len--;
+ i--;
+ continue;
+ }
+ if (buf[i] == '\n') {
+ PHPDBG_G(input_buflen) = len + bytes - 1 - i;
+ if (PHPDBG_G(input_buflen)) {
+ memcpy(PHPDBG_G(input_buffer), buf + i + 1, PHPDBG_G(input_buflen));
+ }
+ if (i != PHPDBG_MAX_CMD - 1) {
+ buf[i + 1] = 0;
+ }
+ return i;
+ }
+ }
+
+ len += bytes;
+ } while ((bytes = phpdbg_mixed_read(PHPDBG_G(io)[PHPDBG_STDIN].fd, buf + len, PHPDBG_MAX_CMD - len, -1)) > 0);
+
+ if (bytes <= 0) {
+ PHPDBG_G(flags) |= PHPDBG_IS_QUITTING | PHPDBG_IS_DISCONNECTED;
+ zend_bailout();
+ }
+
+ return bytes;
+}
+
+PHPDBG_API int phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo) {
+ int got_now, i = len, j;
+ char *p = ptr;
+#ifndef PHP_WIN32
+ struct pollfd pfd;
+
+ if (tmo < 0) goto recv_once;
+ pfd.fd = sock;
+ pfd.events = POLLIN;
+
+ j = poll(&pfd, 1, tmo);
+
+ if (j == 0) {
+#else
+ struct fd_set readfds;
+ struct timeval ttmo;
+
+ if (tmo < 0) goto recv_once;
+ FD_ZERO(&readfds);
+ FD_SET(sock, &readfds);
+
+ ttmo.tv_sec = 0;
+ ttmo.tv_usec = tmo*1000;
+
+ j = select(0, &readfds, NULL, NULL, &ttmo);
+
+ if (j <= 0) {
+#endif
+ return -1;
+ }
+
+recv_once:
+ while(i > 0) {
+ if (tmo < 0) {
+ /* There's something to read. Read what's available and proceed
+ disregarding whether len could be exhausted or not.*/
+ int can_read = recv(sock, p, i, MSG_PEEK);
+#ifndef _WIN32
+ if (can_read == -1 && errno == EINTR) {
+ continue;
+ }
+#endif
+ i = can_read;
+ }
+
+#ifdef _WIN32
+ got_now = recv(sock, p, i, 0);
+#else
+ do {
+ got_now = recv(sock, p, i, 0);
+ } while (got_now == -1 && errno == EINTR);
+#endif
+
+ if (got_now == -1) {
+ quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, ZEND_STRL("Read operation timed out!\n"));
+ return -1;
+ }
+ i -= got_now;
+ p += got_now;
+ }
+
+ return p - ptr;
+}
+
+PHPDBG_API int phpdbg_send_bytes(int sock, const char *ptr, int len) {
+ int sent, i = len;
+ const char *p = ptr;
+/* XXX poll/select needed here? */
+ while(i > 0) {
+ sent = send(sock, p, i, 0);
+ if (sent == -1) {
+ return -1;
+ }
+ i -= sent;
+ p += sent;
+ }
+
+ return len;
+}
+
+
+PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo) {
+ int ret;
+
+ if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) {
+ return phpdbg_consume_bytes(sock, ptr, len, tmo);
+ }
+
+ do {
+ ret = read(sock, ptr, len);
+ } while (ret == -1 && errno == EINTR);
+
+ return ret;
+}
+
+static int phpdbg_output_pager(int sock, const char *ptr, int len) {
+ int count = 0, bytes = 0;
+ const char *p = ptr, *endp = ptr + len;
+
+ while ((p = memchr(p, '\n', endp - p))) {
+ count++;
+ p++;
+
+ if (count % PHPDBG_G(lines) == 0) {
+ bytes += write(sock, ptr + bytes, (p - ptr) - bytes);
+
+ if (memchr(p, '\n', endp - p)) {
+ char buf[PHPDBG_MAX_CMD];
+ write(sock, ZEND_STRL("\r---Type <return> to continue or q <return> to quit---"));
+ phpdbg_consume_stdin_line(buf);
+ if (*buf == 'q') {
+ break;
+ }
+ write(sock, "\r", 1);
+ } else break;
+ }
+ }
+ if (bytes && count % PHPDBG_G(lines) != 0) {
+ bytes += write(sock, ptr + bytes, len - bytes);
+ } else if (!bytes) {
+ bytes += write(sock, ptr, len);
+ }
+ return bytes;
+}
+
+PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len) {
+ if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) {
+ return phpdbg_send_bytes(sock, ptr, len);
+ }
+
+ if ((PHPDBG_G(flags) & PHPDBG_HAS_PAGINATION)
+ && !(PHPDBG_G(flags) & PHPDBG_WRITE_XML)
+ && PHPDBG_G(io)[PHPDBG_STDOUT].fd == sock
+ && PHPDBG_G(lines) > 0) {
+ return phpdbg_output_pager(sock, ptr, len);
+ }
+
+ return write(sock, ptr, len);
+}
+
+PHPDBG_API int phpdbg_open_socket(const char *interface, unsigned short port) {
+ struct addrinfo res;
+ int fd = phpdbg_create_listenable_socket(interface, port, &res);
+
+ if (fd == -1) {
+ return -1;
+ }
+
+ if (bind(fd, res.ai_addr, res.ai_addrlen) == -1) {
+ phpdbg_close_socket(fd);
+ return -4;
+ }
+
+ listen(fd, 5);
+
+ return fd;
+}
+
+
+PHPDBG_API int phpdbg_create_listenable_socket(const char *addr, unsigned short port, struct addrinfo *addr_res) {
+ int sock = -1, rc;
+ int reuse = 1;
+ struct in6_addr serveraddr;
+ struct addrinfo hints, *res = NULL;
+ char port_buf[8];
+ int8_t any_addr = *addr == '*';
+
+ do {
+ memset(&hints, 0, sizeof hints);
+ if (any_addr) {
+ hints.ai_flags = AI_PASSIVE;
+ } else {
+ hints.ai_flags = AI_NUMERICSERV;
+ }
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+
+ rc = inet_pton(AF_INET, addr, &serveraddr);
+ if (1 == rc) {
+ hints.ai_family = AF_INET;
+ if (!any_addr) {
+ hints.ai_flags |= AI_NUMERICHOST;
+ }
+ } else {
+ rc = inet_pton(AF_INET6, addr, &serveraddr);
+ if (1 == rc) {
+ hints.ai_family = AF_INET6;
+ if (!any_addr) {
+ hints.ai_flags |= AI_NUMERICHOST;
+ }
+ } else {
+ /* XXX get host by name ??? */
+ }
+ }
+
+ snprintf(port_buf, 7, "%u", port);
+ if (!any_addr) {
+ rc = getaddrinfo(addr, port_buf, &hints, &res);
+ } else {
+ rc = getaddrinfo(NULL, port_buf, &hints, &res);
+ }
+
+ if (0 != rc) {
+#ifndef PHP_WIN32
+ if (rc == EAI_SYSTEM) {
+ char buf[128];
+ int wrote;
+
+ wrote = snprintf(buf, 128, "Could not translate address '%s'", addr);
+ buf[wrote] = '\0';
+ quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, buf, strlen(buf));
+
+ return sock;
+ } else {
+#endif
+ char buf[256];
+ int wrote;
+
+ wrote = snprintf(buf, 256, "Host '%s' not found. %s", addr, estrdup(gai_strerror(rc)));
+ buf[wrote] = '\0';
+ quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, buf, strlen(buf));
+
+ return sock;
+#ifndef PHP_WIN32
+ }
+#endif
+ return sock;
+ }
+
+ if((sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
+ char buf[128];
+ int wrote;
+
+ wrote = sprintf(buf, "Unable to create socket");
+ buf[wrote] = '\0';
+ quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, buf, strlen(buf));
+
+ return sock;
+ }
+
+ if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char*) &reuse, sizeof(reuse)) == -1) {
+ phpdbg_close_socket(sock);
+ return sock;
+ }
+
+
+ } while (0);
+
+ *addr_res = *res;
+
+ return sock;
+}
+
+PHPDBG_API void phpdbg_close_socket(int sock) {
+ if (socket >= 0) {
+#ifdef _WIN32
+ closesocket(sock);
+#else
+ shutdown(sock, SHUT_RDWR);
+ close(sock);
+#endif
+ }
+}
+
diff --git a/sapi/phpdbg/phpdbg_io.h b/sapi/phpdbg/phpdbg_io.h
new file mode 100644
index 0000000000..fdd579d548
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_io.h
@@ -0,0 +1,41 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Anatol Belski <ab@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#ifndef PHPDBG_IO_H
+#define PHPDBG_IO_H
+
+#include "phpdbg.h"
+
+/* Older versions of glibc <= 2.3.0 and <= OS X 10.5 do not have this constant defined */
+#ifndef AI_NUMERICSERV
+#define AI_NUMERICSERV 0
+#endif
+
+PHPDBG_API int phpdbg_consume_stdin_line(char *buf);
+
+PHPDBG_API int phpdbg_consume_bytes(int sock, char *ptr, int len, int tmo);
+PHPDBG_API int phpdbg_send_bytes(int sock, const char *ptr, int len);
+PHPDBG_API int phpdbg_mixed_read(int sock, char *ptr, int len, int tmo);
+PHPDBG_API int phpdbg_mixed_write(int sock, const char *ptr, int len);
+
+PHPDBG_API int phpdbg_create_listenable_socket(const char *addr, unsigned short port, struct addrinfo *res);
+PHPDBG_API int phpdbg_open_socket(const char *interface, unsigned short port);
+PHPDBG_API void phpdbg_close_socket(int sock);
+
+#endif /* PHPDBG_IO_H */
+
diff --git a/sapi/phpdbg/phpdbg_lexer.c b/sapi/phpdbg/phpdbg_lexer.c
index 3092dc396d..36c6f422bd 100644
--- a/sapi/phpdbg/phpdbg_lexer.c
+++ b/sapi/phpdbg/phpdbg_lexer.c
@@ -1,5 +1,5 @@
-/* Generated by re2c 0.13.5 */
-#line 1 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+/* Generated by re2c 0.14.3 */
+#line 1 "sapi/phpdbg/phpdbg_lexer.l"
/*
* phpdbg_lexer.l
*/
@@ -16,6 +16,7 @@
#define YYGETCONDITION() LEX(state)
#define YYCURSOR LEX(cursor)
#define YYMARKER LEX(marker)
+#define YYCTXMARKER LEX(ctxmarker)
#define yyleng LEX(len)
#define yytext ((char*) LEX(text))
#undef YYDEBUG
@@ -23,12 +24,13 @@
#define YYFILL(n)
#define NORMAL 0
-#define RAW 1
-#define INITIAL 2
+#define PRE_RAW 1
+#define RAW 2
+#define INITIAL 3
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-void phpdbg_init_lexer (phpdbg_param_t *stack, char *input TSRMLS_DC) {
+void phpdbg_init_lexer (phpdbg_param_t *stack, char *input) {
PHPDBG_G(parser_stack) = stack;
YYSETCONDITION(INITIAL);
@@ -37,21 +39,43 @@ void phpdbg_init_lexer (phpdbg_param_t *stack, char *input TSRMLS_DC) {
LEX(len) = strlen(input);
}
+static int unescape_string(char *s) {
+ switch (*s) {
+ case '\'':
+ case '\"': {
+ char start = *s;
+ size_t off = 1;
+ do {
+ if (s[off] == '\\') {
+ off++;
+ }
+ *s = s[off];
+ } while ((++s)[off] != start);
+ return off + 1;
+ }
+ }
+
+ return 0;
+}
+
int phpdbg_lex (phpdbg_param_t* yylval) {
- TSRMLS_FETCH(); /* Slow, but this is not a major problem here. TODO: Use TSRMLS_DC */
restart:
LEX(text) = YYCURSOR;
-#line 48 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
+#line 68 "sapi/phpdbg/phpdbg_lexer.c"
{
YYCTYPE yych;
unsigned int yyaccept = 0;
- if (YYGETCONDITION() < 1) {
- goto yyc_NORMAL;
+ if (YYGETCONDITION() < 2) {
+ if (YYGETCONDITION() < 1) {
+ goto yyc_NORMAL;
+ } else {
+ goto yyc_PRE_RAW;
+ }
} else {
- if (YYGETCONDITION() < 2) {
+ if (YYGETCONDITION() < 3) {
goto yyc_RAW;
} else {
goto yyc_INITIAL;
@@ -62,7 +86,7 @@ yyc_INITIAL:
{
static const unsigned char yybm[] = {
0, 0, 0, 0, 0, 0, 0, 0,
- 0, 128, 128, 0, 0, 128, 0, 0,
+ 0, 128, 0, 0, 0, 128, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
128, 0, 0, 0, 0, 0, 0, 0,
@@ -94,220 +118,217 @@ yyc_INITIAL:
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
-
- YYDEBUG(0, *YYCURSOR);
+ YYDEBUG(1, *YYCURSOR);
YYFILL(4);
yych = *YYCURSOR;
- if (yych <= 'D') {
- if (yych <= '\n') {
- if (yych <= 0x00) goto yy6;
- if (yych <= 0x08) goto yy11;
- if (yych >= '\n') goto yy4;
+ if (yych <= '#') {
+ if (yych <= '\f') {
+ if (yych <= 0x08) {
+ if (yych <= 0x00) goto yy9;
+ goto yy14;
+ } else {
+ if (yych <= '\t') goto yy3;
+ if (yych <= '\n') goto yy9;
+ goto yy14;
+ }
} else {
- if (yych <= '\r') {
- if (yych <= '\f') goto yy11;
+ if (yych <= 0x1F) {
+ if (yych >= 0x0E) goto yy14;
} else {
- if (yych != ' ') goto yy11;
+ if (yych <= ' ') goto yy5;
+ if (yych <= '"') goto yy14;
+ goto yy8;
}
}
} else {
- if (yych <= 'd') {
- if (yych <= 'Q') {
- if (yych <= 'E') goto yy7;
- goto yy11;
+ if (yych <= 'S') {
+ if (yych <= 'E') {
+ if (yych <= 'D') goto yy14;
+ goto yy10;
} else {
- if (yych <= 'R') goto yy10;
- if (yych <= 'S') goto yy8;
+ if (yych <= 'Q') goto yy14;
+ if (yych <= 'R') goto yy13;
goto yy11;
}
} else {
if (yych <= 'q') {
- if (yych <= 'e') goto yy7;
- goto yy11;
+ if (yych == 'e') goto yy10;
+ goto yy14;
} else {
- if (yych <= 'r') goto yy9;
- if (yych <= 's') goto yy8;
- goto yy11;
+ if (yych <= 'r') goto yy12;
+ if (yych <= 's') goto yy11;
+ goto yy14;
}
}
}
- YYDEBUG(2, *YYCURSOR);
- ++YYCURSOR;
- if ((yych = *YYCURSOR) <= '\f') {
- if (yych <= 0x08) goto yy3;
- if (yych <= '\n') goto yy26;
- } else {
- if (yych <= '\r') goto yy26;
- if (yych == ' ') goto yy26;
- }
yy3:
YYDEBUG(3, *YYCURSOR);
+ ++YYCURSOR;
+ if (yybm[0+(yych = *YYCURSOR)] & 128) {
+ goto yy5;
+ }
+yy4:
+ YYDEBUG(4, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 161 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 206 "sapi/phpdbg/phpdbg_lexer.l"
{
YYSETCONDITION(NORMAL);
YYCURSOR = LEX(text);
goto restart;
}
-#line 154 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy4:
- YYDEBUG(4, *YYCURSOR);
- ++YYCURSOR;
- if ((yych = *YYCURSOR) <= '\f') {
- if (yych <= 0x08) goto yy5;
- if (yych <= '\n') goto yy26;
- } else {
- if (yych <= '\r') goto yy26;
- if (yych == ' ') goto yy26;
- }
+#line 181 "sapi/phpdbg/phpdbg_lexer.c"
yy5:
YYDEBUG(5, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ YYDEBUG(6, *YYCURSOR);
+ if (yybm[0+yych] & 128) {
+ goto yy5;
+ }
+ YYDEBUG(7, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 68 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 175 "sapi/phpdbg/phpdbg_lexer.l"
{
- return 0;
+ /* ignore whitespace */
+
+ goto restart;
}
-#line 172 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy6:
- YYDEBUG(6, *YYCURSOR);
- yych = *++YYCURSOR;
- goto yy3;
-yy7:
- YYDEBUG(7, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'V') goto yy22;
- if (yych == 'v') goto yy22;
- goto yy3;
+#line 199 "sapi/phpdbg/phpdbg_lexer.c"
yy8:
YYDEBUG(8, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'H') goto yy18;
- if (yych == 'h') goto yy18;
- goto yy3;
+ yych = *++YYCURSOR;
+ goto yy4;
yy9:
YYDEBUG(9, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yybm[0+yych] & 128) {
- goto yy15;
- }
- if (yych == 'U') goto yy12;
- if (yych == 'u') goto yy12;
- goto yy3;
+ yych = *++YYCURSOR;
+ goto yy4;
yy10:
YYDEBUG(10, *YYCURSOR);
yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'U') goto yy12;
- if (yych == 'u') goto yy12;
- goto yy3;
+ if (yych == 'V') goto yy25;
+ if (yych == 'v') goto yy25;
+ goto yy4;
yy11:
YYDEBUG(11, *YYCURSOR);
- yych = *++YYCURSOR;
- goto yy3;
+ yyaccept = 0;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == 'H') goto yy21;
+ if (yych == 'h') goto yy21;
+ goto yy4;
yy12:
YYDEBUG(12, *YYCURSOR);
- yych = *++YYCURSOR;
- if (yych == 'N') goto yy14;
- if (yych == 'n') goto yy14;
+ yyaccept = 0;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych <= 0x1F) {
+ if (yych <= '\t') {
+ if (yych <= 0x08) goto yy4;
+ goto yy18;
+ } else {
+ if (yych == '\r') goto yy18;
+ goto yy4;
+ }
+ } else {
+ if (yych <= 'U') {
+ if (yych <= ' ') goto yy18;
+ if (yych <= 'T') goto yy4;
+ goto yy15;
+ } else {
+ if (yych == 'u') goto yy15;
+ goto yy4;
+ }
+ }
yy13:
YYDEBUG(13, *YYCURSOR);
- YYCURSOR = YYMARKER;
- goto yy3;
+ yyaccept = 0;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == 'U') goto yy15;
+ if (yych == 'u') goto yy15;
+ goto yy4;
yy14:
YYDEBUG(14, *YYCURSOR);
yych = *++YYCURSOR;
- if (yybm[0+yych] & 128) {
- goto yy15;
- }
- goto yy13;
+ goto yy4;
yy15:
YYDEBUG(15, *YYCURSOR);
- ++YYCURSOR;
- YYFILL(1);
- yych = *YYCURSOR;
+ yych = *++YYCURSOR;
+ if (yych == 'N') goto yy17;
+ if (yych == 'n') goto yy17;
+yy16:
YYDEBUG(16, *YYCURSOR);
- if (yybm[0+yych] & 128) {
- goto yy15;
- }
+ YYCURSOR = YYMARKER;
+ goto yy4;
+yy17:
YYDEBUG(17, *YYCURSOR);
- yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 155 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
- {
- YYSETCONDITION(RAW);
- phpdbg_init_param(yylval, EMPTY_PARAM);
- return T_RUN;
-}
-#line 245 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy18:
- YYDEBUG(18, *YYCURSOR);
yych = *++YYCURSOR;
if (yych <= '\f') {
- if (yych <= 0x08) goto yy13;
- if (yych >= '\v') goto yy13;
+ if (yych != '\t') goto yy16;
} else {
- if (yych <= '\r') goto yy19;
- if (yych != ' ') goto yy13;
+ if (yych <= '\r') goto yy18;
+ if (yych != ' ') goto yy16;
}
-yy19:
- YYDEBUG(19, *YYCURSOR);
+yy18:
+ YYDEBUG(18, *YYCURSOR);
++YYCURSOR;
YYFILL(1);
yych = *YYCURSOR;
- YYDEBUG(20, *YYCURSOR);
+ YYDEBUG(19, *YYCURSOR);
if (yych <= '\f') {
- if (yych <= 0x08) goto yy21;
- if (yych <= '\n') goto yy19;
+ if (yych == '\t') goto yy18;
} else {
- if (yych <= '\r') goto yy19;
- if (yych == ' ') goto yy19;
+ if (yych <= '\r') goto yy18;
+ if (yych == ' ') goto yy18;
}
-yy21:
- YYDEBUG(21, *YYCURSOR);
+ YYDEBUG(20, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 150 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 193 "sapi/phpdbg/phpdbg_lexer.l"
{
- YYSETCONDITION(RAW);
+ YYSETCONDITION(PRE_RAW);
phpdbg_init_param(yylval, EMPTY_PARAM);
- return T_SHELL;
+ return T_RUN;
}
-#line 278 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy22:
- YYDEBUG(22, *YYCURSOR);
+#line 293 "sapi/phpdbg/phpdbg_lexer.c"
+yy21:
+ YYDEBUG(21, *YYCURSOR);
yych = *++YYCURSOR;
if (yych <= '\f') {
- if (yych <= 0x08) goto yy13;
- if (yych >= '\v') goto yy13;
+ if (yych != '\t') goto yy16;
} else {
- if (yych <= '\r') goto yy23;
- if (yych != ' ') goto yy13;
+ if (yych <= '\r') goto yy22;
+ if (yych != ' ') goto yy16;
}
-yy23:
- YYDEBUG(23, *YYCURSOR);
+yy22:
+ YYDEBUG(22, *YYCURSOR);
++YYCURSOR;
YYFILL(1);
yych = *YYCURSOR;
- YYDEBUG(24, *YYCURSOR);
+ YYDEBUG(23, *YYCURSOR);
if (yych <= '\f') {
- if (yych <= 0x08) goto yy25;
- if (yych <= '\n') goto yy23;
+ if (yych == '\t') goto yy22;
} else {
- if (yych <= '\r') goto yy23;
- if (yych == ' ') goto yy23;
+ if (yych <= '\r') goto yy22;
+ if (yych == ' ') goto yy22;
}
-yy25:
- YYDEBUG(25, *YYCURSOR);
+ YYDEBUG(24, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 145 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 187 "sapi/phpdbg/phpdbg_lexer.l"
{
- YYSETCONDITION(RAW);
+ YYSETCONDITION(PRE_RAW);
phpdbg_init_param(yylval, EMPTY_PARAM);
- return T_EVAL;
+ return T_SHELL;
}
-#line 311 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
+#line 323 "sapi/phpdbg/phpdbg_lexer.c"
+yy25:
+ YYDEBUG(25, *YYCURSOR);
+ yych = *++YYCURSOR;
+ if (yych <= '\f') {
+ if (yych != '\t') goto yy16;
+ } else {
+ if (yych <= '\r') goto yy26;
+ if (yych != ' ') goto yy16;
+ }
yy26:
YYDEBUG(26, *YYCURSOR);
++YYCURSOR;
@@ -315,72 +336,107 @@ yy26:
yych = *YYCURSOR;
YYDEBUG(27, *YYCURSOR);
if (yych <= '\f') {
- if (yych <= 0x08) goto yy28;
- if (yych <= '\n') goto yy26;
+ if (yych == '\t') goto yy26;
} else {
if (yych <= '\r') goto yy26;
if (yych == ' ') goto yy26;
}
-yy28:
YYDEBUG(28, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 139 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 181 "sapi/phpdbg/phpdbg_lexer.l"
{
- /* ignore whitespace */
-
- goto restart;
+ YYSETCONDITION(PRE_RAW);
+ phpdbg_init_param(yylval, EMPTY_PARAM);
+ return T_EVAL;
}
-#line 334 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
+#line 353 "sapi/phpdbg/phpdbg_lexer.c"
}
/* *********************************** */
yyc_NORMAL:
{
static const unsigned char yybm[] = {
- 0, 16, 16, 16, 16, 16, 16, 16,
- 16, 8, 8, 16, 16, 8, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 8, 16, 16, 0, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 48, 16,
- 176, 176, 176, 176, 176, 176, 176, 176,
- 176, 176, 0, 16, 16, 16, 16, 16,
- 16, 208, 208, 208, 208, 208, 208, 80,
- 80, 80, 80, 80, 80, 80, 80, 80,
- 80, 80, 80, 80, 80, 80, 80, 80,
- 80, 80, 80, 16, 16, 16, 16, 16,
- 16, 208, 208, 208, 208, 208, 208, 80,
- 80, 80, 80, 80, 80, 80, 80, 80,
- 80, 80, 80, 80, 80, 80, 80, 80,
- 80, 80, 80, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
- 16, 16, 16, 16, 16, 16, 16, 16,
+ /* table 1 .. 8: 0 */
+ 0, 242, 242, 242, 242, 242, 242, 242,
+ 242, 160, 0, 242, 242, 160, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 160, 242, 50, 160, 242, 242, 242, 194,
+ 242, 242, 242, 242, 242, 242, 243, 242,
+ 251, 251, 251, 251, 251, 251, 251, 251,
+ 251, 251, 160, 242, 242, 242, 242, 242,
+ 242, 254, 254, 254, 254, 254, 254, 246,
+ 246, 246, 246, 246, 246, 246, 246, 246,
+ 246, 246, 246, 246, 246, 246, 246, 246,
+ 246, 246, 246, 242, 2, 242, 242, 242,
+ 242, 254, 254, 254, 254, 254, 254, 246,
+ 246, 246, 246, 246, 246, 246, 246, 246,
+ 246, 246, 246, 246, 246, 246, 246, 246,
+ 246, 246, 246, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ 242, 242, 242, 242, 242, 242, 242, 242,
+ /* table 9 .. 10: 256 */
+ 0, 128, 128, 128, 128, 128, 128, 128,
+ 128, 64, 0, 128, 128, 64, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 64, 128, 0, 0, 128, 128, 128, 0,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 0, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 128, 128, 128, 128, 128, 128,
};
YYDEBUG(29, *YYCURSOR);
YYFILL(11);
yych = *YYCURSOR;
+ if (yybm[256+yych] & 64) {
+ goto yy31;
+ }
YYDEBUG(-1, yych);
switch (yych) {
- case 0x00: goto yy36;
+ case 0x00:
case '\t':
- case '\r':
- case ' ': goto yy31;
- case '\n': goto yy34;
- case '#': goto yy55;
- case '-': goto yy41;
+ case '\n': goto yy36;
+ case '"': goto yy44;
+ case '#': goto yy34;
+ case '\'': goto yy46;
+ case '-': goto yy38;
case '.':
case '1':
case '2':
@@ -390,28 +446,28 @@ yyc_NORMAL:
case '6':
case '7':
case '8':
- case '9': goto yy42;
- case '0': goto yy45;
- case ':': goto yy57;
+ case '9': goto yy47;
+ case '0': goto yy50;
+ case ':': goto yy41;
case 'D':
- case 'd': goto yy46;
+ case 'd': goto yy51;
case 'E':
- case 'e': goto yy47;
+ case 'e': goto yy52;
case 'F':
- case 'f': goto yy48;
+ case 'f': goto yy53;
case 'I':
- case 'i': goto yy37;
+ case 'i': goto yy40;
case 'N':
- case 'n': goto yy49;
+ case 'n': goto yy54;
case 'O':
- case 'o': goto yy50;
+ case 'o': goto yy55;
case 'T':
- case 't': goto yy51;
+ case 't': goto yy56;
case 'Y':
- case 'y': goto yy52;
- case 'Z': goto yy53;
- case 'z': goto yy54;
- default: goto yy39;
+ case 'y': goto yy57;
+ case 'Z': goto yy58;
+ case 'z': goto yy59;
+ default: goto yy42;
}
yy31:
YYDEBUG(31, *YYCURSOR);
@@ -419,725 +475,1370 @@ yy31:
YYFILL(1);
yych = *YYCURSOR;
YYDEBUG(32, *YYCURSOR);
- if (yybm[0+yych] & 8) {
+ if (yybm[256+yych] & 64) {
goto yy31;
}
YYDEBUG(33, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 139 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 175 "sapi/phpdbg/phpdbg_lexer.l"
{
/* ignore whitespace */
goto restart;
}
-#line 434 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
+#line 490 "sapi/phpdbg/phpdbg_lexer.c"
yy34:
YYDEBUG(34, *YYCURSOR);
- ++YYCURSOR;
- if (yybm[0+(yych = *YYCURSOR)] & 8) {
- goto yy31;
+ YYCTXMARKER = YYCURSOR + 1;
+ yyaccept = 0;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych <= '.') {
+ if (yych <= ',') goto yy35;
+ if (yych <= '-') goto yy146;
+ goto yy147;
+ } else {
+ if (yych <= '/') goto yy35;
+ if (yych <= '9') goto yy147;
}
yy35:
YYDEBUG(35, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 68 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 110 "sapi/phpdbg/phpdbg_lexer.l"
{
- return 0;
+ YYSETCONDITION(INITIAL);
+ return T_SEPARATOR;
}
-#line 448 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
+#line 512 "sapi/phpdbg/phpdbg_lexer.c"
yy36:
YYDEBUG(36, *YYCURSOR);
- yych = *++YYCURSOR;
- goto yy35;
-yy37:
+ ++YYCURSOR;
YYDEBUG(37, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'F') goto yy106;
- if (yych == 'f') goto yy106;
- goto yy40;
+ yyleng = (size_t) YYCURSOR - (size_t) yytext;
+#line 89 "sapi/phpdbg/phpdbg_lexer.l"
+ {
+ return 0;
+}
+#line 522 "sapi/phpdbg/phpdbg_lexer.c"
yy38:
YYDEBUG(38, *YYCURSOR);
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yybm[0+yych] & 1) {
+ goto yy47;
+ }
+ if (yych == 'r') goto yy136;
+ goto yy43;
+yy39:
+ YYDEBUG(39, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 125 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 161 "sapi/phpdbg/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, STR_PARAM);
- yylval->str = zend_strndup(yytext, yyleng);
+ yylval->str = estrndup(yytext, yyleng - unescape_string(yytext));
yylval->len = yyleng;
- return T_ID;
+ return T_ID;
}
-#line 470 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy39:
- YYDEBUG(39, *YYCURSOR);
- yyaccept = 0;
- YYMARKER = ++YYCURSOR;
- YYFILL(3);
- yych = *YYCURSOR;
+#line 542 "sapi/phpdbg/phpdbg_lexer.c"
yy40:
YYDEBUG(40, *YYCURSOR);
- if (yybm[0+yych] & 16) {
- goto yy39;
- }
- if (yych <= '9') goto yy38;
- goto yy62;
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == 'F') goto yy132;
+ if (yych == 'f') goto yy132;
+ goto yy43;
yy41:
YYDEBUG(41, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yybm[0+yych] & 32) {
- goto yy42;
- }
- goto yy40;
+ YYCTXMARKER = YYCURSOR + 1;
+ yych = *++YYCURSOR;
+ if (yych == ':') goto yy130;
+ if (yych == '\\') goto yy68;
+ goto yy128;
yy42:
YYDEBUG(42, *YYCURSOR);
yyaccept = 1;
YYMARKER = ++YYCURSOR;
YYFILL(3);
yych = *YYCURSOR;
+yy43:
YYDEBUG(43, *YYCURSOR);
- if (yybm[0+yych] & 32) {
+ if (yybm[256+yych] & 128) {
goto yy42;
}
- if (yych <= 0x1F) {
- if (yych <= '\n') {
- if (yych <= 0x00) goto yy44;
- if (yych <= 0x08) goto yy39;
- } else {
- if (yych != '\r') goto yy39;
- }
- } else {
- if (yych <= '#') {
- if (yych <= ' ') goto yy44;
- if (yych <= '"') goto yy39;
- } else {
- if (yych == ':') goto yy62;
- goto yy39;
- }
- }
+ if (yych <= ' ') goto yy39;
+ if (yych == '#') goto yy39;
+ if (yych <= '\'') goto yy62;
+ goto yy61;
yy44:
YYDEBUG(44, *YYCURSOR);
- yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 106 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
- {
- phpdbg_init_param(yylval, NUMERIC_PARAM);
- yylval->num = atoi(yytext);
- return T_DIGITS;
-}
-#line 527 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
+ yych = *++YYCURSOR;
+ if (yych == '"') goto yy62;
+ goto yy120;
yy45:
YYDEBUG(45, *YYCURSOR);
- yyaccept = 1;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yybm[0+yych] & 32) {
- goto yy42;
- }
- if (yych <= 0x1F) {
- if (yych <= '\n') {
- if (yych <= 0x00) goto yy44;
- if (yych <= 0x08) goto yy40;
- goto yy44;
+ YYCURSOR = YYMARKER;
+ if (yyaccept <= 3) {
+ if (yyaccept <= 1) {
+ if (yyaccept == 0) {
+ goto yy35;
+ } else {
+ goto yy39;
+ }
} else {
- if (yych == '\r') goto yy44;
- goto yy40;
+ if (yyaccept == 2) {
+ goto yy49;
+ } else {
+ goto yy76;
+ }
}
} else {
- if (yych <= '#') {
- if (yych <= ' ') goto yy44;
- if (yych <= '"') goto yy40;
- goto yy44;
+ if (yyaccept <= 5) {
+ if (yyaccept == 4) {
+ goto yy107;
+ } else {
+ goto yy67;
+ }
} else {
- if (yych == 'x') goto yy102;
- goto yy40;
+ goto yy142;
}
}
yy46:
YYDEBUG(46, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'I') goto yy96;
- if (yych == 'i') goto yy96;
- goto yy40;
+ yych = *++YYCURSOR;
+ if (yych == '\'') goto yy62;
+ goto yy109;
yy47:
YYDEBUG(47, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'N') goto yy91;
- if (yych == 'n') goto yy91;
- goto yy40;
-yy48:
+ yyaccept = 2;
+ YYMARKER = ++YYCURSOR;
+ YYFILL(3);
+ yych = *YYCURSOR;
YYDEBUG(48, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'A') goto yy88;
- if (yych == 'a') goto yy88;
- goto yy40;
+ if (yybm[0+yych] & 1) {
+ goto yy47;
+ }
+ if (yych <= ' ') {
+ if (yych <= '\n') {
+ if (yych <= 0x00) goto yy49;
+ if (yych <= 0x08) goto yy42;
+ } else {
+ if (yych == '\r') goto yy49;
+ if (yych <= 0x1F) goto yy42;
+ }
+ } else {
+ if (yych <= '&') {
+ if (yych <= '!') goto yy42;
+ if (yych <= '"') goto yy62;
+ if (yych >= '$') goto yy42;
+ } else {
+ if (yych <= '\'') goto yy62;
+ if (yych <= '/') goto yy42;
+ if (yych <= ':') goto yy61;
+ goto yy42;
+ }
+ }
yy49:
YYDEBUG(49, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'O') goto yy84;
- if (yych == 'o') goto yy84;
- goto yy40;
+ yyleng = (size_t) YYCURSOR - (size_t) yytext;
+#line 142 "sapi/phpdbg/phpdbg_lexer.l"
+ {
+ phpdbg_init_param(yylval, NUMERIC_PARAM);
+ yylval->num = atoi(yytext);
+ return T_DIGITS;
+}
+#line 649 "sapi/phpdbg/phpdbg_lexer.c"
yy50:
YYDEBUG(50, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 2;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych <= 'N') {
- if (yych == 'F') goto yy83;
- if (yych <= 'M') goto yy40;
- goto yy77;
+ if (yybm[0+yych] & 1) {
+ goto yy47;
+ }
+ if (yych <= 0x1F) {
+ if (yych <= '\n') {
+ if (yych <= 0x00) goto yy49;
+ if (yych <= 0x08) goto yy43;
+ goto yy49;
+ } else {
+ if (yych == '\r') goto yy49;
+ goto yy43;
+ }
} else {
- if (yych <= 'f') {
- if (yych <= 'e') goto yy40;
- goto yy83;
+ if (yych <= '#') {
+ if (yych <= ' ') goto yy49;
+ if (yych <= '"') goto yy43;
+ goto yy49;
} else {
- if (yych == 'n') goto yy77;
- goto yy40;
+ if (yych == 'x') goto yy104;
+ goto yy43;
}
}
yy51:
YYDEBUG(51, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'R') goto yy81;
- if (yych == 'r') goto yy81;
- goto yy40;
+ if (yych == 'I') goto yy98;
+ if (yych == 'i') goto yy98;
+ goto yy43;
yy52:
YYDEBUG(52, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'E') goto yy76;
- if (yych == 'e') goto yy76;
- goto yy40;
+ if (yych == 'N') goto yy93;
+ if (yych == 'n') goto yy93;
+ goto yy43;
yy53:
YYDEBUG(53, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'E') goto yy73;
- goto yy40;
+ if (yych == 'A') goto yy90;
+ if (yych == 'a') goto yy90;
+ goto yy43;
yy54:
YYDEBUG(54, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'e') goto yy61;
- goto yy40;
+ if (yych == 'O') goto yy87;
+ if (yych == 'o') goto yy87;
+ goto yy43;
yy55:
YYDEBUG(55, *YYCURSOR);
- ++YYCURSOR;
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych <= 'N') {
+ if (yych == 'F') goto yy86;
+ if (yych <= 'M') goto yy43;
+ goto yy81;
+ } else {
+ if (yych <= 'f') {
+ if (yych <= 'e') goto yy43;
+ goto yy86;
+ } else {
+ if (yych == 'n') goto yy81;
+ goto yy43;
+ }
+ }
+yy56:
YYDEBUG(56, *YYCURSOR);
- yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 84 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
- {
- return T_POUND;
-}
-#line 634 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == 'R') goto yy84;
+ if (yych == 'r') goto yy84;
+ goto yy43;
yy57:
YYDEBUG(57, *YYCURSOR);
- ++YYCURSOR;
- if ((yych = *YYCURSOR) == ':') goto yy59;
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == 'E') goto yy80;
+ if (yych == 'e') goto yy80;
+ goto yy43;
+yy58:
YYDEBUG(58, *YYCURSOR);
- yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 90 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
- {
- return T_COLON;
-}
-#line 645 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == 'E') goto yy77;
+ goto yy43;
yy59:
YYDEBUG(59, *YYCURSOR);
- ++YYCURSOR;
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych != 'e') goto yy43;
YYDEBUG(60, *YYCURSOR);
- yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 87 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
- {
- return T_DCOLON;
-}
-#line 655 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == 'n') goto yy71;
+ goto yy43;
yy61:
YYDEBUG(61, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'n') goto yy67;
- goto yy40;
+ yych = *++YYCURSOR;
+ if (yych == '/') goto yy65;
+ if (yych == '\\') goto yy68;
+ goto yy45;
yy62:
YYDEBUG(62, *YYCURSOR);
- yych = *++YYCURSOR;
- if (yych == '/') goto yy64;
+ ++YYCURSOR;
+ YYFILL(3);
+ yych = *YYCURSOR;
yy63:
YYDEBUG(63, *YYCURSOR);
- YYCURSOR = YYMARKER;
- if (yyaccept <= 1) {
- if (yyaccept <= 0) {
- goto yy38;
- } else {
- goto yy44;
- }
- } else {
- if (yyaccept <= 2) {
- goto yy72;
- } else {
- goto yy105;
- }
+ if (yybm[0+yych] & 2) {
+ goto yy62;
}
+ if (yych <= '#') goto yy45;
yy64:
YYDEBUG(64, *YYCURSOR);
yych = *++YYCURSOR;
- if (yych != '/') goto yy63;
+ if (yych != '/') goto yy45;
+yy65:
YYDEBUG(65, *YYCURSOR);
- ++YYCURSOR;
+ yych = *++YYCURSOR;
+ if (yych != '/') goto yy45;
YYDEBUG(66, *YYCURSOR);
+ ++YYCURSOR;
+yy67:
+ YYDEBUG(67, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 78 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 123 "sapi/phpdbg/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, STR_PARAM);
- yylval->str = zend_strndup(yytext, yyleng);
+ yylval->str = estrndup(yytext, yyleng);
yylval->len = yyleng;
return T_PROTO;
}
-#line 697 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy67:
- YYDEBUG(67, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych != 'd') goto yy40;
+#line 788 "sapi/phpdbg/phpdbg_lexer.c"
+yy68:
YYDEBUG(68, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych != '_') goto yy40;
-yy69:
+ yyaccept = 1;
+ YYMARKER = ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
YYDEBUG(69, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yybm[0+yych] & 64) {
- goto yy70;
+ if (yych <= ' ') {
+ if (yych <= '\n') {
+ if (yych <= 0x00) goto yy39;
+ if (yych <= 0x08) goto yy68;
+ goto yy39;
+ } else {
+ if (yych == '\r') goto yy39;
+ if (yych <= 0x1F) goto yy68;
+ goto yy39;
+ }
+ } else {
+ if (yych <= '&') {
+ if (yych <= '!') goto yy68;
+ if (yych <= '#') goto yy39;
+ goto yy68;
+ } else {
+ if (yych <= '\'') goto yy39;
+ if (yych != ':') goto yy68;
+ }
}
- goto yy40;
-yy70:
YYDEBUG(70, *YYCURSOR);
- yyaccept = 2;
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ if (yych == '\\') goto yy68;
+ goto yy45;
+yy71:
+ YYDEBUG(71, *YYCURSOR);
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych != 'd') goto yy43;
+ YYDEBUG(72, *YYCURSOR);
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych != '_') goto yy43;
+yy73:
+ YYDEBUG(73, *YYCURSOR);
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yybm[0+yych] & 4) {
+ goto yy74;
+ }
+ goto yy43;
+yy74:
+ YYDEBUG(74, *YYCURSOR);
+ yyaccept = 3;
YYMARKER = ++YYCURSOR;
YYFILL(3);
yych = *YYCURSOR;
- YYDEBUG(71, *YYCURSOR);
- if (yybm[0+yych] & 64) {
- goto yy70;
+ YYDEBUG(75, *YYCURSOR);
+ if (yybm[0+yych] & 4) {
+ goto yy74;
}
- if (yych <= 0x1F) {
+ if (yych <= ' ') {
if (yych <= '\n') {
- if (yych <= 0x00) goto yy72;
- if (yych <= 0x08) goto yy39;
+ if (yych <= 0x00) goto yy76;
+ if (yych <= 0x08) goto yy42;
} else {
- if (yych != '\r') goto yy39;
+ if (yych == '\r') goto yy76;
+ if (yych <= 0x1F) goto yy42;
}
} else {
- if (yych <= '#') {
- if (yych <= ' ') goto yy72;
- if (yych <= '"') goto yy39;
+ if (yych <= '&') {
+ if (yych <= '!') goto yy42;
+ if (yych <= '"') goto yy62;
+ if (yych >= '$') goto yy42;
} else {
- if (yych == ':') goto yy62;
- goto yy39;
+ if (yych <= '\'') goto yy62;
+ if (yych == ':') goto yy61;
+ goto yy42;
}
}
-yy72:
- YYDEBUG(72, *YYCURSOR);
+yy76:
+ YYDEBUG(76, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 118 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 154 "sapi/phpdbg/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, OP_PARAM);
- yylval->str = zend_strndup(yytext, yyleng);
+ yylval->str = estrndup(yytext, yyleng);
yylval->len = yyleng;
return T_OPCODE;
}
-#line 751 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy73:
- YYDEBUG(73, *YYCURSOR);
- yyaccept = 0;
+#line 878 "sapi/phpdbg/phpdbg_lexer.c"
+yy77:
+ YYDEBUG(77, *YYCURSOR);
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych != 'N') goto yy40;
- YYDEBUG(74, *YYCURSOR);
- yyaccept = 0;
+ if (yych != 'N') goto yy43;
+ YYDEBUG(78, *YYCURSOR);
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych != 'D') goto yy40;
- YYDEBUG(75, *YYCURSOR);
- yyaccept = 0;
+ if (yych != 'D') goto yy43;
+ YYDEBUG(79, *YYCURSOR);
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == '_') goto yy69;
- goto yy40;
-yy76:
- YYDEBUG(76, *YYCURSOR);
- yyaccept = 0;
+ if (yych == '_') goto yy73;
+ goto yy43;
+yy80:
+ YYDEBUG(80, *YYCURSOR);
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'S') goto yy77;
- if (yych != 's') goto yy40;
-yy77:
- YYDEBUG(77, *YYCURSOR);
- yyaccept = 0;
+ if (yych == 'S') goto yy81;
+ if (yych != 's') goto yy43;
+yy81:
+ YYDEBUG(81, *YYCURSOR);
+ YYCTXMARKER = YYCURSOR + 1;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
if (yych <= '\f') {
- if (yych <= 0x08) goto yy40;
- if (yych >= '\v') goto yy40;
+ if (yych <= 0x00) goto yy82;
+ if (yych <= 0x08) goto yy43;
+ if (yych >= '\v') goto yy43;
} else {
- if (yych <= '\r') goto yy78;
- if (yych != ' ') goto yy40;
+ if (yych <= '\r') goto yy82;
+ if (yych != ' ') goto yy43;
}
-yy78:
- YYDEBUG(78, *YYCURSOR);
+yy82:
+ YYDEBUG(82, *YYCURSOR);
++YYCURSOR;
- YYFILL(1);
- yych = *YYCURSOR;
- YYDEBUG(79, *YYCURSOR);
- if (yych <= '\f') {
- if (yych <= 0x08) goto yy80;
- if (yych <= '\n') goto yy78;
- } else {
- if (yych <= '\r') goto yy78;
- if (yych == ' ') goto yy78;
- }
-yy80:
- YYDEBUG(80, *YYCURSOR);
+ YYDEBUG(83, *YYCURSOR);
+ YYCURSOR = YYCTXMARKER;
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 94 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 130 "sapi/phpdbg/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, NUMERIC_PARAM);
- yylval->num = 1;
+ yylval->num = 1;
return T_TRUTHY;
}
-#line 805 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy81:
- YYDEBUG(81, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'U') goto yy82;
- if (yych != 'u') goto yy40;
-yy82:
- YYDEBUG(82, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'E') goto yy77;
- if (yych == 'e') goto yy77;
- goto yy40;
-yy83:
- YYDEBUG(83, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'F') goto yy84;
- if (yych != 'f') goto yy40;
+#line 924 "sapi/phpdbg/phpdbg_lexer.c"
yy84:
YYDEBUG(84, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych <= '\f') {
- if (yych <= 0x08) goto yy40;
- if (yych >= '\v') goto yy40;
- } else {
- if (yych <= '\r') goto yy85;
- if (yych != ' ') goto yy40;
- }
+ if (yych == 'U') goto yy85;
+ if (yych != 'u') goto yy43;
yy85:
YYDEBUG(85, *YYCURSOR);
- ++YYCURSOR;
- YYFILL(1);
- yych = *YYCURSOR;
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == 'E') goto yy81;
+ if (yych == 'e') goto yy81;
+ goto yy43;
+yy86:
YYDEBUG(86, *YYCURSOR);
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == 'F') goto yy87;
+ if (yych != 'f') goto yy43;
+yy87:
+ YYDEBUG(87, *YYCURSOR);
+ YYCTXMARKER = YYCURSOR + 1;
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
if (yych <= '\f') {
- if (yych <= 0x08) goto yy87;
- if (yych <= '\n') goto yy85;
+ if (yych <= 0x00) goto yy88;
+ if (yych <= 0x08) goto yy43;
+ if (yych >= '\v') goto yy43;
} else {
- if (yych <= '\r') goto yy85;
- if (yych == ' ') goto yy85;
+ if (yych <= '\r') goto yy88;
+ if (yych != ' ') goto yy43;
}
-yy87:
- YYDEBUG(87, *YYCURSOR);
+yy88:
+ YYDEBUG(88, *YYCURSOR);
+ ++YYCURSOR;
+ YYDEBUG(89, *YYCURSOR);
+ YYCURSOR = YYCTXMARKER;
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 100 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 136 "sapi/phpdbg/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, NUMERIC_PARAM);
yylval->num = 0;
return T_FALSY;
}
-#line 858 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy88:
- YYDEBUG(88, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'L') goto yy89;
- if (yych != 'l') goto yy40;
-yy89:
- YYDEBUG(89, *YYCURSOR);
- yyaccept = 0;
- yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'S') goto yy90;
- if (yych != 's') goto yy40;
+#line 969 "sapi/phpdbg/phpdbg_lexer.c"
yy90:
YYDEBUG(90, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'E') goto yy84;
- if (yych == 'e') goto yy84;
- goto yy40;
+ if (yych == 'L') goto yy91;
+ if (yych != 'l') goto yy43;
yy91:
YYDEBUG(91, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'A') goto yy92;
- if (yych != 'a') goto yy40;
+ if (yych == 'S') goto yy92;
+ if (yych != 's') goto yy43;
yy92:
YYDEBUG(92, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'B') goto yy93;
- if (yych != 'b') goto yy40;
+ if (yych == 'E') goto yy87;
+ if (yych == 'e') goto yy87;
+ goto yy43;
yy93:
YYDEBUG(93, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'L') goto yy94;
- if (yych != 'l') goto yy40;
+ if (yych == 'A') goto yy94;
+ if (yych != 'a') goto yy43;
yy94:
YYDEBUG(94, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'E') goto yy95;
- if (yych != 'e') goto yy40;
+ if (yych == 'B') goto yy95;
+ if (yych != 'b') goto yy43;
yy95:
YYDEBUG(95, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'D') goto yy77;
- if (yych == 'd') goto yy77;
- goto yy40;
+ if (yych == 'L') goto yy96;
+ if (yych != 'l') goto yy43;
yy96:
YYDEBUG(96, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'S') goto yy97;
- if (yych != 's') goto yy40;
+ if (yych == 'E') goto yy97;
+ if (yych != 'e') goto yy43;
yy97:
YYDEBUG(97, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'A') goto yy98;
- if (yych != 'a') goto yy40;
+ if (yych == 'D') goto yy81;
+ if (yych == 'd') goto yy81;
+ goto yy43;
yy98:
YYDEBUG(98, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'B') goto yy99;
- if (yych != 'b') goto yy40;
+ if (yych == 'S') goto yy99;
+ if (yych != 's') goto yy43;
yy99:
YYDEBUG(99, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'L') goto yy100;
- if (yych != 'l') goto yy40;
+ if (yych == 'A') goto yy100;
+ if (yych != 'a') goto yy43;
yy100:
YYDEBUG(100, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'E') goto yy101;
- if (yych != 'e') goto yy40;
+ if (yych == 'B') goto yy101;
+ if (yych != 'b') goto yy43;
yy101:
YYDEBUG(101, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yych == 'D') goto yy84;
- if (yych == 'd') goto yy84;
- goto yy40;
+ if (yych == 'L') goto yy102;
+ if (yych != 'l') goto yy43;
yy102:
YYDEBUG(102, *YYCURSOR);
- yyaccept = 0;
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
- if (yybm[0+yych] & 128) {
- goto yy103;
- }
- goto yy40;
+ if (yych == 'E') goto yy103;
+ if (yych != 'e') goto yy43;
yy103:
YYDEBUG(103, *YYCURSOR);
- yyaccept = 3;
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == 'D') goto yy87;
+ if (yych == 'd') goto yy87;
+ goto yy43;
+yy104:
+ YYDEBUG(104, *YYCURSOR);
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yybm[0+yych] & 8) {
+ goto yy105;
+ }
+ goto yy43;
+yy105:
+ YYDEBUG(105, *YYCURSOR);
+ yyaccept = 4;
YYMARKER = ++YYCURSOR;
YYFILL(3);
yych = *YYCURSOR;
- YYDEBUG(104, *YYCURSOR);
- if (yybm[0+yych] & 128) {
- goto yy103;
+ YYDEBUG(106, *YYCURSOR);
+ if (yybm[0+yych] & 8) {
+ goto yy105;
}
- if (yych <= 0x1F) {
+ if (yych <= ' ') {
if (yych <= '\n') {
- if (yych <= 0x00) goto yy105;
- if (yych <= 0x08) goto yy39;
+ if (yych <= 0x00) goto yy107;
+ if (yych <= 0x08) goto yy42;
} else {
- if (yych != '\r') goto yy39;
+ if (yych == '\r') goto yy107;
+ if (yych <= 0x1F) goto yy42;
}
} else {
- if (yych <= '#') {
- if (yych <= ' ') goto yy105;
- if (yych <= '"') goto yy39;
+ if (yych <= '&') {
+ if (yych <= '!') goto yy42;
+ if (yych <= '"') goto yy62;
+ if (yych >= '$') goto yy42;
} else {
- if (yych == ':') goto yy62;
- goto yy39;
+ if (yych <= '\'') goto yy62;
+ if (yych <= '/') goto yy42;
+ if (yych <= ':') goto yy61;
+ goto yy42;
}
}
-yy105:
- YYDEBUG(105, *YYCURSOR);
+yy107:
+ YYDEBUG(107, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 112 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 148 "sapi/phpdbg/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, ADDR_PARAM);
yylval->addr = strtoul(yytext, 0, 16);
return T_ADDR;
}
-#line 989 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy106:
- YYDEBUG(106, *YYCURSOR);
- yyaccept = 0;
+#line 1104 "sapi/phpdbg/phpdbg_lexer.c"
+yy108:
+ YYDEBUG(108, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(4);
+ yych = *YYCURSOR;
+yy109:
+ YYDEBUG(109, *YYCURSOR);
+ if (yybm[0+yych] & 16) {
+ goto yy108;
+ }
+ if (yych <= '\n') {
+ if (yych <= 0x00) goto yy45;
+ if (yych >= '\n') goto yy45;
+ } else {
+ if (yych <= '#') goto yy110;
+ if (yych <= '\'') goto yy118;
+ if (yych <= ':') goto yy112;
+ goto yy113;
+ }
+yy110:
+ YYDEBUG(110, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+yy111:
+ YYDEBUG(111, *YYCURSOR);
+ if (yybm[0+yych] & 32) {
+ goto yy110;
+ }
+ if (yych <= '\n') goto yy45;
+ if (yych <= '\'') goto yy115;
+ goto yy116;
+yy112:
+ YYDEBUG(112, *YYCURSOR);
+ yych = *++YYCURSOR;
+ if (yych == '/') goto yy114;
+ goto yy111;
+yy113:
+ YYDEBUG(113, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(3);
+ yych = *YYCURSOR;
+ if (yych <= '"') {
+ if (yych <= '\f') {
+ if (yych <= 0x00) goto yy45;
+ if (yych <= 0x08) goto yy62;
+ if (yych <= '\n') goto yy45;
+ goto yy62;
+ } else {
+ if (yych <= '\r') goto yy45;
+ if (yych == ' ') goto yy45;
+ goto yy62;
+ }
+ } else {
+ if (yych <= '9') {
+ if (yych <= '#') goto yy45;
+ if (yych == '\'') goto yy108;
+ goto yy62;
+ } else {
+ if (yych <= ':') goto yy64;
+ if (yych == '\\') goto yy108;
+ goto yy62;
+ }
+ }
+yy114:
+ YYDEBUG(114, *YYCURSOR);
+ yych = *++YYCURSOR;
+ if (yych == '/') goto yy117;
+ goto yy111;
+yy115:
+ YYDEBUG(115, *YYCURSOR);
+ yych = *++YYCURSOR;
+ goto yy39;
+yy116:
+ YYDEBUG(116, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ if (yych == '\'') goto yy110;
+ if (yych == '\\') goto yy110;
+ goto yy45;
+yy117:
+ YYDEBUG(117, *YYCURSOR);
+ yyaccept = 5;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych <= 0x00) goto yy67;
+ if (yych == '\n') goto yy67;
+ goto yy111;
+yy118:
+ YYDEBUG(118, *YYCURSOR);
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych <= '\r') {
+ if (yych <= 0x08) {
+ if (yych <= 0x00) goto yy39;
+ goto yy63;
+ } else {
+ if (yych <= '\n') goto yy39;
+ if (yych <= '\f') goto yy63;
+ goto yy39;
+ }
+ } else {
+ if (yych <= ' ') {
+ if (yych <= 0x1F) goto yy63;
+ goto yy39;
+ } else {
+ if (yych == '#') goto yy39;
+ goto yy63;
+ }
+ }
+yy119:
+ YYDEBUG(119, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(4);
+ yych = *YYCURSOR;
+yy120:
+ YYDEBUG(120, *YYCURSOR);
+ if (yybm[0+yych] & 64) {
+ goto yy119;
+ }
+ if (yych <= ' ') {
+ if (yych <= 0x00) goto yy45;
+ if (yych == '\n') goto yy45;
+ } else {
+ if (yych <= '"') goto yy118;
+ if (yych <= '#') goto yy121;
+ if (yych <= ':') goto yy123;
+ goto yy124;
+ }
+yy121:
+ YYDEBUG(121, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+yy122:
+ YYDEBUG(122, *YYCURSOR);
+ if (yybm[0+yych] & 128) {
+ goto yy121;
+ }
+ if (yych <= '\n') goto yy45;
+ if (yych <= '"') goto yy115;
+ goto yy126;
+yy123:
+ YYDEBUG(123, *YYCURSOR);
+ yych = *++YYCURSOR;
+ if (yych == '/') goto yy125;
+ goto yy122;
+yy124:
+ YYDEBUG(124, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(3);
+ yych = *YYCURSOR;
+ if (yych <= ' ') {
+ if (yych <= '\n') {
+ if (yych <= 0x00) goto yy45;
+ if (yych <= 0x08) goto yy62;
+ goto yy45;
+ } else {
+ if (yych == '\r') goto yy45;
+ if (yych <= 0x1F) goto yy62;
+ goto yy45;
+ }
+ } else {
+ if (yych <= '9') {
+ if (yych <= '!') goto yy62;
+ if (yych <= '"') goto yy119;
+ if (yych <= '#') goto yy45;
+ goto yy62;
+ } else {
+ if (yych <= ':') goto yy64;
+ if (yych == '\\') goto yy119;
+ goto yy62;
+ }
+ }
+yy125:
+ YYDEBUG(125, *YYCURSOR);
+ yych = *++YYCURSOR;
+ if (yych == '/') goto yy127;
+ goto yy122;
+yy126:
+ YYDEBUG(126, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ if (yych == '"') goto yy121;
+ if (yych == '\\') goto yy121;
+ goto yy45;
+yy127:
+ YYDEBUG(127, *YYCURSOR);
+ yyaccept = 5;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych <= 0x00) goto yy67;
+ if (yych == '\n') goto yy67;
+ goto yy122;
+yy128:
+ YYDEBUG(128, *YYCURSOR);
+ ++YYCURSOR;
+ YYDEBUG(129, *YYCURSOR);
+ YYCURSOR = YYCTXMARKER;
+ yyleng = (size_t) YYCURSOR - (size_t) yytext;
+#line 119 "sapi/phpdbg/phpdbg_lexer.l"
+ {
+ return T_COLON;
+}
+#line 1309 "sapi/phpdbg/phpdbg_lexer.c"
+yy130:
+ YYDEBUG(130, *YYCURSOR);
+ ++YYCURSOR;
+ YYDEBUG(131, *YYCURSOR);
+ yyleng = (size_t) YYCURSOR - (size_t) yytext;
+#line 115 "sapi/phpdbg/phpdbg_lexer.l"
+ {
+ return T_DCOLON;
+}
+#line 1319 "sapi/phpdbg/phpdbg_lexer.c"
+yy132:
+ YYDEBUG(132, *YYCURSOR);
+ yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
if (yych <= '\f') {
- if (yych <= 0x08) goto yy40;
- if (yych >= '\v') goto yy40;
+ if (yych != '\t') goto yy43;
} else {
- if (yych <= '\r') goto yy107;
- if (yych != ' ') goto yy40;
+ if (yych <= '\r') goto yy133;
+ if (yych != ' ') goto yy43;
}
-yy107:
- YYDEBUG(107, *YYCURSOR);
+yy133:
+ YYDEBUG(133, *YYCURSOR);
++YYCURSOR;
YYFILL(1);
yych = *YYCURSOR;
- YYDEBUG(108, *YYCURSOR);
+ YYDEBUG(134, *YYCURSOR);
if (yych <= '\f') {
- if (yych <= 0x08) goto yy109;
- if (yych <= '\n') goto yy107;
+ if (yych == '\t') goto yy133;
} else {
- if (yych <= '\r') goto yy107;
- if (yych == ' ') goto yy107;
+ if (yych <= '\r') goto yy133;
+ if (yych == ' ') goto yy133;
}
-yy109:
- YYDEBUG(109, *YYCURSOR);
+ YYDEBUG(135, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 72 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 100 "sapi/phpdbg/phpdbg_lexer.l"
{
YYSETCONDITION(RAW);
phpdbg_init_param(yylval, EMPTY_PARAM);
return T_IF;
}
-#line 1023 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
+#line 1350 "sapi/phpdbg/phpdbg_lexer.c"
+yy136:
+ YYDEBUG(136, *YYCURSOR);
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych <= ' ') {
+ if (yych <= '\f') {
+ if (yych != '\t') goto yy43;
+ } else {
+ if (yych <= '\r') goto yy137;
+ if (yych <= 0x1F) goto yy43;
+ }
+ } else {
+ if (yych <= '.') {
+ if (yych <= ',') goto yy43;
+ if (yych <= '-') goto yy139;
+ goto yy140;
+ } else {
+ if (yych <= '/') goto yy43;
+ if (yych <= '9') goto yy140;
+ goto yy43;
+ }
+ }
+yy137:
+ YYDEBUG(137, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(2);
+ yych = *YYCURSOR;
+ YYDEBUG(138, *YYCURSOR);
+ if (yych <= ' ') {
+ if (yych <= '\f') {
+ if (yych == '\t') goto yy137;
+ goto yy45;
+ } else {
+ if (yych <= '\r') goto yy137;
+ if (yych <= 0x1F) goto yy45;
+ goto yy137;
+ }
+ } else {
+ if (yych <= '.') {
+ if (yych <= ',') goto yy45;
+ if (yych <= '-') goto yy143;
+ goto yy144;
+ } else {
+ if (yych <= '/') goto yy45;
+ if (yych <= '9') goto yy144;
+ goto yy45;
+ }
+ }
+yy139:
+ YYDEBUG(139, *YYCURSOR);
+ yyaccept = 1;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == '.') goto yy140;
+ if (yych <= '/') goto yy43;
+ if (yych >= ':') goto yy43;
+yy140:
+ YYDEBUG(140, *YYCURSOR);
+ yyaccept = 6;
+ YYMARKER = ++YYCURSOR;
+ YYFILL(3);
+ yych = *YYCURSOR;
+ YYDEBUG(141, *YYCURSOR);
+ if (yych <= '"') {
+ if (yych <= '\f') {
+ if (yych <= 0x00) goto yy142;
+ if (yych <= 0x08) goto yy42;
+ if (yych >= '\v') goto yy42;
+ } else {
+ if (yych <= 0x1F) {
+ if (yych >= 0x0E) goto yy42;
+ } else {
+ if (yych <= ' ') goto yy142;
+ if (yych <= '!') goto yy42;
+ goto yy62;
+ }
+ }
+ } else {
+ if (yych <= '-') {
+ if (yych <= '#') goto yy142;
+ if (yych == '\'') goto yy62;
+ goto yy42;
+ } else {
+ if (yych <= '/') {
+ if (yych <= '.') goto yy140;
+ goto yy42;
+ } else {
+ if (yych <= '9') goto yy140;
+ if (yych <= ':') goto yy61;
+ goto yy42;
+ }
+ }
+ }
+yy142:
+ YYDEBUG(142, *YYCURSOR);
+ yyleng = (size_t) YYCURSOR - (size_t) yytext;
+#line 93 "sapi/phpdbg/phpdbg_lexer.l"
+ {
+ char *text = yytext + 2;
+ while (*++text < '0');
+ yylval->num = atoi(text);
+ return T_REQ_ID;
+}
+#line 1453 "sapi/phpdbg/phpdbg_lexer.c"
+yy143:
+ YYDEBUG(143, *YYCURSOR);
+ yych = *++YYCURSOR;
+ if (yych == '.') goto yy144;
+ if (yych <= '/') goto yy45;
+ if (yych >= ':') goto yy45;
+yy144:
+ YYDEBUG(144, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ YYDEBUG(145, *YYCURSOR);
+ if (yych == '.') goto yy144;
+ if (yych <= '/') goto yy142;
+ if (yych <= '9') goto yy144;
+ goto yy142;
+yy146:
+ YYDEBUG(146, *YYCURSOR);
+ yych = *++YYCURSOR;
+ if (yych == '.') goto yy147;
+ if (yych <= '/') goto yy45;
+ if (yych >= ':') goto yy45;
+yy147:
+ YYDEBUG(147, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ YYDEBUG(148, *YYCURSOR);
+ if (yych == '.') goto yy147;
+ if (yych <= '/') goto yy149;
+ if (yych <= '9') goto yy147;
+yy149:
+ YYDEBUG(149, *YYCURSOR);
+ YYCURSOR = YYCTXMARKER;
+ yyleng = (size_t) YYCURSOR - (size_t) yytext;
+#line 106 "sapi/phpdbg/phpdbg_lexer.l"
+ {
+ return T_POUND;
+}
+#line 1493 "sapi/phpdbg/phpdbg_lexer.c"
}
/* *********************************** */
-yyc_RAW:
+yyc_PRE_RAW:
{
static const unsigned char yybm[] = {
- 0, 64, 64, 64, 64, 64, 64, 64,
- 64, 224, 128, 64, 64, 224, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 224, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
- 64, 64, 64, 64, 64, 64, 64, 64,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 64, 0, 0, 0, 64, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 64, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 128, 0,
+ 128, 128, 128, 128, 128, 128, 128, 128,
+ 128, 128, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0,
};
- YYDEBUG(110, *YYCURSOR);
+ YYDEBUG(150, *YYCURSOR);
YYFILL(2);
yych = *YYCURSOR;
- if (yybm[0+yych] & 32) {
- goto yy112;
+ if (yych <= '\r') {
+ if (yych <= '\t') {
+ if (yych <= 0x00) goto yy158;
+ if (yych <= 0x08) goto yy160;
+ } else {
+ if (yych <= '\n') goto yy158;
+ if (yych <= '\f') goto yy160;
+ }
+ } else {
+ if (yych <= '"') {
+ if (yych == ' ') goto yy154;
+ goto yy160;
+ } else {
+ if (yych <= '#') goto yy157;
+ if (yych == '-') goto yy159;
+ goto yy160;
+ }
}
- if (yych <= 0x00) goto yy117;
- if (yych == '\n') goto yy115;
- goto yy118;
-yy112:
- YYDEBUG(112, *YYCURSOR);
+ YYDEBUG(152, *YYCURSOR);
+ ++YYCURSOR;
+ if (yybm[0+(yych = *YYCURSOR)] & 64) {
+ goto yy154;
+ }
+yy153:
+ YYDEBUG(153, *YYCURSOR);
+ yyleng = (size_t) YYCURSOR - (size_t) yytext;
+#line 199 "sapi/phpdbg/phpdbg_lexer.l"
+ {
+ YYSETCONDITION(RAW);
+
+ YYCURSOR = LEX(text);
+ goto restart;
+}
+#line 1568 "sapi/phpdbg/phpdbg_lexer.c"
+yy154:
+ YYDEBUG(154, *YYCURSOR);
++YYCURSOR;
YYFILL(1);
yych = *YYCURSOR;
- YYDEBUG(113, *YYCURSOR);
- if (yybm[0+yych] & 32) {
- goto yy112;
+ YYDEBUG(155, *YYCURSOR);
+ if (yybm[0+yych] & 64) {
+ goto yy154;
}
- if (yych <= 0x00) goto yy114;
- if (yych == '\n') goto yy120;
- goto yy118;
-yy114:
- YYDEBUG(114, *YYCURSOR);
+ YYDEBUG(156, *YYCURSOR);
+ yyleng = (size_t) YYCURSOR - (size_t) yytext;
+#line 175 "sapi/phpdbg/phpdbg_lexer.l"
+ {
+ /* ignore whitespace */
+
+ goto restart;
+}
+#line 1586 "sapi/phpdbg/phpdbg_lexer.c"
+yy157:
+ YYDEBUG(157, *YYCURSOR);
+ yych = *++YYCURSOR;
+ goto yy153;
+yy158:
+ YYDEBUG(158, *YYCURSOR);
+ yych = *++YYCURSOR;
+ goto yy153;
+yy159:
+ YYDEBUG(159, *YYCURSOR);
+ yyaccept = 0;
+ yych = *(YYMARKER = ++YYCURSOR);
+ if (yych == 'r') goto yy161;
+ goto yy153;
+yy160:
+ YYDEBUG(160, *YYCURSOR);
+ yych = *++YYCURSOR;
+ goto yy153;
+yy161:
+ YYDEBUG(161, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(2);
+ yych = *YYCURSOR;
+ YYDEBUG(162, *YYCURSOR);
+ if (yybm[0+yych] & 128) {
+ goto yy165;
+ }
+ if (yych <= '\r') {
+ if (yych == '\t') goto yy161;
+ if (yych >= '\r') goto yy161;
+ } else {
+ if (yych <= ' ') {
+ if (yych >= ' ') goto yy161;
+ } else {
+ if (yych == '-') goto yy164;
+ }
+ }
+yy163:
+ YYDEBUG(163, *YYCURSOR);
+ YYCURSOR = YYMARKER;
+ goto yy153;
+yy164:
+ YYDEBUG(164, *YYCURSOR);
+ yych = *++YYCURSOR;
+ if (yybm[0+yych] & 128) {
+ goto yy165;
+ }
+ goto yy163;
+yy165:
+ YYDEBUG(165, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ YYDEBUG(166, *YYCURSOR);
+ if (yybm[0+yych] & 128) {
+ goto yy165;
+ }
+ YYDEBUG(167, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 132 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 93 "sapi/phpdbg/phpdbg_lexer.l"
+ {
+ char *text = yytext + 2;
+ while (*++text < '0');
+ yylval->num = atoi(text);
+ return T_REQ_ID;
+}
+#line 1653 "sapi/phpdbg/phpdbg_lexer.c"
+ }
+/* *********************************** */
+yyc_RAW:
+ {
+ static const unsigned char yybm[] = {
+ 0, 224, 224, 224, 224, 224, 224, 224,
+ 224, 240, 0, 224, 224, 240, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 240, 224, 64, 192, 224, 224, 224, 128,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 32, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ 224, 224, 224, 224, 224, 224, 224, 224,
+ };
+ YYDEBUG(168, *YYCURSOR);
+ YYFILL(1);
+ yych = *YYCURSOR;
+ if (yybm[0+yych] & 16) {
+ goto yy170;
+ }
+ if (yych <= '!') {
+ if (yych <= 0x00) goto yy175;
+ if (yych <= 0x08) goto yy177;
+ if (yych <= '\n') goto yy175;
+ goto yy177;
+ } else {
+ if (yych <= '#') {
+ if (yych <= '"') goto yy179;
+ goto yy173;
+ } else {
+ if (yych == '\'') goto yy181;
+ goto yy177;
+ }
+ }
+yy170:
+ YYDEBUG(170, *YYCURSOR);
+ yyaccept = 0;
+ YYMARKER = ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ YYDEBUG(171, *YYCURSOR);
+ if (yybm[0+yych] & 16) {
+ goto yy170;
+ }
+ if (yych <= '!') {
+ if (yych <= 0x00) goto yy172;
+ if (yych <= 0x08) goto yy177;
+ if (yych >= '\v') goto yy177;
+ } else {
+ if (yych <= '#') {
+ if (yych <= '"') goto yy179;
+ } else {
+ if (yych == '\'') goto yy181;
+ goto yy177;
+ }
+ }
+yy172:
+ YYDEBUG(172, *YYCURSOR);
+ yyleng = (size_t) YYCURSOR - (size_t) yytext;
+#line 168 "sapi/phpdbg/phpdbg_lexer.l"
{
phpdbg_init_param(yylval, STR_PARAM);
- yylval->str = zend_strndup(yytext, yyleng);
+ yylval->str = estrndup(yytext, yyleng - unescape_string(yytext));
yylval->len = yyleng;
return T_INPUT;
}
-#line 1093 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy115:
- YYDEBUG(115, *YYCURSOR);
+#line 1744 "sapi/phpdbg/phpdbg_lexer.c"
+yy173:
+ YYDEBUG(173, *YYCURSOR);
++YYCURSOR;
- if (yybm[0+(yych = *YYCURSOR)] & 128) {
- goto yy120;
- }
-yy116:
- YYDEBUG(116, *YYCURSOR);
+ YYDEBUG(174, *YYCURSOR);
yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 68 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 110 "sapi/phpdbg/phpdbg_lexer.l"
+ {
+ YYSETCONDITION(INITIAL);
+ return T_SEPARATOR;
+}
+#line 1755 "sapi/phpdbg/phpdbg_lexer.c"
+yy175:
+ YYDEBUG(175, *YYCURSOR);
+ ++YYCURSOR;
+ YYDEBUG(176, *YYCURSOR);
+ yyleng = (size_t) YYCURSOR - (size_t) yytext;
+#line 89 "sapi/phpdbg/phpdbg_lexer.l"
{
return 0;
}
-#line 1107 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
-yy117:
- YYDEBUG(117, *YYCURSOR);
- yych = *++YYCURSOR;
- goto yy116;
-yy118:
- YYDEBUG(118, *YYCURSOR);
+#line 1765 "sapi/phpdbg/phpdbg_lexer.c"
+yy177:
+ YYDEBUG(177, *YYCURSOR);
+ yyaccept = 0;
+ YYMARKER = ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ YYDEBUG(178, *YYCURSOR);
+ if (yybm[0+yych] & 32) {
+ goto yy177;
+ }
+ if (yych <= '\n') goto yy172;
+ if (yych <= '"') goto yy179;
+ if (yych <= '#') goto yy172;
+ goto yy181;
+yy179:
+ YYDEBUG(179, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ if (yybm[0+yych] & 128) {
+ goto yy185;
+ }
+ if (yych >= '#') goto yy187;
+yy180:
+ YYDEBUG(180, *YYCURSOR);
+ YYCURSOR = YYMARKER;
+ goto yy172;
+yy181:
+ YYDEBUG(181, *YYCURSOR);
++YYCURSOR;
YYFILL(1);
yych = *YYCURSOR;
- YYDEBUG(119, *YYCURSOR);
if (yybm[0+yych] & 64) {
- goto yy118;
+ goto yy182;
}
- goto yy114;
-yy120:
- YYDEBUG(120, *YYCURSOR);
+ if (yych <= '\'') goto yy180;
+ goto yy184;
+yy182:
+ YYDEBUG(182, *YYCURSOR);
++YYCURSOR;
YYFILL(1);
yych = *YYCURSOR;
- YYDEBUG(121, *YYCURSOR);
+ YYDEBUG(183, *YYCURSOR);
+ if (yybm[0+yych] & 64) {
+ goto yy182;
+ }
+ if (yych <= '\n') goto yy180;
+ if (yych <= '\'') goto yy177;
+yy184:
+ YYDEBUG(184, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ if (yych == '\'') goto yy182;
+ if (yych == '\\') goto yy182;
+ goto yy180;
+yy185:
+ YYDEBUG(185, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ YYDEBUG(186, *YYCURSOR);
if (yybm[0+yych] & 128) {
- goto yy120;
+ goto yy185;
}
- YYDEBUG(122, *YYCURSOR);
- yyleng = (size_t) YYCURSOR - (size_t) yytext;
-#line 139 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
- {
- /* ignore whitespace */
-
- goto restart;
-}
-#line 1139 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.c"
+ if (yych <= '\n') goto yy180;
+ if (yych <= '"') goto yy177;
+yy187:
+ YYDEBUG(187, *YYCURSOR);
+ ++YYCURSOR;
+ YYFILL(1);
+ yych = *YYCURSOR;
+ if (yych == '"') goto yy185;
+ if (yych == '\\') goto yy185;
+ goto yy180;
}
}
-#line 168 "/var/root/php-src/sapi/phpdbg/phpdbg_lexer.l"
+#line 213 "sapi/phpdbg/phpdbg_lexer.l"
}
diff --git a/sapi/phpdbg/phpdbg_lexer.h b/sapi/phpdbg/phpdbg_lexer.h
index d060e08fc3..f9b75b95bf 100644
--- a/sapi/phpdbg/phpdbg_lexer.h
+++ b/sapi/phpdbg/phpdbg_lexer.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -28,13 +28,14 @@ typedef struct {
unsigned char *text;
unsigned char *cursor;
unsigned char *marker;
+ unsigned char *ctxmarker;
int state;
} phpdbg_lexer_data;
#define yyparse phpdbg_parse
#define yylex phpdbg_lex
-void phpdbg_init_lexer (phpdbg_param_t *stack, char *input TSRMLS_DC);
+void phpdbg_init_lexer (phpdbg_param_t *stack, char *input);
int phpdbg_lex (phpdbg_param_t* yylval);
diff --git a/sapi/phpdbg/phpdbg_lexer.l b/sapi/phpdbg/phpdbg_lexer.l
index 7b3ce38c47..5d1c8b77ba 100644
--- a/sapi/phpdbg/phpdbg_lexer.l
+++ b/sapi/phpdbg/phpdbg_lexer.l
@@ -14,6 +14,7 @@
#define YYGETCONDITION() LEX(state)
#define YYCURSOR LEX(cursor)
#define YYMARKER LEX(marker)
+#define YYCTXMARKER LEX(ctxmarker)
#define yyleng LEX(len)
#define yytext ((char*) LEX(text))
#undef YYDEBUG
@@ -21,12 +22,13 @@
#define YYFILL(n)
#define NORMAL 0
-#define RAW 1
-#define INITIAL 2
+#define PRE_RAW 1
+#define RAW 2
+#define INITIAL 3
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-void phpdbg_init_lexer (phpdbg_param_t *stack, char *input TSRMLS_DC) {
+void phpdbg_init_lexer (phpdbg_param_t *stack, char *input) {
PHPDBG_G(parser_stack) = stack;
YYSETCONDITION(INITIAL);
@@ -35,8 +37,26 @@ void phpdbg_init_lexer (phpdbg_param_t *stack, char *input TSRMLS_DC) {
LEX(len) = strlen(input);
}
+static int unescape_string(char *s) {
+ switch (*s) {
+ case '\'':
+ case '\"': {
+ char start = *s;
+ size_t off = 1;
+ do {
+ if (s[off] == '\\') {
+ off++;
+ }
+ *s = s[off];
+ } while ((++s)[off] != start);
+ return off + 1;
+ }
+ }
+
+ return 0;
+}
+
int phpdbg_lex (phpdbg_param_t* yylval) {
- TSRMLS_FETCH(); /* Slow, but this is not a major problem here. TODO: Use TSRMLS_DC */
restart:
LEX(text) = YYCURSOR;
@@ -56,12 +76,13 @@ T_SHELL 'sh'
T_IF 'if'
T_RUN 'run'
T_RUN_SHORT "r"
-WS [ \r\n\t]+
+WS [ \r\t]+
DIGITS [-]?[0-9\.]+
ID [^ \r\n\t:#\000]+
+GENERIC_ID ([^ \r\n\t:#\000"']|":\\")+|["]([^\n\000"\\]|"\\\\"|"\\"["])+["]|[']([^\n\000'\\]|"\\\\"|"\\"['])+[']
ADDR [0][x][a-fA-F0-9]+
OPCODE (ZEND_|zend_)([A-Za-z])+
-INPUT [^\n\000]+
+INPUT ([^\n\000#"']|["]([^\n\000"\\]|"\\\\"|"\\"["])+["]|[']([^\n\000'\\]|"\\\\"|"\\"['])+['])+
<!*> := yyleng = (size_t) YYCURSOR - (size_t) yytext;
@@ -69,35 +90,50 @@ INPUT [^\n\000]+
return 0;
}
+<PRE_RAW, NORMAL>"-r"{WS}?{DIGITS} {
+ char *text = yytext + 2;
+ while (*++text < '0');
+ yylval->num = atoi(text);
+ return T_REQ_ID;
+}
+
<NORMAL>{T_IF}{WS} {
YYSETCONDITION(RAW);
phpdbg_init_param(yylval, EMPTY_PARAM);
return T_IF;
}
-<NORMAL>{ID}[:]{1}[//]{2} {
- phpdbg_init_param(yylval, STR_PARAM);
- yylval->str = zend_strndup(yytext, yyleng);
- yylval->len = yyleng;
- return T_PROTO;
-}
-<NORMAL>[#]{1} {
+<NORMAL>"#"/{DIGITS} {
return T_POUND;
}
-<NORMAL>[:]{2} {
+
+<*>"#" {
+ YYSETCONDITION(INITIAL);
+ return T_SEPARATOR;
+}
+
+<NORMAL>"::" {
return T_DCOLON;
}
-<NORMAL>[:]{1} {
+
+<NORMAL>":"/[^\\] {
return T_COLON;
}
-<NORMAL>({T_YES}|{T_ON}|{T_ENABLED}|{T_TRUE}){WS} {
+<NORMAL>{ID}"://" {
+ phpdbg_init_param(yylval, STR_PARAM);
+ yylval->str = estrndup(yytext, yyleng);
+ yylval->len = yyleng;
+ return T_PROTO;
+}
+
+<NORMAL>({T_YES}|{T_ON}|{T_ENABLED}|{T_TRUE})/[ \r\t\n\000] {
phpdbg_init_param(yylval, NUMERIC_PARAM);
- yylval->num = 1;
+ yylval->num = 1;
return T_TRUTHY;
}
-<NORMAL>({T_NO}|{T_OFF}|{T_DISABLED}|{T_FALSE}){WS} {
+<NORMAL>({T_NO}|{T_OFF}|{T_DISABLED}|{T_FALSE})/[ \r\t\n\000] {
phpdbg_init_param(yylval, NUMERIC_PARAM);
yylval->num = 0;
return T_FALSY;
@@ -117,21 +153,21 @@ INPUT [^\n\000]+
<NORMAL>{OPCODE} {
phpdbg_init_param(yylval, OP_PARAM);
- yylval->str = zend_strndup(yytext, yyleng);
+ yylval->str = estrndup(yytext, yyleng);
yylval->len = yyleng;
return T_OPCODE;
}
-<NORMAL>{ID} {
+<NORMAL>{GENERIC_ID} {
phpdbg_init_param(yylval, STR_PARAM);
- yylval->str = zend_strndup(yytext, yyleng);
+ yylval->str = estrndup(yytext, yyleng - unescape_string(yytext));
yylval->len = yyleng;
- return T_ID;
+ return T_ID;
}
<RAW>{INPUT} {
phpdbg_init_param(yylval, STR_PARAM);
- yylval->str = zend_strndup(yytext, yyleng);
+ yylval->str = estrndup(yytext, yyleng - unescape_string(yytext));
yylval->len = yyleng;
return T_INPUT;
}
@@ -143,22 +179,31 @@ INPUT [^\n\000]+
}
<INITIAL>{T_EVAL}{WS} {
- YYSETCONDITION(RAW);
+ YYSETCONDITION(PRE_RAW);
phpdbg_init_param(yylval, EMPTY_PARAM);
return T_EVAL;
}
+
<INITIAL>{T_SHELL}{WS} {
- YYSETCONDITION(RAW);
+ YYSETCONDITION(PRE_RAW);
phpdbg_init_param(yylval, EMPTY_PARAM);
return T_SHELL;
}
+
<INITIAL>({T_RUN}|{T_RUN_SHORT}){WS} {
- YYSETCONDITION(RAW);
+ YYSETCONDITION(PRE_RAW);
phpdbg_init_param(yylval, EMPTY_PARAM);
return T_RUN;
}
-<INITIAL>. {
+<PRE_RAW>[^ ] {
+ YYSETCONDITION(RAW);
+
+ YYCURSOR = LEX(text);
+ goto restart;
+}
+
+<INITIAL>[^ ] {
YYSETCONDITION(NORMAL);
YYCURSOR = LEX(text);
diff --git a/sapi/phpdbg/phpdbg_list.c b/sapi/phpdbg/phpdbg_list.c
index 0709b58ff3..5a4ca21583 100644
--- a/sapi/phpdbg/phpdbg_list.c
+++ b/sapi/phpdbg/phpdbg_list.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -31,38 +31,41 @@
#include "phpdbg_utils.h"
#include "phpdbg_prompt.h"
#include "php_streams.h"
+#include "zend_exceptions.h"
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-#define PHPDBG_LIST_COMMAND_D(f, h, a, m, l, s) \
- PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[13])
+#define PHPDBG_LIST_COMMAND_D(f, h, a, m, l, s, flags) \
+ PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[12], flags)
const phpdbg_command_t phpdbg_list_commands[] = {
- PHPDBG_LIST_COMMAND_D(lines, "lists the specified lines", 'l', list_lines, NULL, "l"),
- PHPDBG_LIST_COMMAND_D(class, "lists the specified class", 'c', list_class, NULL, "s"),
- PHPDBG_LIST_COMMAND_D(method, "lists the specified method", 'm', list_method, NULL, "m"),
- PHPDBG_LIST_COMMAND_D(func, "lists the specified function", 'f', list_func, NULL, "s"),
+ PHPDBG_LIST_COMMAND_D(lines, "lists the specified lines", 'l', list_lines, NULL, "l", PHPDBG_ASYNC_SAFE),
+ PHPDBG_LIST_COMMAND_D(class, "lists the specified class", 'c', list_class, NULL, "s", PHPDBG_ASYNC_SAFE),
+ PHPDBG_LIST_COMMAND_D(method, "lists the specified method", 'm', list_method, NULL, "m", PHPDBG_ASYNC_SAFE),
+ PHPDBG_LIST_COMMAND_D(func, "lists the specified function", 'f', list_func, NULL, "s", PHPDBG_ASYNC_SAFE),
PHPDBG_END_COMMAND
};
PHPDBG_LIST(lines) /* {{{ */
{
- if (!PHPDBG_G(exec) && !zend_is_executing(TSRMLS_C)) {
- phpdbg_error("Not executing, and execution context not set");
+ if (!PHPDBG_G(exec) && !zend_is_executing()) {
+ phpdbg_error("inactive", "type=\"execution\"", "Not executing, and execution context not set");
return SUCCESS;
}
switch (param->type) {
- case NUMERIC_PARAM:
- phpdbg_list_file(phpdbg_current_file(TSRMLS_C),
- (param->num < 0 ? 1 - param->num : param->num),
- (param->num < 0 ? param->num : 0) + zend_get_executed_lineno(TSRMLS_C),
- 0 TSRMLS_CC);
- break;
-
- case FILE_PARAM:
- phpdbg_list_file(param->file.name, param->file.line, 0, 0 TSRMLS_CC);
- break;
+ case NUMERIC_PARAM: {
+ const char *char_file = phpdbg_current_file();
+ zend_string *file = zend_string_init(char_file, strlen(char_file), 0);
+ phpdbg_list_file(file, param->num < 0 ? 1 - param->num : param->num, (param->num < 0 ? param->num : 0) + zend_get_executed_lineno(), 0);
+ efree(file);
+ } break;
+
+ case FILE_PARAM: {
+ zend_string *file = zend_string_init(param->file.name, strlen(param->file.name), 0);
+ phpdbg_list_file(file, param->file.line, 0, 0);
+ efree(file);
+ } break;
phpdbg_default_switch_case();
}
@@ -72,28 +75,28 @@ PHPDBG_LIST(lines) /* {{{ */
PHPDBG_LIST(func) /* {{{ */
{
- phpdbg_list_function_byname(param->str, param->len TSRMLS_CC);
+ phpdbg_list_function_byname(param->str, param->len);
return SUCCESS;
} /* }}} */
PHPDBG_LIST(method) /* {{{ */
{
- zend_class_entry **ce;
+ zend_class_entry *ce;
- if (zend_lookup_class(param->method.class, strlen(param->method.class), &ce TSRMLS_CC) == SUCCESS) {
+ if (phpdbg_safe_class_lookup(param->method.class, strlen(param->method.class), &ce) == SUCCESS) {
zend_function *function;
char *lcname = zend_str_tolower_dup(param->method.name, strlen(param->method.name));
- if (zend_hash_find(&(*ce)->function_table, lcname, strlen(lcname)+1, (void**) &function) == SUCCESS) {
- phpdbg_list_function(function TSRMLS_CC);
+ if ((function = zend_hash_str_find_ptr(&ce->function_table, lcname, strlen(lcname)))) {
+ phpdbg_list_function(function);
} else {
- phpdbg_error("Could not find %s::%s", param->method.class, param->method.name);
+ phpdbg_error("list", "type=\"notfound\" method=\"%s::%s\"", "Could not find %s::%s", param->method.class, param->method.name);
}
efree(lcname);
} else {
- phpdbg_error("Could not find the class %s", param->method.class);
+ phpdbg_error("list", "type=\"notfound\" class=\"%s\"", "Could not find the class %s", param->method.class);
}
return SUCCESS;
@@ -101,100 +104,94 @@ PHPDBG_LIST(method) /* {{{ */
PHPDBG_LIST(class) /* {{{ */
{
- zend_class_entry **ce;
-
- if (zend_lookup_class(param->str, param->len, &ce TSRMLS_CC) == SUCCESS) {
- if ((*ce)->type == ZEND_USER_CLASS) {
- if ((*ce)->info.user.filename) {
- phpdbg_list_file(
- (*ce)->info.user.filename,
- (*ce)->info.user.line_end - (*ce)->info.user.line_start + 1,
- (*ce)->info.user.line_start, 0 TSRMLS_CC
- );
+ zend_class_entry *ce;
+
+ if (phpdbg_safe_class_lookup(param->str, param->len, &ce) == SUCCESS) {
+ if (ce->type == ZEND_USER_CLASS) {
+ if (ce->info.user.filename) {
+ phpdbg_list_file(ce->info.user.filename, ce->info.user.line_end - ce->info.user.line_start + 1, ce->info.user.line_start, 0);
} else {
- phpdbg_error("The source of the requested class (%s) cannot be found", (*ce)->name);
+ phpdbg_error("list", "type=\"nosource\" class=\"%s\"", "The source of the requested class (%s) cannot be found", ZSTR_VAL(ce->name));
}
} else {
- phpdbg_error("The class requested (%s) is not user defined", (*ce)->name);
+ phpdbg_error("list", "type=\"internalclass\" class=\"%s\"", "The class requested (%s) is not user defined", ZSTR_VAL(ce->name));
}
} else {
- phpdbg_error("The requested class (%s) could not be found", param->str);
+ phpdbg_error("list", "type=\"notfound\" class=\"%s\"", "The requested class (%s) could not be found", param->str);
}
return SUCCESS;
} /* }}} */
-void phpdbg_list_file(const char *filename, long count, long offset, int highlight TSRMLS_DC) /* {{{ */
+void phpdbg_list_file(zend_string *filename, uint count, int offset, uint highlight) /* {{{ */
{
- struct stat st;
- char *opened = NULL;
- char buffer[8096] = {0,};
- long line = 0;
-
- php_stream *stream = NULL;
-
- if (VCWD_STAT(filename, &st) == FAILURE) {
- phpdbg_error("Failed to stat file %s", filename);
- return;
+ uint line, lastline;
+ phpdbg_file_source *data;
+ char resolved_path_buf[MAXPATHLEN];
+ const char *abspath;
+
+ if (VCWD_REALPATH(ZSTR_VAL(filename), resolved_path_buf)) {
+ abspath = resolved_path_buf;
+ } else {
+ abspath = ZSTR_VAL(filename);
}
- stream = php_stream_open_wrapper(filename, "rb", USE_PATH, &opened);
-
- if (!stream) {
- phpdbg_error("Failed to open file %s to list", filename);
+ if (!(data = zend_hash_str_find_ptr(&PHPDBG_G(file_sources), abspath, strlen(abspath)))) {
+ phpdbg_error("list", "type=\"unknownfile\"", "Could not find information about included file...");
return;
}
-
+
if (offset < 0) {
count += offset;
offset = 0;
}
-
- while (php_stream_gets(stream, buffer, sizeof(buffer)) != NULL) {
- long linelen = strlen(buffer);
- ++line;
-
- if (offset <= line) {
- if (!highlight) {
- phpdbg_write("%05ld: %s", line, buffer);
- } else {
- if (highlight != line) {
- phpdbg_write(" %05ld: %s", line, buffer);
- } else {
- phpdbg_write(">%05ld: %s", line, buffer);
- }
- }
+ lastline = offset + count;
+
+ if (lastline > data->lines) {
+ lastline = data->lines;
+ }
+
+ phpdbg_xml("<list %r file=\"%s\">", ZSTR_VAL(filename));
- if (buffer[linelen - 1] != '\n') {
- phpdbg_write("\n");
+ for (line = offset; line < lastline;) {
+ uint linestart = data->line[line++];
+ uint linelen = data->line[line] - linestart;
+ char *buffer = data->buf + linestart;
+
+ if (!highlight) {
+ phpdbg_write("line", "line=\"%u\" code=\"%.*s\"", " %05u: %.*s", line, linelen, buffer);
+ } else {
+ if (highlight != line) {
+ phpdbg_write("line", "line=\"%u\" code=\"%.*s\"", " %05u: %.*s", line, linelen, buffer);
+ } else {
+ phpdbg_write("line", "line=\"%u\" code=\"%.*s\" current=\"current\"", ">%05u: %.*s", line, linelen, buffer);
}
}
- if (count > 0 && count + offset - 1 < line) {
- break;
+ if (*(buffer + linelen - 1) != '\n' || !linelen) {
+ phpdbg_out("\n");
}
}
-
- php_stream_close(stream);
+
+ phpdbg_xml("</list>");
} /* }}} */
-void phpdbg_list_function(const zend_function *fbc TSRMLS_DC) /* {{{ */
+void phpdbg_list_function(const zend_function *fbc) /* {{{ */
{
const zend_op_array *ops;
if (fbc->type != ZEND_USER_FUNCTION) {
- phpdbg_error("The function requested (%s) is not user defined", fbc->common.function_name);
+ phpdbg_error("list", "type=\"internalfunction\" function=\"%s\"", "The function requested (%s) is not user defined", ZSTR_VAL(fbc->common.function_name));
return;
}
- ops = (zend_op_array*)fbc;
+ ops = (zend_op_array *) fbc;
- phpdbg_list_file(ops->filename,
- ops->line_end - ops->line_start + 1, ops->line_start, 0 TSRMLS_CC);
+ phpdbg_list_file(ops->filename, ops->line_end - ops->line_start + 1, ops->line_start, 0);
} /* }}} */
-void phpdbg_list_function_byname(const char *str, size_t len TSRMLS_DC) /* {{{ */
+void phpdbg_list_function_byname(const char *str, size_t len) /* {{{ */
{
HashTable *func_table = EG(function_table);
zend_function* fbc;
@@ -209,11 +206,11 @@ void phpdbg_list_function_byname(const char *str, size_t len TSRMLS_DC) /* {{{ *
func_table = &EG(scope)->function_table;
} else {
- phpdbg_error("No active class");
+ phpdbg_error("inactive", "type=\"noclasses\"", "No active class");
return;
}
} else if (!EG(function_table)) {
- phpdbg_error("No function table loaded");
+ phpdbg_error("inactive", "type=\"function_table\"", "No function table loaded");
return;
} else {
func_table = EG(function_table);
@@ -222,12 +219,174 @@ void phpdbg_list_function_byname(const char *str, size_t len TSRMLS_DC) /* {{{ *
/* use lowercase names, case insensitive */
func_name = zend_str_tolower_dup(func_name, func_name_len);
- if (zend_hash_find(func_table, func_name, func_name_len+1, (void**)&fbc) == SUCCESS) {
- phpdbg_list_function(fbc TSRMLS_CC);
- } else {
- phpdbg_error("Function %s not found", func_name);
- }
+ phpdbg_try_access {
+ if ((fbc = zend_hash_str_find_ptr(func_table, func_name, func_name_len))) {
+ phpdbg_list_function(fbc);
+ } else {
+ phpdbg_error("list", "type=\"nofunction\" function=\"%s\"", "Function %s not found", func_name);
+ }
+ } phpdbg_catch_access {
+ phpdbg_error("signalsegv", "function=\"%s\"", "Could not list function %s, invalid data source", func_name);
+ } phpdbg_end_try_access();
efree(func_name);
} /* }}} */
+zend_op_array *phpdbg_compile_file(zend_file_handle *file, int type) {
+ phpdbg_file_source data, *dataptr;
+ zend_file_handle fake;
+ zend_op_array *ret;
+ char *filename = (char *)(file->opened_path ? ZSTR_VAL(file->opened_path) : file->filename);
+ uint line;
+ char *bufptr, *endptr;
+ char resolved_path_buf[MAXPATHLEN];
+
+ if (zend_stream_fixup(file, &bufptr, &data.len) == FAILURE) {
+ return NULL;
+ }
+
+ data.buf = emalloc(data.len + ZEND_MMAP_AHEAD + 1);
+ if (data.len > 0) {
+ memcpy(data.buf, bufptr, data.len);
+ }
+ memset(data.buf + data.len, 0, ZEND_MMAP_AHEAD + 1);
+ data.filename = filename;
+ data.line[0] = 0;
+
+ memset(&fake, 0, sizeof(fake));
+ fake.type = ZEND_HANDLE_MAPPED;
+ fake.handle.stream.mmap.buf = data.buf;
+ fake.handle.stream.mmap.len = data.len;
+ fake.free_filename = 0;
+ fake.filename = filename;
+ fake.opened_path = file->opened_path;
+
+ *(dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint) * data.len)) = data;
+ if (VCWD_REALPATH(filename, resolved_path_buf)) {
+ filename = resolved_path_buf;
+ }
+
+ for (line = 0, bufptr = data.buf - 1, endptr = data.buf + data.len; ++bufptr < endptr;) {
+ if (*bufptr == '\n') {
+ dataptr->line[++line] = (uint)(bufptr - data.buf) + 1;
+ }
+ }
+ dataptr->lines = ++line;
+ dataptr->line[line] = endptr - data.buf;
+
+ ret = PHPDBG_G(compile_file)(&fake, type);
+
+ if (ret == NULL) {
+ efree(data.buf);
+ efree(dataptr);
+ return NULL;
+ }
+
+ dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line);
+ zend_hash_str_add_ptr(&PHPDBG_G(file_sources), filename, strlen(filename), dataptr);
+ phpdbg_resolve_pending_file_break(filename);
+
+ fake.opened_path = NULL;
+ zend_file_handle_dtor(&fake);
+
+ return ret;
+}
+
+zend_op_array *phpdbg_init_compile_file(zend_file_handle *file, int type) {
+ char *filename = (char *)(file->opened_path ? ZSTR_VAL(file->opened_path) : file->filename);
+ char resolved_path_buf[MAXPATHLEN];
+ zend_op_array *op_array;
+ phpdbg_file_source *dataptr;
+
+ if (VCWD_REALPATH(filename, resolved_path_buf)) {
+ filename = resolved_path_buf;
+ }
+
+ op_array = PHPDBG_G(init_compile_file)(file, type);
+
+ if (op_array == NULL) {
+ return NULL;
+ }
+
+ dataptr = zend_hash_str_find_ptr(&PHPDBG_G(file_sources), filename, strlen(filename));
+ ZEND_ASSERT(dataptr != NULL);
+
+ dataptr->op_array = *op_array;
+ if (dataptr->op_array.refcount) {
+ ++*dataptr->op_array.refcount;
+ }
+
+ return op_array;
+}
+
+zend_op_array *phpdbg_compile_string(zval *source_string, char *filename) {
+ zend_string *fake_name;
+ zend_op_array *op_array;
+ phpdbg_file_source *dataptr;
+ uint line;
+ char *bufptr, *endptr;
+
+ if (PHPDBG_G(flags) & PHPDBG_IN_EVAL) {
+ return PHPDBG_G(compile_string)(source_string, filename);
+ }
+
+ dataptr = emalloc(sizeof(phpdbg_file_source) + sizeof(uint) * Z_STRLEN_P(source_string));
+ dataptr->buf = estrndup(Z_STRVAL_P(source_string), Z_STRLEN_P(source_string));
+ dataptr->len = Z_STRLEN_P(source_string);
+ dataptr->line[0] = 0;
+ for (line = 0, bufptr = dataptr->buf - 1, endptr = dataptr->buf + dataptr->len; ++bufptr < endptr;) {
+ if (*bufptr == '\n') {
+ dataptr->line[++line] = (uint)(bufptr - dataptr->buf) + 1;
+ }
+ }
+ dataptr->lines = ++line;
+ dataptr->line[line] = endptr - dataptr->buf;
+
+ op_array = PHPDBG_G(compile_string)(source_string, filename);
+
+ if (op_array == NULL) {
+ efree(dataptr->buf);
+ efree(dataptr);
+ return NULL;
+ }
+
+ fake_name = strpprintf(0, "%s\0%p", filename, op_array->opcodes);
+
+ dataptr = erealloc(dataptr, sizeof(phpdbg_file_source) + sizeof(uint) * line);
+ zend_hash_add_ptr(&PHPDBG_G(file_sources), fake_name, dataptr);
+
+ dataptr->filename = estrndup(ZSTR_VAL(fake_name), ZSTR_LEN(fake_name));
+ zend_string_release(fake_name);
+
+ dataptr->op_array = *op_array;
+ if (dataptr->op_array.refcount) {
+ ++*dataptr->op_array.refcount;
+ }
+
+ return op_array;
+}
+
+void phpdbg_free_file_source(zval *zv) {
+ phpdbg_file_source *data = Z_PTR_P(zv);
+
+ if (data->buf) {
+ efree(data->buf);
+ }
+
+ destroy_op_array(&data->op_array);
+
+ efree(data);
+}
+
+void phpdbg_init_list(void) {
+ PHPDBG_G(compile_file) = zend_compile_file;
+ PHPDBG_G(compile_string) = zend_compile_string;
+ zend_hash_init(&PHPDBG_G(file_sources), 1, NULL, (dtor_func_t) phpdbg_free_file_source, 0);
+ zend_compile_file = phpdbg_compile_file;
+ zend_compile_string = phpdbg_compile_string;
+}
+
+void phpdbg_list_update(void) {
+ PHPDBG_G(init_compile_file) = zend_compile_file;
+ zend_compile_file = phpdbg_init_compile_file;
+}
diff --git a/sapi/phpdbg/phpdbg_list.h b/sapi/phpdbg/phpdbg_list.h
index 1530a8bbba..04a30e984c 100644
--- a/sapi/phpdbg/phpdbg_list.h
+++ b/sapi/phpdbg/phpdbg_list.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -32,10 +32,26 @@ PHPDBG_LIST(class);
PHPDBG_LIST(method);
PHPDBG_LIST(func);
-void phpdbg_list_function_byname(const char *, size_t TSRMLS_DC);
-void phpdbg_list_function(const zend_function* TSRMLS_DC);
-void phpdbg_list_file(const char*, long, long, int TSRMLS_DC);
+void phpdbg_list_function_byname(const char *, size_t);
+void phpdbg_list_function(const zend_function *);
+void phpdbg_list_file(zend_string *, uint, int, uint);
extern const phpdbg_command_t phpdbg_list_commands[];
+void phpdbg_init_list(void);
+void phpdbg_list_update(void);
+
+typedef struct {
+ char *filename;
+ char *buf;
+ size_t len;
+#if HAVE_MMAP
+ void *map;
+#endif
+ zend_op_array op_array;
+ zend_bool destroy_op_array;
+ uint lines;
+ uint line[1];
+} phpdbg_file_source;
+
#endif /* PHPDBG_LIST_H */
diff --git a/sapi/phpdbg/phpdbg_opcode.c b/sapi/phpdbg/phpdbg_opcode.c
index 1229b7e3a8..44170c8c9e 100644
--- a/sapi/phpdbg/phpdbg_opcode.c
+++ b/sapi/phpdbg/phpdbg_opcode.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -23,124 +23,153 @@
#include "zend_compile.h"
#include "phpdbg_opcode.h"
#include "phpdbg_utils.h"
+#include "ext/standard/php_string.h"
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-static inline zend_uint phpdbg_decode_literal(zend_op_array *ops, zend_literal *literal TSRMLS_DC) /* {{{ */
+static inline const char *phpdbg_decode_opcode(zend_uchar opcode) /* {{{ */
{
- int iter = 0;
-
- while (iter < ops->last_literal) {
- if (literal == &ops->literals[iter]) {
- return iter;
- }
- iter++;
+ const char *ret = zend_get_opcode_name(opcode);
+ if (ret) {
+ return ret + 5; /* Skip ZEND_ prefix */
}
-
- return 0;
+ return "UNKNOWN";
} /* }}} */
-static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, zend_uint type, HashTable *vars TSRMLS_DC) /* {{{ */
+static inline char *phpdbg_decode_op(zend_op_array *ops, znode_op *op, uint32_t type) /* {{{ */
{
char *decode = NULL;
- switch (type &~ EXT_TYPE_UNUSED) {
- case IS_CV:
- asprintf(&decode, "$%s", ops->vars[op->var].name);
- break;
-
- case IS_VAR:
- case IS_TMP_VAR: {
- zend_ulong id = 0, *pid = NULL;
- if (vars != NULL) {
- if (zend_hash_index_find(vars, (zend_ulong) ops->vars - op->var, (void**) &pid) != SUCCESS) {
- id = zend_hash_num_elements(vars);
- zend_hash_index_update(
- vars, (zend_ulong) ops->vars - op->var,
- (void**) &id,
- sizeof(zend_ulong), NULL);
- } else id = *pid;
- }
- asprintf(&decode, "@%lu", id);
+ switch (type) {
+ case IS_CV: {
+ zend_string *var = ops->vars[EX_VAR_TO_NUM(op->var)];
+ spprintf(&decode, 0, "$%.*s%c",
+ ZSTR_LEN(var) <= 19 ? (int) ZSTR_LEN(var) : 18,
+ ZSTR_VAL(var), ZSTR_LEN(var) <= 19 ? 0 : '+');
} break;
- case IS_CONST:
- asprintf(&decode, "C%u", phpdbg_decode_literal(ops, op->literal TSRMLS_CC));
+ case IS_VAR:
+ spprintf(&decode, 0, "@%td", EX_VAR_TO_NUM(op->var) - ops->last_var);
break;
-
- case IS_UNUSED:
- asprintf(&decode, "<unused>");
+ case IS_TMP_VAR:
+ spprintf(&decode, 0, "~%td", EX_VAR_TO_NUM(op->var) - ops->last_var);
break;
+ case IS_CONST: {
+ zval *literal = RT_CONSTANT(ops, *op);
+ decode = phpdbg_short_zval_print(literal, 20);
+ } break;
}
return decode;
} /* }}} */
-char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRMLS_DC) /*{{{ */
+char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op) /*{{{ */
{
- char *decode[4] = {NULL, NULL, NULL, NULL};
+ const char *opcode_name = phpdbg_decode_opcode(op->opcode);
+ char *result, *decode[4] = {NULL, NULL, NULL, NULL};
+ /* EX */
+ switch (op->opcode) {
+ case ZEND_FAST_CALL:
+ if (op->extended_value == ZEND_FAST_CALL_FROM_FINALLY) {
+ decode[0] = estrdup("FAST_CALL<FROM_FINALLY>");
+ }
+ break;
+ case ZEND_FAST_RET:
+ if (op->extended_value != 0) {
+ spprintf(&decode[0], 0, "FAST_RET<%s>",
+ op->extended_value == ZEND_FAST_RET_TO_CATCH ? "TO_CATCH" : "TO_FINALLY");
+ }
+ break;
+ }
+
+ /* OP1 */
switch (op->opcode) {
case ZEND_JMP:
-#ifdef ZEND_GOTO
- case ZEND_GOTO:
-#endif
-#ifdef ZEND_FAST_CALL
case ZEND_FAST_CALL:
-#endif
- asprintf(&decode[1], "J%ld", op->op1.jmp_addr - ops->opcodes);
- goto format;
+ spprintf(&decode[1], 0, "J%td", OP_JMP_ADDR(op, op->op1) - ops->opcodes);
+ break;
+
+ case ZEND_INIT_FCALL:
+ case ZEND_RECV:
+ case ZEND_RECV_INIT:
+ case ZEND_RECV_VARIADIC:
+ spprintf(&decode[1], 0, "%" PRIu32, op->op1.num);
+ break;
+
+ default:
+ decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type);
+ break;
+ }
+ /* OP2 */
+ switch (op->opcode) {
case ZEND_JMPZNZ:
- decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
- asprintf(
- &decode[2], "J%u or J%lu", op->op2.opline_num, op->extended_value);
- goto result;
+ spprintf(&decode[2], 0, "J%td or J%td",
+ OP_JMP_ADDR(op, op->op2) - ops->opcodes,
+ ZEND_OFFSET_TO_OPLINE(op, op->extended_value) - ops->opcodes);
+ break;
case ZEND_JMPZ:
case ZEND_JMPNZ:
case ZEND_JMPZ_EX:
case ZEND_JMPNZ_EX:
-
-#ifdef ZEND_JMP_SET
case ZEND_JMP_SET:
-#endif
-#ifdef ZEND_JMP_SET_VAR
- case ZEND_JMP_SET_VAR:
-#endif
- decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
- asprintf(
- &decode[2], "J%ld", op->op2.jmp_addr - ops->opcodes);
- goto result;
-
- case ZEND_RECV_INIT:
- goto result;
+ case ZEND_ASSERT_CHECK:
+ spprintf(&decode[2], 0, "J%td", OP_JMP_ADDR(op, op->op2) - ops->opcodes);
+ break;
- default: {
- decode[1] = phpdbg_decode_op(ops, &op->op1, op->op1_type, vars TSRMLS_CC);
- decode[2] = phpdbg_decode_op(ops, &op->op2, op->op2_type, vars TSRMLS_CC);
-result:
- decode[3] = phpdbg_decode_op(ops, &op->result, op->result_type, vars TSRMLS_CC);
-format:
- asprintf(
- &decode[0],
- "%-20s %-20s %-20s",
- decode[1] ? decode[1] : "",
- decode[2] ? decode[2] : "",
- decode[3] ? decode[3] : "");
+ case ZEND_FAST_CALL:
+ case ZEND_FAST_RET:
+ if (op->extended_value != 0) {
+ spprintf(&decode[2], 0, "J%" PRIu32, op->op2.opline_num);
}
+ break;
+
+ case ZEND_SEND_VAL:
+ case ZEND_SEND_VAL_EX:
+ case ZEND_SEND_VAR:
+ case ZEND_SEND_VAR_NO_REF:
+ case ZEND_SEND_REF:
+ case ZEND_SEND_VAR_EX:
+ case ZEND_SEND_USER:
+ spprintf(&decode[2], 0, "%" PRIu32, op->op2.num);
+ break;
+
+ default:
+ decode[2] = phpdbg_decode_op(ops, &op->op2, op->op2_type);
+ break;
}
+ /* RESULT */
+ switch (op->opcode) {
+ case ZEND_CATCH:
+ spprintf(&decode[3], 0, "%" PRIu32, op->result.num);
+ break;
+ default:
+ decode[3] = phpdbg_decode_op(ops, &op->result, op->result_type);
+ break;
+ }
+
+ spprintf(&result, 0,
+ "%-23s %-20s %-20s %-20s",
+ decode[0] ? decode[0] : opcode_name,
+ decode[1] ? decode[1] : "",
+ decode[2] ? decode[2] : "",
+ decode[3] ? decode[3] : "");
+
+ if (decode[0])
+ efree(decode[0]);
if (decode[1])
- free(decode[1]);
+ efree(decode[1]);
if (decode[2])
- free(decode[2]);
+ efree(decode[2]);
if (decode[3])
- free(decode[3]);
+ efree(decode[3]);
- return decode[0];
+ return result;
} /* }}} */
-void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, zend_bool ignore_flags TSRMLS_DC) /* {{{ */
+void phpdbg_print_opline_ex(zend_execute_data *execute_data, zend_bool ignore_flags) /* {{{ */
{
/* force out a line while stepping so the user knows what is happening */
if (ignore_flags ||
@@ -148,221 +177,44 @@ void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, ze
(PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ||
(PHPDBG_G(oplog)))) {
- zend_op *opline = execute_data->opline;
- char *decode = phpdbg_decode_opline(execute_data->op_array, opline, vars TSRMLS_CC);
+ zend_op *opline = (zend_op *) execute_data->opline;
+ char *decode = phpdbg_decode_opline(&execute_data->func->op_array, opline);
if (ignore_flags || (!(PHPDBG_G(flags) & PHPDBG_IS_QUIET) || (PHPDBG_G(flags) & PHPDBG_IS_STEPPING))) {
/* output line info */
- phpdbg_notice("L%-5u %16p %-30s %s %s",
+ phpdbg_notice("opline", "line=\"%u\" opline=\"%p\" op=\"%s\" file=\"%s\"", "L%-5u %16p %s %s",
opline->lineno,
opline,
- phpdbg_decode_opcode(opline->opcode),
decode,
- execute_data->op_array->filename ? execute_data->op_array->filename : "unknown");
+ execute_data->func->op_array.filename ? ZSTR_VAL(execute_data->func->op_array.filename) : "unknown");
}
if (!ignore_flags && PHPDBG_G(oplog)) {
- phpdbg_log_ex(PHPDBG_G(oplog), "L%-5u %16p %-30s %s %s",
+ phpdbg_log_ex(fileno(PHPDBG_G(oplog)), "L%-5u %16p %s %s\n",
opline->lineno,
opline,
- phpdbg_decode_opcode(opline->opcode),
decode,
- execute_data->op_array->filename ? execute_data->op_array->filename : "unknown");
+ execute_data->func->op_array.filename ? ZSTR_VAL(execute_data->func->op_array.filename) : "unknown");
}
- if (decode) {
- free(decode);
- }
+ efree(decode);
}
-} /* }}} */
-void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags TSRMLS_DC) /* {{{ */
-{
- phpdbg_print_opline_ex(execute_data, NULL, ignore_flags TSRMLS_CC);
+ if (PHPDBG_G(oplog_list)) {
+ phpdbg_oplog_entry *cur = zend_arena_alloc(&PHPDBG_G(oplog_arena), sizeof(phpdbg_oplog_entry));
+ zend_op_array *op_array = &execute_data->func->op_array;
+ cur->op = (zend_op *) execute_data->opline;
+ cur->opcodes = op_array->opcodes;
+ cur->filename = op_array->filename;
+ cur->scope = op_array->scope;
+ cur->function_name = op_array->function_name;
+ cur->next = NULL;
+ PHPDBG_G(oplog_cur)->next = cur;
+ PHPDBG_G(oplog_cur) = cur;
+ }
} /* }}} */
-const char *phpdbg_decode_opcode(zend_uchar opcode) /* {{{ */
+void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags) /* {{{ */
{
-#if ZEND_EXTENSION_API_NO <= PHP_5_5_API_NO
-#define CASE(s) case s: return #s
- switch (opcode) {
- CASE(ZEND_NOP);
- CASE(ZEND_ADD);
- CASE(ZEND_SUB);
- CASE(ZEND_MUL);
- CASE(ZEND_DIV);
- CASE(ZEND_MOD);
- CASE(ZEND_SL);
- CASE(ZEND_SR);
- CASE(ZEND_CONCAT);
- CASE(ZEND_BW_OR);
- CASE(ZEND_BW_AND);
- CASE(ZEND_BW_XOR);
- CASE(ZEND_BW_NOT);
- CASE(ZEND_BOOL_NOT);
- CASE(ZEND_BOOL_XOR);
- CASE(ZEND_IS_IDENTICAL);
- CASE(ZEND_IS_NOT_IDENTICAL);
- CASE(ZEND_IS_EQUAL);
- CASE(ZEND_IS_NOT_EQUAL);
- CASE(ZEND_IS_SMALLER);
- CASE(ZEND_IS_SMALLER_OR_EQUAL);
- CASE(ZEND_CAST);
- CASE(ZEND_QM_ASSIGN);
- CASE(ZEND_ASSIGN_ADD);
- CASE(ZEND_ASSIGN_SUB);
- CASE(ZEND_ASSIGN_MUL);
- CASE(ZEND_ASSIGN_DIV);
- CASE(ZEND_ASSIGN_MOD);
- CASE(ZEND_ASSIGN_SL);
- CASE(ZEND_ASSIGN_SR);
- CASE(ZEND_ASSIGN_CONCAT);
- CASE(ZEND_ASSIGN_BW_OR);
- CASE(ZEND_ASSIGN_BW_AND);
- CASE(ZEND_ASSIGN_BW_XOR);
- CASE(ZEND_PRE_INC);
- CASE(ZEND_PRE_DEC);
- CASE(ZEND_POST_INC);
- CASE(ZEND_POST_DEC);
- CASE(ZEND_ASSIGN);
- CASE(ZEND_ASSIGN_REF);
- CASE(ZEND_ECHO);
- CASE(ZEND_PRINT);
- CASE(ZEND_JMP);
- CASE(ZEND_JMPZ);
- CASE(ZEND_JMPNZ);
- CASE(ZEND_JMPZNZ);
- CASE(ZEND_JMPZ_EX);
- CASE(ZEND_JMPNZ_EX);
- CASE(ZEND_CASE);
- CASE(ZEND_SWITCH_FREE);
- CASE(ZEND_BRK);
- CASE(ZEND_CONT);
- CASE(ZEND_BOOL);
- CASE(ZEND_INIT_STRING);
- CASE(ZEND_ADD_CHAR);
- CASE(ZEND_ADD_STRING);
- CASE(ZEND_ADD_VAR);
- CASE(ZEND_BEGIN_SILENCE);
- CASE(ZEND_END_SILENCE);
- CASE(ZEND_INIT_FCALL_BY_NAME);
- CASE(ZEND_DO_FCALL);
- CASE(ZEND_DO_FCALL_BY_NAME);
- CASE(ZEND_RETURN);
- CASE(ZEND_RECV);
- CASE(ZEND_RECV_INIT);
- CASE(ZEND_SEND_VAL);
- CASE(ZEND_SEND_VAR);
- CASE(ZEND_SEND_REF);
- CASE(ZEND_NEW);
- CASE(ZEND_INIT_NS_FCALL_BY_NAME);
- CASE(ZEND_FREE);
- CASE(ZEND_INIT_ARRAY);
- CASE(ZEND_ADD_ARRAY_ELEMENT);
- CASE(ZEND_INCLUDE_OR_EVAL);
- CASE(ZEND_UNSET_VAR);
- CASE(ZEND_UNSET_DIM);
- CASE(ZEND_UNSET_OBJ);
- CASE(ZEND_FE_RESET);
- CASE(ZEND_FE_FETCH);
- CASE(ZEND_EXIT);
- CASE(ZEND_FETCH_R);
- CASE(ZEND_FETCH_DIM_R);
- CASE(ZEND_FETCH_OBJ_R);
- CASE(ZEND_FETCH_W);
- CASE(ZEND_FETCH_DIM_W);
- CASE(ZEND_FETCH_OBJ_W);
- CASE(ZEND_FETCH_RW);
- CASE(ZEND_FETCH_DIM_RW);
- CASE(ZEND_FETCH_OBJ_RW);
- CASE(ZEND_FETCH_IS);
- CASE(ZEND_FETCH_DIM_IS);
- CASE(ZEND_FETCH_OBJ_IS);
- CASE(ZEND_FETCH_FUNC_ARG);
- CASE(ZEND_FETCH_DIM_FUNC_ARG);
- CASE(ZEND_FETCH_OBJ_FUNC_ARG);
- CASE(ZEND_FETCH_UNSET);
- CASE(ZEND_FETCH_DIM_UNSET);
- CASE(ZEND_FETCH_OBJ_UNSET);
- CASE(ZEND_FETCH_DIM_TMP_VAR);
- CASE(ZEND_FETCH_CONSTANT);
- CASE(ZEND_GOTO);
- CASE(ZEND_EXT_STMT);
- CASE(ZEND_EXT_FCALL_BEGIN);
- CASE(ZEND_EXT_FCALL_END);
- CASE(ZEND_EXT_NOP);
- CASE(ZEND_TICKS);
- CASE(ZEND_SEND_VAR_NO_REF);
- CASE(ZEND_CATCH);
- CASE(ZEND_THROW);
- CASE(ZEND_FETCH_CLASS);
- CASE(ZEND_CLONE);
- CASE(ZEND_RETURN_BY_REF);
- CASE(ZEND_INIT_METHOD_CALL);
- CASE(ZEND_INIT_STATIC_METHOD_CALL);
- CASE(ZEND_ISSET_ISEMPTY_VAR);
- CASE(ZEND_ISSET_ISEMPTY_DIM_OBJ);
- CASE(ZEND_PRE_INC_OBJ);
- CASE(ZEND_PRE_DEC_OBJ);
- CASE(ZEND_POST_INC_OBJ);
- CASE(ZEND_POST_DEC_OBJ);
- CASE(ZEND_ASSIGN_OBJ);
- CASE(ZEND_INSTANCEOF);
- CASE(ZEND_DECLARE_CLASS);
- CASE(ZEND_DECLARE_INHERITED_CLASS);
- CASE(ZEND_DECLARE_FUNCTION);
- CASE(ZEND_RAISE_ABSTRACT_ERROR);
- CASE(ZEND_DECLARE_CONST);
- CASE(ZEND_ADD_INTERFACE);
- CASE(ZEND_DECLARE_INHERITED_CLASS_DELAYED);
- CASE(ZEND_VERIFY_ABSTRACT_CLASS);
- CASE(ZEND_ASSIGN_DIM);
- CASE(ZEND_ISSET_ISEMPTY_PROP_OBJ);
- CASE(ZEND_HANDLE_EXCEPTION);
- CASE(ZEND_USER_OPCODE);
-#ifdef ZEND_JMP_SET
- CASE(ZEND_JMP_SET);
-#endif
- CASE(ZEND_DECLARE_LAMBDA_FUNCTION);
-#ifdef ZEND_ADD_TRAIT
- CASE(ZEND_ADD_TRAIT);
-#endif
-#ifdef ZEND_BIND_TRAITS
- CASE(ZEND_BIND_TRAITS);
-#endif
-#ifdef ZEND_SEPARATE
- CASE(ZEND_SEPARATE);
-#endif
-#ifdef ZEND_QM_ASSIGN_VAR
- CASE(ZEND_QM_ASSIGN_VAR);
-#endif
-#ifdef ZEND_JMP_SET_VAR
- CASE(ZEND_JMP_SET_VAR);
-#endif
-#ifdef ZEND_DISCARD_EXCEPTION
- CASE(ZEND_DISCARD_EXCEPTION);
-#endif
-#ifdef ZEND_YIELD
- CASE(ZEND_YIELD);
-#endif
-#ifdef ZEND_GENERATOR_RETURN
- CASE(ZEND_GENERATOR_RETURN);
-#endif
-#ifdef ZEND_FAST_CALL
- CASE(ZEND_FAST_CALL);
-#endif
-#ifdef ZEND_FAST_RET
- CASE(ZEND_FAST_RET);
-#endif
-#ifdef ZEND_RECV_VARIADIC
- CASE(ZEND_RECV_VARIADIC);
-#endif
- CASE(ZEND_OP_DATA);
- default:
- return "UNKNOWN";
- }
-#else
- const char *ret = zend_get_opcode_name(opcode);
- return ret?ret:"UNKNOWN";
-#endif
+ phpdbg_print_opline_ex(execute_data, ignore_flags);
} /* }}} */
diff --git a/sapi/phpdbg/phpdbg_opcode.h b/sapi/phpdbg/phpdbg_opcode.h
index 6005181b75..10d8be3f42 100644
--- a/sapi/phpdbg/phpdbg_opcode.h
+++ b/sapi/phpdbg/phpdbg_opcode.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -23,9 +23,24 @@
#include "zend_types.h"
-const char *phpdbg_decode_opcode(zend_uchar);
-char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op, HashTable *vars TSRMLS_DC);
-void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags TSRMLS_DC);
-void phpdbg_print_opline_ex(zend_execute_data *execute_data, HashTable *vars, zend_bool ignore_flags TSRMLS_DC);
+char *phpdbg_decode_opline(zend_op_array *ops, zend_op *op);
+void phpdbg_print_opline(zend_execute_data *execute_data, zend_bool ignore_flags);
+void phpdbg_print_opline_ex(zend_execute_data *execute_data, zend_bool ignore_flags);
+
+typedef struct _phpdbg_oplog_entry phpdbg_oplog_entry;
+struct _phpdbg_oplog_entry {
+ phpdbg_oplog_entry *next;
+ zend_string *function_name;
+ zend_class_entry *scope;
+ zend_string *filename;
+ zend_op *opcodes;
+ zend_op *op;
+};
+
+typedef struct _phpdbg_oplog_list phpdbg_oplog_list;
+struct _phpdbg_oplog_list {
+ phpdbg_oplog_list *prev;
+ phpdbg_oplog_entry *start;
+};
#endif /* PHPDBG_OPCODE_H */
diff --git a/sapi/phpdbg/phpdbg_out.c b/sapi/phpdbg/phpdbg_out.c
new file mode 100644
index 0000000000..c771b439d1
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_out.c
@@ -0,0 +1,1321 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Felipe Pena <felipe@php.net> |
+ | Authors: Joe Watkins <joe.watkins@live.co.uk> |
+ | Authors: Bob Weinand <bwoebi@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#include "zend.h"
+#include "php.h"
+#include "spprintf.h"
+#include "phpdbg.h"
+#include "phpdbg_io.h"
+#include "phpdbg_eol.h"
+#include "ext/standard/html.h"
+
+#ifdef _WIN32
+# include "win32/time.h"
+#endif
+
+ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+
+/* copied from php-src/main/snprintf.c and slightly modified */
+/*
+ * NUM_BUF_SIZE is the size of the buffer used for arithmetic conversions
+ *
+ * XXX: this is a magic number; do not decrease it
+ * Emax = 1023
+ * NDIG = 320
+ * NUM_BUF_SIZE >= strlen("-") + Emax + strlrn(".") + NDIG + strlen("E+1023") + 1;
+ */
+#define NUM_BUF_SIZE 2048
+
+/*
+ * Descriptor for buffer area
+ */
+struct buf_area {
+ char *buf_end;
+ char *nextb; /* pointer to next byte to read/write */
+};
+
+typedef struct buf_area buffy;
+
+/*
+ * The INS_CHAR macro inserts a character in the buffer and writes
+ * the buffer back to disk if necessary
+ * It uses the char pointers sp and bep:
+ * sp points to the next available character in the buffer
+ * bep points to the end-of-buffer+1
+ * While using this macro, note that the nextb pointer is NOT updated.
+ *
+ * NOTE: Evaluation of the c argument should not have any side-effects
+ */
+#define INS_CHAR(c, sp, bep, cc) \
+ { \
+ if (sp < bep) \
+ { \
+ *sp++ = c; \
+ } \
+ cc++; \
+ }
+
+#define NUM( c ) ( c - '0' )
+
+#define STR_TO_DEC( str, num ) \
+ num = NUM( *str++ ) ; \
+ while ( isdigit((int)*str ) ) \
+ { \
+ num *= 10 ; \
+ num += NUM( *str++ ) ; \
+ }
+
+/*
+ * This macro does zero padding so that the precision
+ * requirement is satisfied. The padding is done by
+ * adding '0's to the left of the string that is going
+ * to be printed.
+ */
+#define FIX_PRECISION( adjust, precision, s, s_len ) \
+ if ( adjust ) \
+ while ( s_len < precision ) \
+ { \
+ *--s = '0' ; \
+ s_len++ ; \
+ }
+
+/*
+ * Macro that does padding. The padding is done by printing
+ * the character ch.
+ */
+#define PAD( width, len, ch ) do \
+ { \
+ INS_CHAR( ch, sp, bep, cc ) ; \
+ width-- ; \
+ } \
+ while ( width > len )
+
+/*
+ * Prefix the character ch to the string str
+ * Increase length
+ * Set the has_prefix flag
+ */
+#define PREFIX( str, length, ch ) *--str = ch ; length++ ; has_prefix = YES
+
+
+#ifdef HAVE_LOCALE_H
+#include <locale.h>
+#define LCONV_DECIMAL_POINT (*lconv->decimal_point)
+#else
+#define LCONV_DECIMAL_POINT '.'
+#endif
+#define NUL '\0'
+#define S_NULL "(null)"
+#define S_NULL_LEN 6
+#define FLOAT_DIGITS 6
+
+/*
+ * Do format conversion placing the output in buffer
+ */
+static int format_converter(register buffy *odp, const char *fmt, zend_bool escape_xml, va_list ap) {
+ char *sp;
+ char *bep;
+ int cc = 0;
+ int i;
+
+ char *s = NULL, *free_s = NULL;
+ size_t s_len;
+ zend_bool free_zcopy;
+ zval *zvp, zcopy;
+
+ int min_width = 0;
+ int precision = 0;
+ enum {
+ LEFT, RIGHT
+ } adjust;
+ char pad_char;
+ char prefix_char;
+
+ double fp_num;
+ wide_int i_num = (wide_int) 0;
+ u_wide_int ui_num;
+
+ char num_buf[NUM_BUF_SIZE];
+ char char_buf[2]; /* for printing %% and %<unknown> */
+
+#ifdef HAVE_LOCALE_H
+ struct lconv *lconv = NULL;
+#endif
+
+ /*
+ * Flag variables
+ */
+ length_modifier_e modifier;
+ boolean_e alternate_form;
+ boolean_e print_sign;
+ boolean_e print_blank;
+ boolean_e adjust_precision;
+ boolean_e adjust_width;
+ bool_int is_negative;
+
+ sp = odp->nextb;
+ bep = odp->buf_end;
+
+ while (*fmt) {
+ if (*fmt != '%') {
+ INS_CHAR(*fmt, sp, bep, cc);
+ } else {
+ /*
+ * Default variable settings
+ */
+ adjust = RIGHT;
+ alternate_form = print_sign = print_blank = NO;
+ pad_char = ' ';
+ prefix_char = NUL;
+ free_zcopy = 0;
+
+ fmt++;
+
+ /*
+ * Try to avoid checking for flags, width or precision
+ */
+ if (isascii((int)*fmt) && !islower((int)*fmt)) {
+ /*
+ * Recognize flags: -, #, BLANK, +
+ */
+ for (;; fmt++) {
+ if (*fmt == '-')
+ adjust = LEFT;
+ else if (*fmt == '+')
+ print_sign = YES;
+ else if (*fmt == '#')
+ alternate_form = YES;
+ else if (*fmt == ' ')
+ print_blank = YES;
+ else if (*fmt == '0')
+ pad_char = '0';
+ else
+ break;
+ }
+
+ /*
+ * Check if a width was specified
+ */
+ if (isdigit((int)*fmt)) {
+ STR_TO_DEC(fmt, min_width);
+ adjust_width = YES;
+ } else if (*fmt == '*') {
+ min_width = va_arg(ap, int);
+ fmt++;
+ adjust_width = YES;
+ if (min_width < 0) {
+ adjust = LEFT;
+ min_width = -min_width;
+ }
+ } else
+ adjust_width = NO;
+
+ /*
+ * Check if a precision was specified
+ */
+ if (*fmt == '.') {
+ adjust_precision = YES;
+ fmt++;
+ if (isdigit((int)*fmt)) {
+ STR_TO_DEC(fmt, precision);
+ } else if (*fmt == '*') {
+ precision = va_arg(ap, int);
+ fmt++;
+ if (precision < 0)
+ precision = 0;
+ } else
+ precision = 0;
+
+ if (precision > FORMAT_CONV_MAX_PRECISION && *fmt != 's' && *fmt != 'v' && *fmt != 'b') {
+ precision = FORMAT_CONV_MAX_PRECISION;
+ }
+ } else
+ adjust_precision = NO;
+ } else
+ adjust_precision = adjust_width = NO;
+
+ /*
+ * Modifier check
+ */
+ switch (*fmt) {
+ case 'L':
+ fmt++;
+ modifier = LM_LONG_DOUBLE;
+ break;
+ case 'I':
+ fmt++;
+#if SIZEOF_LONG_LONG
+ if (*fmt == '6' && *(fmt+1) == '4') {
+ fmt += 2;
+ modifier = LM_LONG_LONG;
+ } else
+#endif
+ if (*fmt == '3' && *(fmt+1) == '2') {
+ fmt += 2;
+ modifier = LM_LONG;
+ } else {
+#ifdef _WIN64
+ modifier = LM_LONG_LONG;
+#else
+ modifier = LM_LONG;
+#endif
+ }
+ break;
+ case 'l':
+ fmt++;
+#if SIZEOF_LONG_LONG
+ if (*fmt == 'l') {
+ fmt++;
+ modifier = LM_LONG_LONG;
+ } else
+#endif
+ modifier = LM_LONG;
+ break;
+ case 'z':
+ fmt++;
+ modifier = LM_SIZE_T;
+ break;
+ case 'j':
+ fmt++;
+#if SIZEOF_INTMAX_T
+ modifier = LM_INTMAX_T;
+#else
+ modifier = LM_SIZE_T;
+#endif
+ break;
+ case 't':
+ fmt++;
+#if SIZEOF_PTRDIFF_T
+ modifier = LM_PTRDIFF_T;
+#else
+ modifier = LM_SIZE_T;
+#endif
+ break;
+ case 'h':
+ fmt++;
+ if (*fmt == 'h') {
+ fmt++;
+ }
+ /* these are promoted to int, so no break */
+ default:
+ modifier = LM_STD;
+ break;
+ }
+
+ /*
+ * Argument extraction and printing.
+ * First we determine the argument type.
+ * Then, we convert the argument to a string.
+ * On exit from the switch, s points to the string that
+ * must be printed, s_len has the length of the string
+ * The precision requirements, if any, are reflected in s_len.
+ *
+ * NOTE: pad_char may be set to '0' because of the 0 flag.
+ * It is reset to ' ' by non-numeric formats
+ */
+ switch (*fmt) {
+ case 'Z':
+ zvp = (zval *) va_arg(ap, zval *);
+ free_zcopy = zend_make_printable_zval(zvp, &zcopy);
+ if (free_zcopy) {
+ zvp = &zcopy;
+ }
+ s_len = Z_STRLEN_P(zvp);
+ s = Z_STRVAL_P(zvp);
+ if (adjust_precision && precision < s_len) {
+ s_len = precision;
+ }
+ break;
+ case 'u':
+ switch(modifier) {
+ default:
+ i_num = (wide_int) va_arg(ap, unsigned int);
+ break;
+ case LM_LONG_DOUBLE:
+ goto fmt_error;
+ case LM_LONG:
+ i_num = (wide_int) va_arg(ap, unsigned long int);
+ break;
+ case LM_SIZE_T:
+ i_num = (wide_int) va_arg(ap, size_t);
+ break;
+#if SIZEOF_LONG_LONG
+ case LM_LONG_LONG:
+ i_num = (wide_int) va_arg(ap, u_wide_int);
+ break;
+#endif
+#if SIZEOF_INTMAX_T
+ case LM_INTMAX_T:
+ i_num = (wide_int) va_arg(ap, uintmax_t);
+ break;
+#endif
+#if SIZEOF_PTRDIFF_T
+ case LM_PTRDIFF_T:
+ i_num = (wide_int) va_arg(ap, ptrdiff_t);
+ break;
+#endif
+ }
+ /*
+ * The rest also applies to other integer formats, so fall
+ * into that case.
+ */
+ case 'd':
+ case 'i':
+ /*
+ * Get the arg if we haven't already.
+ */
+ if ((*fmt) != 'u') {
+ switch(modifier) {
+ default:
+ i_num = (wide_int) va_arg(ap, int);
+ break;
+ case LM_LONG_DOUBLE:
+ goto fmt_error;
+ case LM_LONG:
+ i_num = (wide_int) va_arg(ap, long int);
+ break;
+ case LM_SIZE_T:
+#if SIZEOF_SSIZE_T
+ i_num = (wide_int) va_arg(ap, ssize_t);
+#else
+ i_num = (wide_int) va_arg(ap, size_t);
+#endif
+ break;
+#if SIZEOF_LONG_LONG
+ case LM_LONG_LONG:
+ i_num = (wide_int) va_arg(ap, wide_int);
+ break;
+#endif
+#if SIZEOF_INTMAX_T
+ case LM_INTMAX_T:
+ i_num = (wide_int) va_arg(ap, intmax_t);
+ break;
+#endif
+#if SIZEOF_PTRDIFF_T
+ case LM_PTRDIFF_T:
+ i_num = (wide_int) va_arg(ap, ptrdiff_t);
+ break;
+#endif
+ }
+ }
+ s = ap_php_conv_10(i_num, (*fmt) == 'u', &is_negative,
+ &num_buf[NUM_BUF_SIZE], &s_len);
+ FIX_PRECISION(adjust_precision, precision, s, s_len);
+
+ if (*fmt != 'u') {
+ if (is_negative) {
+ prefix_char = '-';
+ } else if (print_sign) {
+ prefix_char = '+';
+ } else if (print_blank) {
+ prefix_char = ' ';
+ }
+ }
+ break;
+
+
+ case 'o':
+ switch(modifier) {
+ default:
+ ui_num = (u_wide_int) va_arg(ap, unsigned int);
+ break;
+ case LM_LONG_DOUBLE:
+ goto fmt_error;
+ case LM_LONG:
+ ui_num = (u_wide_int) va_arg(ap, unsigned long int);
+ break;
+ case LM_SIZE_T:
+ ui_num = (u_wide_int) va_arg(ap, size_t);
+ break;
+#if SIZEOF_LONG_LONG
+ case LM_LONG_LONG:
+ ui_num = (u_wide_int) va_arg(ap, u_wide_int);
+ break;
+#endif
+#if SIZEOF_INTMAX_T
+ case LM_INTMAX_T:
+ ui_num = (u_wide_int) va_arg(ap, uintmax_t);
+ break;
+#endif
+#if SIZEOF_PTRDIFF_T
+ case LM_PTRDIFF_T:
+ ui_num = (u_wide_int) va_arg(ap, ptrdiff_t);
+ break;
+#endif
+ }
+ s = ap_php_conv_p2(ui_num, 3, *fmt, &num_buf[NUM_BUF_SIZE], &s_len);
+ FIX_PRECISION(adjust_precision, precision, s, s_len);
+ if (alternate_form && *s != '0') {
+ *--s = '0';
+ s_len++;
+ }
+ break;
+
+
+ case 'x':
+ case 'X':
+ switch(modifier) {
+ default:
+ ui_num = (u_wide_int) va_arg(ap, unsigned int);
+ break;
+ case LM_LONG_DOUBLE:
+ goto fmt_error;
+ case LM_LONG:
+ ui_num = (u_wide_int) va_arg(ap, unsigned long int);
+ break;
+ case LM_SIZE_T:
+ ui_num = (u_wide_int) va_arg(ap, size_t);
+ break;
+#if SIZEOF_LONG_LONG
+ case LM_LONG_LONG:
+ ui_num = (u_wide_int) va_arg(ap, u_wide_int);
+ break;
+#endif
+#if SIZEOF_INTMAX_T
+ case LM_INTMAX_T:
+ ui_num = (u_wide_int) va_arg(ap, uintmax_t);
+ break;
+#endif
+#if SIZEOF_PTRDIFF_T
+ case LM_PTRDIFF_T:
+ ui_num = (u_wide_int) va_arg(ap, ptrdiff_t);
+ break;
+#endif
+ }
+ s = ap_php_conv_p2(ui_num, 4, *fmt, &num_buf[NUM_BUF_SIZE], &s_len);
+ FIX_PRECISION(adjust_precision, precision, s, s_len);
+ if (alternate_form && i_num != 0) {
+ *--s = *fmt; /* 'x' or 'X' */
+ *--s = '0';
+ s_len += 2;
+ }
+ break;
+
+
+ case 's':
+ case 'v':
+ s = va_arg(ap, char *);
+ if (s != NULL) {
+ if (adjust_precision) {
+ s_len = precision;
+ } else {
+ s_len = strlen(s);
+ }
+
+ if (escape_xml) {
+ /* added: support for xml escaping */
+
+ int old_slen = s_len, i = 0;
+ char *old_s = s, *s_ptr;
+ free_s = s_ptr = s = emalloc(old_slen * 6 + 1);
+ do {
+ if (old_s[i] == '&' || old_s[i] == '"' || old_s[i] == '<') {
+ *s_ptr++ = '&';
+ switch (old_s[i]) {
+ case '"':
+ s_len += 5;
+ *s_ptr++ = 'q';
+ *s_ptr++ = 'u';
+ *s_ptr++ = 'o';
+ *s_ptr++ = 't';
+ break;
+ case '<':
+ s_len += 3;
+ *s_ptr++ = 'l';
+ *s_ptr++ = 't';
+ break;
+ case '&':
+ s_len += 4;
+ *s_ptr++ = 'a';
+ *s_ptr++ = 'm';
+ *s_ptr++ = 'p';
+ break;
+ }
+ *s_ptr++ = ';';
+ } else {
+ *s_ptr++ = old_s[i];
+ }
+ } while (i++ < old_slen);
+ }
+ } else {
+ s = S_NULL;
+ s_len = S_NULL_LEN;
+ }
+ pad_char = ' ';
+ break;
+
+
+ case 'b':
+ if (escape_xml) {
+ s = PHPDBG_G(err_buf).xml;
+ } else {
+ s = PHPDBG_G(err_buf).msg;
+ }
+
+ if (s != NULL) {
+ if (escape_xml) {
+ s_len = PHPDBG_G(err_buf).xmllen;
+ } else {
+ s_len = PHPDBG_G(err_buf).msglen;
+ }
+
+ if (adjust_precision && precision != s_len) {
+ s_len = precision;
+ }
+ } else {
+ s = "";
+ s_len = 0;
+ }
+ pad_char = ' ';
+ break;
+
+
+ case 'r':
+ if (PHPDBG_G(req_id)) {
+ s_len = spprintf(&s, 0, "req=\"%lu\"", PHPDBG_G(req_id));
+ free_s = s;
+ } else {
+ s = "";
+ s_len = 0;
+ }
+ break;
+
+
+ case 'f':
+ case 'F':
+ case 'e':
+ case 'E':
+
+ switch(modifier) {
+ case LM_LONG_DOUBLE:
+ fp_num = (double) va_arg(ap, long double);
+ break;
+ case LM_STD:
+ fp_num = va_arg(ap, double);
+ break;
+ default:
+ goto fmt_error;
+ }
+
+ if (zend_isnan(fp_num)) {
+ s = "NAN";
+ s_len = 3;
+ } else if (zend_isinf(fp_num)) {
+ s = "INF";
+ s_len = 3;
+ } else {
+#ifdef HAVE_LOCALE_H
+ if (!lconv) {
+ lconv = localeconv();
+ }
+#endif
+ s = php_conv_fp((*fmt == 'f')?'F':*fmt, fp_num, alternate_form,
+ (adjust_precision == NO) ? FLOAT_DIGITS : precision,
+ (*fmt == 'f')?LCONV_DECIMAL_POINT:'.',
+ &is_negative, &num_buf[1], &s_len);
+ if (is_negative)
+ prefix_char = '-';
+ else if (print_sign)
+ prefix_char = '+';
+ else if (print_blank)
+ prefix_char = ' ';
+ }
+ break;
+
+
+ case 'g':
+ case 'k':
+ case 'G':
+ case 'H':
+ switch(modifier) {
+ case LM_LONG_DOUBLE:
+ fp_num = (double) va_arg(ap, long double);
+ break;
+ case LM_STD:
+ fp_num = va_arg(ap, double);
+ break;
+ default:
+ goto fmt_error;
+ }
+
+ if (zend_isnan(fp_num)) {
+ s = "NAN";
+ s_len = 3;
+ break;
+ } else if (zend_isinf(fp_num)) {
+ if (fp_num > 0) {
+ s = "INF";
+ s_len = 3;
+ } else {
+ s = "-INF";
+ s_len = 4;
+ }
+ break;
+ }
+
+ if (adjust_precision == NO) {
+ precision = FLOAT_DIGITS;
+ } else if (precision == 0) {
+ precision = 1;
+ }
+ /*
+ * * We use &num_buf[ 1 ], so that we have room for the sign
+ */
+#ifdef HAVE_LOCALE_H
+ if (!lconv) {
+ lconv = localeconv();
+ }
+#endif
+ s = php_gcvt(fp_num, precision, (*fmt=='H' || *fmt == 'k') ? '.' : LCONV_DECIMAL_POINT, (*fmt == 'G' || *fmt == 'H')?'E':'e', &num_buf[1]);
+ if (*s == '-') {
+ prefix_char = *s++;
+ } else if (print_sign) {
+ prefix_char = '+';
+ } else if (print_blank) {
+ prefix_char = ' ';
+ }
+
+ s_len = strlen(s);
+
+ if (alternate_form && (strchr(s, '.')) == NULL) {
+ s[s_len++] = '.';
+ }
+ break;
+
+
+ case 'c':
+ char_buf[0] = (char) (va_arg(ap, int));
+ s = &char_buf[0];
+ s_len = 1;
+ pad_char = ' ';
+ break;
+
+
+ case '%':
+ char_buf[0] = '%';
+ s = &char_buf[0];
+ s_len = 1;
+ pad_char = ' ';
+ break;
+
+
+ case 'n':
+ *(va_arg(ap, int *)) = cc;
+ goto skip_output;
+
+ /*
+ * Always extract the argument as a "char *" pointer. We
+ * should be using "void *" but there are still machines
+ * that don't understand it.
+ * If the pointer size is equal to the size of an unsigned
+ * integer we convert the pointer to a hex number, otherwise
+ * we print "%p" to indicate that we don't handle "%p".
+ */
+ case 'p':
+ if (sizeof(char *) <= sizeof(u_wide_int)) {
+ ui_num = (u_wide_int)((size_t) va_arg(ap, char *));
+ s = ap_php_conv_p2(ui_num, 4, 'x',
+ &num_buf[NUM_BUF_SIZE], &s_len);
+ if (ui_num != 0) {
+ *--s = 'x';
+ *--s = '0';
+ s_len += 2;
+ }
+ } else {
+ s = "%p";
+ s_len = 2;
+ }
+ pad_char = ' ';
+ break;
+
+
+ case NUL:
+ /*
+ * The last character of the format string was %.
+ * We ignore it.
+ */
+ continue;
+
+
+fmt_error:
+ php_error(E_ERROR, "Illegal length modifier specified '%c' in s[np]printf call", *fmt);
+ /*
+ * The default case is for unrecognized %'s.
+ * We print %<char> to help the user identify what
+ * option is not understood.
+ * This is also useful in case the user wants to pass
+ * the output of format_converter to another function
+ * that understands some other %<char> (like syslog).
+ * Note that we can't point s inside fmt because the
+ * unknown <char> could be preceded by width etc.
+ */
+ default:
+ char_buf[0] = '%';
+ char_buf[1] = *fmt;
+ s = char_buf;
+ s_len = 2;
+ pad_char = ' ';
+ break;
+ }
+
+ if (prefix_char != NUL) {
+ *--s = prefix_char;
+ s_len++;
+ }
+ if (adjust_width && adjust == RIGHT && min_width > s_len) {
+ if (pad_char == '0' && prefix_char != NUL) {
+ INS_CHAR(*s, sp, bep, cc)
+ s++;
+ s_len--;
+ min_width--;
+ }
+ PAD(min_width, s_len, pad_char);
+ }
+ /*
+ * Print the string s.
+ */
+ for (i = s_len; i != 0; i--) {
+ INS_CHAR(*s, sp, bep, cc);
+ s++;
+ }
+
+ if (adjust_width && adjust == LEFT && min_width > s_len)
+ PAD(min_width, s_len, pad_char);
+ if (free_zcopy) {
+ zval_dtor(&zcopy);
+ }
+ }
+skip_output:
+ if (free_s) {
+ efree(free_s);
+ free_s = NULL;
+ }
+
+ fmt++;
+ }
+ odp->nextb = sp;
+ return (cc);
+}
+
+static void strx_printv(int *ccp, char *buf, size_t len, const char *format, zend_bool escape_xml, va_list ap) {
+ buffy od;
+ int cc;
+
+ /*
+ * First initialize the descriptor
+ * Notice that if no length is given, we initialize buf_end to the
+ * highest possible address.
+ */
+ if (len == 0) {
+ od.buf_end = (char *) ~0;
+ od.nextb = (char *) ~0;
+ } else {
+ od.buf_end = &buf[len-1];
+ od.nextb = buf;
+ }
+
+ /*
+ * Do the conversion
+ */
+ cc = format_converter(&od, format, escape_xml, ap);
+ if (len != 0 && od.nextb <= od.buf_end) {
+ *(od.nextb) = '\0';
+ }
+ if (ccp) {
+ *ccp = cc;
+ }
+}
+
+static int phpdbg_xml_vsnprintf(char *buf, size_t len, const char *format, zend_bool escape_xml, va_list ap) {
+ int cc;
+
+ strx_printv(&cc, buf, len, format, escape_xml, ap);
+ return (cc);
+}
+
+PHPDBG_API int phpdbg_xml_vasprintf(char **buf, const char *format, zend_bool escape_xml, va_list ap) {
+ va_list ap2;
+ int cc;
+
+ va_copy(ap2, ap);
+ cc = phpdbg_xml_vsnprintf(NULL, 0, format, escape_xml, ap2);
+ va_end(ap2);
+
+ *buf = NULL;
+
+ if (cc >= 0) {
+ if ((*buf = emalloc(++cc)) != NULL) {
+ if ((cc = phpdbg_xml_vsnprintf(*buf, cc, format, escape_xml, ap)) < 0) {
+ efree(*buf);
+ *buf = NULL;
+ }
+ }
+ }
+
+ return cc;
+}
+/* copy end */
+
+PHPDBG_API int _phpdbg_xml_asprintf(char **buf, const char *format, zend_bool escape_xml, ...) {
+ int ret;
+ va_list va;
+
+ va_start(va, escape_xml);
+ ret = phpdbg_xml_vasprintf(buf, format, escape_xml, va);
+ va_end(va);
+
+ return ret;
+}
+
+PHPDBG_API int _phpdbg_asprintf(char **buf, const char *format, ...) {
+ int ret;
+ va_list va;
+
+ va_start(va, format);
+ ret = phpdbg_xml_vasprintf(buf, format, 0, va);
+ va_end(va);
+
+ return ret;
+}
+
+static int phpdbg_encode_xml(char **buf, char *msg, int msglen, int from, char *to) {
+ int i;
+ int tolen = to ? strlen(to) : 5;
+ char *tmp = *buf = emalloc(msglen * tolen);
+ for (i = 0; i++ < msglen; msg++) {
+ if (*msg == '&') {
+ memcpy(tmp, ZEND_STRL("&amp;"));
+ tmp += sizeof("&amp;") - 1;
+ } else if (*msg == '<') {
+ memcpy(tmp, ZEND_STRL("&lt;"));
+ tmp += sizeof("&lt;") - 1;
+ } else if (((int) *msg) == from) {
+ memcpy(tmp, to, tolen);
+ tmp += tolen;
+ } else {
+ *tmp++ = *msg;
+ }
+ }
+
+ {
+ int len = tmp - *buf;
+ *buf = erealloc(*buf, len + 1);
+ return len;
+ }
+}
+
+static void phpdbg_encode_ctrl_chars(char **buf, int *buflen) {
+ char *tmp, *tmpptr;
+ int len;
+ int i;
+
+ tmp = tmpptr = emalloc(*buflen * 5);
+
+ for (i = 0; i < *buflen; i++) {
+ if ((*buf)[i] < 0x20) {
+ *tmpptr++ = '&';
+ *tmpptr++ = '#';
+ if ((unsigned int) ((*buf)[i]) > 9) {
+ *tmpptr++ = ((*buf)[i] / 10) + '0';
+ }
+ *tmpptr++ = ((*buf)[i] % 10) + '0';
+ *tmpptr++ = ';';
+ } else {
+ *tmpptr++ = (*buf)[i];
+ }
+ }
+
+ len = tmpptr - tmp;
+
+ efree(*buf);
+ *buf = erealloc(tmp, len + 1);
+ *buflen = len;
+}
+
+static int phpdbg_process_print(int fd, int type, const char *tag, const char *msg, int msglen, const char *xml, int xmllen) {
+ char *msgout = NULL, *buf;
+ int msgoutlen, xmloutlen, buflen;
+ const char *severity;
+
+ if ((PHPDBG_G(flags) & PHPDBG_WRITE_XML) && PHPDBG_G(in_script_xml) && PHPDBG_G(in_script_xml) != type) {
+ phpdbg_mixed_write(fd, ZEND_STRL("</stream>"));
+ PHPDBG_G(in_script_xml) = 0;
+ }
+
+ switch (type) {
+ case P_ERROR:
+ severity = "error";
+ if (!PHPDBG_G(last_was_newline)) {
+ if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+ phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>\n" "</phpdbg>"));
+ } else {
+ phpdbg_mixed_write(fd, ZEND_STRL("\n"));
+ }
+ PHPDBG_G(last_was_newline) = 1;
+ }
+ if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) {
+ msgoutlen = phpdbg_asprintf(&msgout, "\033[%sm[%.*s]\033[0m\n", PHPDBG_G(colors)[PHPDBG_COLOR_ERROR]->code, msglen, msg);
+ } else {
+ msgoutlen = phpdbg_asprintf(&msgout, "[%.*s]\n", msglen, msg);
+ }
+ break;
+
+ case P_NOTICE:
+ severity = "notice";
+ if (!PHPDBG_G(last_was_newline)) {
+ if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+ phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>\n" "</phpdbg>"));
+ } else {
+ phpdbg_mixed_write(fd, ZEND_STRL("\n"));
+ }
+ PHPDBG_G(last_was_newline) = 1;
+ }
+ if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) {
+ msgoutlen = phpdbg_asprintf(&msgout, "\033[%sm[%.*s]\033[0m\n", PHPDBG_G(colors)[PHPDBG_COLOR_NOTICE]->code, msglen, msg);
+ } else {
+ msgoutlen = phpdbg_asprintf(&msgout, "[%.*s]\n", msglen, msg);
+ }
+ break;
+
+ case P_WRITELN:
+ severity = "normal";
+ if (msg) {
+ msgoutlen = phpdbg_asprintf(&msgout, "%.*s\n", msglen, msg);
+ } else {
+ msgoutlen = 1;
+ msgout = estrdup("\n");
+ }
+ PHPDBG_G(last_was_newline) = 1;
+ break;
+
+ case P_WRITE:
+ severity = "normal";
+ if (msg) {
+ msgout = estrndup(msg, msglen);
+ msgoutlen = msglen;
+ PHPDBG_G(last_was_newline) = msg[msglen - 1] == '\n';
+ } else {
+ msgoutlen = 0;
+ msgout = estrdup("");
+ }
+ break;
+
+ case P_STDOUT:
+ case P_STDERR:
+ if (msg) {
+ PHPDBG_G(last_was_newline) = msg[msglen - 1] == '\n';
+ if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+ zend_string *encoded;
+
+ if (PHPDBG_G(in_script_xml) != type) {
+ char *stream_buf;
+ int stream_buflen = phpdbg_asprintf(&stream_buf, "<stream type=\"%s\">", type == P_STDERR ? "stderr" : "stdout");
+ phpdbg_mixed_write(fd, stream_buf, stream_buflen);
+ efree(stream_buf);
+ PHPDBG_G(in_script_xml) = type;
+ }
+ encoded = php_escape_html_entities((unsigned char *) msg, msglen, 0, ENT_NOQUOTES, PG(internal_encoding) && PG(internal_encoding)[0] ? PG(internal_encoding) : (SG(default_charset) ? SG(default_charset) : "UTF-8"));
+ buflen = ZSTR_LEN(encoded);
+ memcpy(buf = emalloc(buflen + 1), ZSTR_VAL(encoded), buflen);
+ phpdbg_encode_ctrl_chars(&buf, &buflen);
+ phpdbg_mixed_write(fd, buf, buflen);
+ efree(buf);
+ } else {
+ phpdbg_mixed_write(fd, msg, msglen);
+ }
+ return msglen;
+ }
+ break;
+
+ /* no formatting on logging output */
+ case P_LOG:
+ severity = "log";
+ if (msg) {
+ struct timeval tp;
+ if (gettimeofday(&tp, NULL) == SUCCESS) {
+ msgoutlen = phpdbg_asprintf(&msgout, "[%ld %.8F]: %.*s\n", tp.tv_sec, tp.tv_usec / 1000000., msglen, msg);
+ } else {
+ msgoutlen = FAILURE;
+ }
+ }
+ break;
+ }
+
+ if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+ char *xmlout;
+
+ if (PHPDBG_G(req_id)) {
+ char *xmlbuf = NULL;
+ xmllen = phpdbg_asprintf(&xmlbuf, "req=\"%lu\" %.*s", PHPDBG_G(req_id), xmllen, xml);
+ xml = xmlbuf;
+ }
+ if (msgout) {
+ buflen = phpdbg_encode_xml(&buf, msgout, msgoutlen, '"', "&quot;");
+ xmloutlen = phpdbg_asprintf(&xmlout, "<%s severity=\"%s\" %.*s msgout=\"%.*s\" />", tag, severity, xmllen, xml, buflen, buf);
+
+ efree(buf);
+ } else {
+ xmloutlen = phpdbg_asprintf(&xmlout, "<%s severity=\"%s\" %.*s msgout=\"\" />", tag, severity, xmllen, xml);
+ }
+
+ phpdbg_encode_ctrl_chars(&xmlout, &xmloutlen);
+ phpdbg_eol_convert(&xmlout, &xmloutlen);
+ phpdbg_mixed_write(fd, xmlout, xmloutlen);
+ efree(xmlout);
+ } else if (msgout) {
+ phpdbg_eol_convert(&msgout, &msgoutlen);
+ phpdbg_mixed_write(fd, msgout, msgoutlen);
+ }
+
+ if (PHPDBG_G(req_id) && (PHPDBG_G(flags) & PHPDBG_WRITE_XML)) {
+ efree((char *) xml);
+ }
+
+ if (msgout) {
+ efree(msgout);
+ }
+
+ return msgout ? msgoutlen : xmloutlen;
+} /* }}} */
+
+PHPDBG_API int phpdbg_vprint(int type, int fd, const char *tag, const char *xmlfmt, const char *strfmt, va_list args) {
+ char *msg = NULL, *xml = NULL;
+ int msglen = 0, xmllen = 0;
+ int len;
+ va_list argcpy;
+
+ if (strfmt != NULL && strlen(strfmt) > 0L) {
+ va_copy(argcpy, args);
+ msglen = phpdbg_xml_vasprintf(&msg, strfmt, 0, argcpy);
+ va_end(argcpy);
+ }
+
+ if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+ if (xmlfmt != NULL && strlen(xmlfmt) > 0L) {
+ va_copy(argcpy, args);
+ xmllen = phpdbg_xml_vasprintf(&xml, xmlfmt, 1, argcpy);
+ va_end(argcpy);
+ } else {
+ xml = estrdup("");
+ }
+ }
+
+ if (PHPDBG_G(err_buf).active && type != P_STDOUT && type != P_STDERR) {
+ phpdbg_free_err_buf();
+
+ PHPDBG_G(err_buf).type = type;
+ PHPDBG_G(err_buf).fd = fd;
+ PHPDBG_G(err_buf).tag = estrdup(tag);
+ PHPDBG_G(err_buf).msg = msg;
+ PHPDBG_G(err_buf).msglen = msglen;
+ if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+ PHPDBG_G(err_buf).xml = xml;
+ PHPDBG_G(err_buf).xmllen = xmllen;
+ }
+
+ return msglen;
+ }
+
+ len = phpdbg_process_print(fd, type, tag, msg, msglen, xml, xmllen);
+
+ if (msg) {
+ efree(msg);
+ }
+
+ if (xml) {
+ efree(xml);
+ }
+
+ return len;
+}
+
+PHPDBG_API void phpdbg_free_err_buf(void) {
+ if (PHPDBG_G(err_buf).type == 0) {
+ return;
+ }
+
+ PHPDBG_G(err_buf).type = 0;
+
+ efree(PHPDBG_G(err_buf).tag);
+ efree(PHPDBG_G(err_buf).msg);
+ if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+ efree(PHPDBG_G(err_buf).xml);
+ }
+}
+
+PHPDBG_API void phpdbg_activate_err_buf(zend_bool active) {
+ PHPDBG_G(err_buf).active = active;
+}
+
+PHPDBG_API int phpdbg_output_err_buf(const char *tag, const char *xmlfmt, const char *strfmt, ...) {
+ int len;
+ va_list args;
+ int errbuf_active = PHPDBG_G(err_buf).active;
+
+ if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) {
+ return 0;
+ }
+
+ PHPDBG_G(err_buf).active = 0;
+
+ va_start(args, strfmt);
+ len = phpdbg_vprint(PHPDBG_G(err_buf).type, PHPDBG_G(err_buf).fd, tag ? tag : PHPDBG_G(err_buf).tag, xmlfmt, strfmt, args);
+ va_end(args);
+
+ PHPDBG_G(err_buf).active = errbuf_active;
+ phpdbg_free_err_buf();
+
+ return len;
+}
+
+PHPDBG_API int phpdbg_print(int type, int fd, const char *tag, const char *xmlfmt, const char *strfmt, ...) {
+ va_list args;
+ int len;
+
+ if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) {
+ return 0;
+ }
+
+ va_start(args, strfmt);
+ len = phpdbg_vprint(type, fd, tag, xmlfmt, strfmt, args);
+ va_end(args);
+
+ return len;
+}
+
+PHPDBG_API int phpdbg_xml_internal(int fd, const char *fmt, ...) {
+ int len = 0;
+
+ if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) {
+ return 0;
+ }
+
+ if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+ va_list args;
+ char *buffer;
+ int buflen;
+
+ va_start(args, fmt);
+ buflen = phpdbg_xml_vasprintf(&buffer, fmt, 1, args);
+ va_end(args);
+
+ phpdbg_encode_ctrl_chars(&buffer, &buflen);
+
+ if (PHPDBG_G(in_script_xml)) {
+ phpdbg_mixed_write(fd, ZEND_STRL("</stream>"));
+ PHPDBG_G(in_script_xml) = 0;
+ }
+
+ len = phpdbg_mixed_write(fd, buffer, buflen);
+ efree(buffer);
+ }
+
+ return len;
+}
+
+PHPDBG_API int phpdbg_log_internal(int fd, const char *fmt, ...) {
+ va_list args;
+ char *buffer;
+ int buflen;
+ int len = 0;
+
+ va_start(args, fmt);
+ buflen = phpdbg_xml_vasprintf(&buffer, fmt, 0, args);
+ va_end(args);
+
+ len = phpdbg_mixed_write(fd, buffer, buflen);
+ efree(buffer);
+
+ return len;
+}
+
+PHPDBG_API int phpdbg_out_internal(int fd, const char *fmt, ...) {
+ va_list args;
+ char *buffer;
+ int buflen;
+ int len = 0;
+
+ if (PHPDBG_G(flags) & PHPDBG_DISCARD_OUTPUT) {
+ return 0;
+ }
+
+ va_start(args, fmt);
+ buflen = phpdbg_xml_vasprintf(&buffer, fmt, 0, args);
+ va_end(args);
+
+ if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+ char *msg;
+ int msglen;
+
+ msglen = phpdbg_encode_xml(&msg, buffer, buflen, 256, NULL);
+ phpdbg_encode_ctrl_chars(&msg, &msglen);
+ phpdbg_eol_convert(&msg, &msglen);
+
+ if (PHPDBG_G(in_script_xml)) {
+ phpdbg_mixed_write(fd, ZEND_STRL("</stream>"));
+ PHPDBG_G(in_script_xml) = 0;
+ }
+
+ phpdbg_mixed_write(fd, ZEND_STRL("<phpdbg>"));
+ len = phpdbg_mixed_write(fd, msg, msglen);
+ phpdbg_mixed_write(fd, ZEND_STRL("</phpdbg>"));
+ } else {
+ phpdbg_eol_convert(&buffer, &buflen);
+ len = phpdbg_mixed_write(fd, buffer, buflen);
+ }
+
+ efree(buffer);
+ return len;
+}
+
+
+PHPDBG_API int phpdbg_rlog_internal(int fd, const char *fmt, ...) { /* {{{ */
+ int rc = 0;
+
+ va_list args;
+ struct timeval tp;
+
+ va_start(args, fmt);
+ if (gettimeofday(&tp, NULL) == SUCCESS) {
+ char friendly[100];
+ char *format = NULL, *buffer = NULL, *outbuf = NULL;
+ const time_t tt = tp.tv_sec;
+
+#ifdef PHP_WIN32
+ strftime(friendly, 100, "%a %b %d %H.%%04d %Y", localtime(&tt));
+#else
+ strftime(friendly, 100, "%a %b %d %T.%%04d %Y", localtime(&tt));
+#endif
+ phpdbg_asprintf(&buffer, friendly, tp.tv_usec/1000);
+ phpdbg_asprintf(&format, "[%s]: %s\n", buffer, fmt);
+ rc = phpdbg_xml_vasprintf(&outbuf, format, 0, args);
+
+ if (outbuf) {
+ rc = phpdbg_mixed_write(fd, outbuf, rc);
+ efree(outbuf);
+ }
+
+ efree(format);
+ efree(buffer);
+ }
+ va_end(args);
+
+ return rc;
+} /* }}} */
diff --git a/sapi/phpdbg/phpdbg_out.h b/sapi/phpdbg/phpdbg_out.h
new file mode 100644
index 0000000000..30435718ed
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_out.h
@@ -0,0 +1,93 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Felipe Pena <felipe@php.net> |
+ | Authors: Joe Watkins <joe.watkins@live.co.uk> |
+ | Authors: Bob Weinand <bwoebi@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#ifndef PHPDBG_OUT_H
+#define PHPDBG_OUT_H
+
+/**
+ * Error/notice/formatting helpers
+ */
+enum {
+ P_ERROR = 1,
+ P_NOTICE,
+ P_WRITELN,
+ P_WRITE,
+ P_STDOUT,
+ P_STDERR,
+ P_LOG
+};
+
+#ifdef ZTS
+PHPDBG_API int phpdbg_print(int severity, int fd, const char *tag, const char *xmlfmt, const char *strfmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 6, 7);
+PHPDBG_API int phpdbg_xml_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
+PHPDBG_API int phpdbg_log_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
+PHPDBG_API int phpdbg_out_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
+PHPDBG_API int phpdbg_rlog_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
+#else
+PHPDBG_API int phpdbg_print(int severity, int fd, const char *tag, const char *xmlfmt, const char *strfmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 5, 6);
+PHPDBG_API int phpdbg_xml_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
+PHPDBG_API int phpdbg_log_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
+PHPDBG_API int phpdbg_out_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
+PHPDBG_API int phpdbg_rlog_internal(int fd, const char *fmt, ...) PHP_ATTRIBUTE_FORMAT(printf, 2, 3);
+#endif
+
+
+#define phpdbg_error(tag, xmlfmt, strfmt, ...) phpdbg_print(P_ERROR , PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__)
+#define phpdbg_notice(tag, xmlfmt, strfmt, ...) phpdbg_print(P_NOTICE , PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__)
+#define phpdbg_writeln(tag, xmlfmt, strfmt, ...) phpdbg_print(P_WRITELN, PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__)
+#define phpdbg_write(tag, xmlfmt, strfmt, ...) phpdbg_print(P_WRITE , PHPDBG_G(io)[PHPDBG_STDOUT].fd, tag, xmlfmt, strfmt, ##__VA_ARGS__)
+#define phpdbg_script(type, fmt, ...) phpdbg_print(type , PHPDBG_G(io)[PHPDBG_STDOUT].fd, NULL, NULL, fmt, ##__VA_ARGS__)
+#define phpdbg_log(fmt, ...) phpdbg_log_internal(PHPDBG_G(io)[PHPDBG_STDOUT].fd, fmt, ##__VA_ARGS__)
+#define phpdbg_xml(fmt, ...) phpdbg_xml_internal(PHPDBG_G(io)[PHPDBG_STDOUT].fd, fmt, ##__VA_ARGS__)
+#define phpdbg_out(fmt, ...) phpdbg_out_internal(PHPDBG_G(io)[PHPDBG_STDOUT].fd, fmt, ##__VA_ARGS__)
+
+#define phpdbg_error_ex(out, tag, xmlfmt, strfmt, ...) phpdbg_print(P_ERROR , out, tag, xmlfmt, strfmt, ##__VA_ARGS__)
+#define phpdbg_notice_ex(out, tag, xmlfmt, strfmt, ...) phpdbg_print(P_NOTICE , out, tag, xmlfmt, strfmt, ##__VA_ARGS__)
+#define phpdbg_writeln_ex(out, tag, xmlfmt, strfmt, ...) phpdbg_print(P_WRITELN, out, tag, xmlfmt, strfmt, ##__VA_ARGS__)
+#define phpdbg_write_ex(out, tag, xmlfmt, strfmt, ...) phpdbg_print(P_WRITE , out, tag, xmlfmt, strfmt, ##__VA_ARGS__)
+#define phpdbg_script_ex(out, type, fmt, ...) phpdbg_print(type , out, NULL, NULL, fmt, ##__VA_ARGS__)
+#define phpdbg_log_ex(out, fmt, ...) phpdbg_log_internal(out, fmt, ##__VA_ARGS__)
+#define phpdbg_xml_ex(out, fmt, ...) phpdbg_xml_internal(out, fmt, ##__VA_ARGS__)
+#define phpdbg_out_ex(out, fmt, ...) phpdbg_out_internal(out, fmt, ##__VA_ARGS__)
+
+#define phpdbg_rlog(fd, fmt, ...) phpdbg_rlog_internal(fd, fmt, ##__VA_ARGS__)
+
+#define phpdbg_xml_asprintf(buf, ...) _phpdbg_xml_asprintf(buf, ##__VA_ARGS__)
+PHPDBG_API int _phpdbg_xml_asprintf(char **buf, const char *format, zend_bool escape_xml, ...);
+
+#define phpdbg_asprintf(buf, ...) _phpdbg_asprintf(buf, ##__VA_ARGS__)
+PHPDBG_API int _phpdbg_asprintf(char **buf, const char *format, ...);
+
+
+#if PHPDBG_DEBUG
+# define phpdbg_debug(fmt, ...) phpdbg_log_ex(PHPDBG_G(io)[PHPDBG_STDERR].fd, fmt, ##__VA_ARGS__)
+#else
+# define phpdbg_debug(fmt, ...)
+#endif
+
+PHPDBG_API void phpdbg_free_err_buf(void);
+PHPDBG_API void phpdbg_activate_err_buf(zend_bool active);
+PHPDBG_API int phpdbg_output_err_buf(const char *tag, const char *xmlfmt, const char *strfmt, ...);
+
+
+/* {{{ For separation */
+#define SEPARATE "------------------------------------------------" /* }}} */
+
+#endif /* PHPDBG_OUT_H */
diff --git a/sapi/phpdbg/phpdbg_parser.c b/sapi/phpdbg/phpdbg_parser.c
index 5537dfd330..8a33a10780 100644
--- a/sapi/phpdbg/phpdbg_parser.c
+++ b/sapi/phpdbg/phpdbg_parser.c
@@ -72,14 +72,14 @@
/* Line 371 of yacc.c */
#line 1 "sapi/phpdbg/phpdbg_parser.y"
-
+
/*
* phpdbg_parser.y
* (from php-src root)
* flex sapi/phpdbg/dev/phpdbg_lexer.l
* bison sapi/phpdbg/dev/phpdbg_parser.y
*/
-
+
#include "phpdbg.h"
#include "phpdbg_cmd.h"
#include "phpdbg_utils.h"
@@ -92,13 +92,18 @@
#include "phpdbg_lexer.h"
#undef yyerror
-static int yyerror(void ***tsrm_ls, const char *msg);
+static int yyerror(const char *msg);
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+#ifdef _MSC_VER
+#define YYMALLOC malloc
+#define YYFREE free
+#endif
+
/* Line 371 of yacc.c */
-#line 102 "sapi/phpdbg/phpdbg_parser.c"
+#line 107 "sapi/phpdbg/phpdbg_parser.c"
# ifndef YY_NULL
# if defined __cplusplus && 201103L <= __cplusplus
@@ -129,7 +134,7 @@ extern int phpdbg_debug;
#endif
/* "%code requires" blocks. */
/* Line 387 of yacc.c */
-#line 31 "sapi/phpdbg/phpdbg_parser.y"
+#line 36 "sapi/phpdbg/phpdbg_parser.y"
#include "phpdbg.h"
#ifndef YY_TYPEDEF_YY_SCANNER_T
@@ -139,7 +144,7 @@ typedef void* yyscan_t;
/* Line 387 of yacc.c */
-#line 143 "sapi/phpdbg/phpdbg_parser.c"
+#line 148 "sapi/phpdbg/phpdbg_parser.c"
/* Tokens. */
#ifndef YYTOKENTYPE
@@ -157,14 +162,16 @@ typedef void* yyscan_t;
T_COLON = 265,
T_DCOLON = 266,
T_POUND = 267,
- T_PROTO = 268,
- T_DIGITS = 269,
- T_LITERAL = 270,
- T_ADDR = 271,
- T_OPCODE = 272,
- T_ID = 273,
- T_INPUT = 274,
- T_UNEXPECTED = 275
+ T_SEPARATOR = 268,
+ T_PROTO = 269,
+ T_DIGITS = 270,
+ T_LITERAL = 271,
+ T_ADDR = 272,
+ T_OPCODE = 273,
+ T_ID = 274,
+ T_INPUT = 275,
+ T_UNEXPECTED = 276,
+ T_REQ_ID = 277
};
#endif
/* Tokens. */
@@ -178,14 +185,16 @@ typedef void* yyscan_t;
#define T_COLON 265
#define T_DCOLON 266
#define T_POUND 267
-#define T_PROTO 268
-#define T_DIGITS 269
-#define T_LITERAL 270
-#define T_ADDR 271
-#define T_OPCODE 272
-#define T_ID 273
-#define T_INPUT 274
-#define T_UNEXPECTED 275
+#define T_SEPARATOR 268
+#define T_PROTO 269
+#define T_DIGITS 270
+#define T_LITERAL 271
+#define T_ADDR 272
+#define T_OPCODE 273
+#define T_ID 274
+#define T_INPUT 275
+#define T_UNEXPECTED 276
+#define T_REQ_ID 277
@@ -205,7 +214,7 @@ int phpdbg_parse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
-int phpdbg_parse (void *tsrm_ls);
+int phpdbg_parse (void);
#else
int phpdbg_parse ();
#endif
@@ -216,7 +225,7 @@ int phpdbg_parse ();
/* Copy the second part of user declarations. */
/* Line 390 of yacc.c */
-#line 220 "sapi/phpdbg/phpdbg_parser.c"
+#line 229 "sapi/phpdbg/phpdbg_parser.c"
#ifdef short
# undef short
@@ -443,22 +452,22 @@ union yyalloc
#endif /* !YYCOPY_NEEDED */
/* YYFINAL -- State number of the termination state. */
-#define YYFINAL 25
+#define YYFINAL 27
/* YYLAST -- Last index in YYTABLE. */
-#define YYLAST 42
+#define YYLAST 50
/* YYNTOKENS -- Number of terminals. */
-#define YYNTOKENS 21
+#define YYNTOKENS 23
/* YYNNTS -- Number of nonterminals. */
-#define YYNNTS 5
+#define YYNNTS 7
/* YYNRULES -- Number of rules. */
-#define YYNRULES 25
+#define YYNRULES 30
/* YYNRULES -- Number of states. */
-#define YYNSTATES 38
+#define YYNSTATES 46
/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
#define YYUNDEFTOK 2
-#define YYMAXUTOK 275
+#define YYMAXUTOK 277
#define YYTRANSLATE(YYX) \
((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
@@ -493,7 +502,7 @@ static const yytype_uint8 yytranslate[] =
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20
+ 15, 16, 17, 18, 19, 20, 21, 22
};
#if YYDEBUG
@@ -501,30 +510,34 @@ static const yytype_uint8 yytranslate[] =
YYRHS. */
static const yytype_uint8 yyprhs[] =
{
- 0, 0, 3, 5, 7, 8, 10, 13, 17, 22,
- 27, 33, 37, 43, 47, 50, 52, 54, 56, 58,
- 60, 62, 64, 67, 70, 72
+ 0, 0, 3, 5, 9, 10, 12, 14, 16, 19,
+ 22, 26, 31, 36, 42, 46, 52, 56, 59, 61,
+ 63, 65, 67, 69, 71, 73, 75, 76, 80, 84,
+ 87
};
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
static const yytype_int8 yyrhs[] =
{
- 22, 0, -1, 23, -1, 25, -1, -1, 24, -1,
- 23, 24, -1, 18, 10, 14, -1, 18, 10, 12,
- 14, -1, 13, 18, 10, 14, -1, 13, 18, 10,
- 12, 14, -1, 18, 11, 18, -1, 18, 11, 18,
- 12, 14, -1, 18, 12, 14, -1, 6, 19, -1,
- 17, -1, 16, -1, 15, -1, 7, -1, 8, -1,
- 14, -1, 18, -1, 3, 19, -1, 5, 19, -1,
- 4, -1, 4, 19, -1
+ 24, 0, -1, 25, -1, 24, 13, 25, -1, -1,
+ 26, -1, 29, -1, 27, -1, 26, 27, -1, 26,
+ 28, -1, 19, 10, 15, -1, 19, 10, 12, 15,
+ -1, 14, 19, 10, 15, -1, 14, 19, 10, 12,
+ 15, -1, 19, 11, 19, -1, 19, 11, 19, 12,
+ 15, -1, 19, 12, 15, -1, 6, 20, -1, 18,
+ -1, 17, -1, 16, -1, 7, -1, 8, -1, 15,
+ -1, 19, -1, 22, -1, -1, 3, 28, 20, -1,
+ 5, 28, 20, -1, 4, 28, -1, 4, 28, 20,
+ -1
};
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
- 0, 66, 66, 67, 68, 72, 73, 77, 82, 87,
- 97, 107, 112, 118, 124, 129, 130, 131, 132, 133,
- 134, 135, 139, 144, 149, 153
+ 0, 71, 71, 72, 73, 77, 78, 82, 83, 84,
+ 88, 93, 98, 108, 118, 123, 129, 135, 140, 141,
+ 142, 143, 144, 145, 146, 150, 151, 155, 160, 165,
+ 169
};
#endif
@@ -537,11 +550,13 @@ static const char *const yytname[] =
"\"if (condition)\"", "\"truthy (true, on, yes or enabled)\"",
"\"falsy (false, off, no or disabled)\"",
"\"string (some input, perhaps)\"", "\": (colon)\"",
- "\":: (double colon)\"", "\"# (pound sign)\"", "\"protocol (file://)\"",
- "\"digits (numbers)\"", "\"literal (string)\"", "\"address\"",
- "\"opcode\"", "\"identifier (command or function name)\"",
- "\"input (input string or data)\"", "\"input\"", "$accept", "input",
- "parameters", "parameter", "full_expression", YY_NULL
+ "\":: (double colon)\"", "\"# (pound sign followed by digits)\"",
+ "\"# (pound sign)\"", "\"protocol (file://)\"", "\"digits (numbers)\"",
+ "\"literal (string)\"", "\"address\"", "\"opcode\"",
+ "\"identifier (command or function name)\"",
+ "\"input (input string or data)\"", "\"input\"",
+ "\"request id (-r %d)\"", "$accept", "input", "command", "parameters",
+ "parameter", "req_id", "full_expression", YY_NULL
};
#endif
@@ -552,24 +567,26 @@ static const yytype_uint16 yytoknum[] =
{
0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
- 275
+ 275, 276, 277
};
# endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
static const yytype_uint8 yyr1[] =
{
- 0, 21, 22, 22, 22, 23, 23, 24, 24, 24,
- 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
- 24, 24, 25, 25, 25, 25
+ 0, 23, 24, 24, 24, 25, 25, 26, 26, 26,
+ 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
+ 27, 27, 27, 27, 27, 28, 28, 29, 29, 29,
+ 29
};
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
static const yytype_uint8 yyr2[] =
{
- 0, 2, 1, 1, 0, 1, 2, 3, 4, 4,
- 5, 3, 5, 3, 2, 1, 1, 1, 1, 1,
- 1, 1, 2, 2, 1, 2
+ 0, 2, 1, 3, 0, 1, 1, 1, 2, 2,
+ 3, 4, 4, 5, 3, 5, 3, 2, 1, 1,
+ 1, 1, 1, 1, 1, 1, 0, 3, 3, 2,
+ 3
};
/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM.
@@ -577,33 +594,35 @@ static const yytype_uint8 yyr2[] =
means the default is an error. */
static const yytype_uint8 yydefact[] =
{
- 4, 0, 24, 0, 0, 18, 19, 0, 20, 17,
- 16, 15, 21, 0, 2, 5, 3, 22, 25, 23,
- 14, 0, 0, 0, 0, 1, 6, 0, 0, 7,
- 11, 13, 0, 9, 8, 0, 10, 12
+ 4, 26, 26, 26, 0, 21, 22, 0, 23, 20,
+ 19, 18, 24, 0, 2, 5, 7, 6, 25, 0,
+ 29, 0, 17, 0, 0, 0, 0, 1, 0, 8,
+ 9, 27, 30, 28, 0, 0, 10, 14, 16, 3,
+ 0, 12, 11, 0, 13, 15
};
/* YYDEFGOTO[NTERM-NUM]. */
static const yytype_int8 yydefgoto[] =
{
- -1, 13, 14, 15, 16
+ -1, 13, 14, 15, 16, 19, 17
};
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
-#define YYPACT_NINF -11
+#define YYPACT_NINF -17
static const yytype_int8 yypact[] =
{
- -3, -10, 11, 12, 13, -11, -11, 15, -11, -11,
- -11, -11, -4, 29, 10, -11, -11, -11, -11, -11,
- -11, 24, 7, 17, 22, -11, -11, 8, 23, -11,
- 26, -11, 25, -11, -11, 27, -11, -11
+ -3, -16, -16, -16, -10, -17, -17, 2, -17, -17,
+ -17, -17, 26, 9, -17, 11, -17, -17, -17, 3,
+ 4, 21, -17, 29, 19, 23, 25, -17, -3, -17,
+ -17, -17, -17, -17, 20, 28, -17, 32, -17, -17,
+ 30, -17, -17, 31, -17, -17
};
/* YYPGOTO[NTERM-NUM]. */
static const yytype_int8 yypgoto[] =
{
- -11, -11, -11, 28, -11
+ -17, -17, 22, -17, 33, 5, -17
};
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
@@ -612,36 +631,39 @@ static const yytype_int8 yypgoto[] =
#define YYTABLE_NINF -1
static const yytype_uint8 yytable[] =
{
- 1, 2, 3, 4, 5, 6, 22, 23, 24, 17,
- 7, 8, 9, 10, 11, 12, 4, 5, 6, 28,
- 32, 29, 33, 7, 8, 9, 10, 11, 12, 25,
- 18, 19, 20, 21, 27, 30, 31, 34, 35, 36,
- 0, 37, 26
+ 1, 2, 3, 4, 5, 6, 18, 20, 21, 27,
+ 22, 7, 8, 9, 10, 11, 12, 4, 5, 6,
+ 30, 23, 28, 31, 32, 7, 8, 9, 10, 11,
+ 12, 35, 40, 18, 36, 41, 24, 25, 26, 34,
+ 38, 33, 37, 42, 43, 44, 45, 0, 29, 0,
+ 39
};
#define yypact_value_is_default(Yystate) \
- (!!((Yystate) == (-11)))
+ (!!((Yystate) == (-17)))
#define yytable_value_is_error(Yytable_value) \
YYID (0)
static const yytype_int8 yycheck[] =
{
- 3, 4, 5, 6, 7, 8, 10, 11, 12, 19,
- 13, 14, 15, 16, 17, 18, 6, 7, 8, 12,
- 12, 14, 14, 13, 14, 15, 16, 17, 18, 0,
- 19, 19, 19, 18, 10, 18, 14, 14, 12, 14,
- -1, 14, 14
+ 3, 4, 5, 6, 7, 8, 22, 2, 3, 0,
+ 20, 14, 15, 16, 17, 18, 19, 6, 7, 8,
+ 15, 19, 13, 20, 20, 14, 15, 16, 17, 18,
+ 19, 12, 12, 22, 15, 15, 10, 11, 12, 10,
+ 15, 20, 19, 15, 12, 15, 15, -1, 15, -1,
+ 28
};
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
static const yytype_uint8 yystos[] =
{
- 0, 3, 4, 5, 6, 7, 8, 13, 14, 15,
- 16, 17, 18, 22, 23, 24, 25, 19, 19, 19,
- 19, 18, 10, 11, 12, 0, 24, 10, 12, 14,
- 18, 14, 12, 14, 14, 12, 14, 14
+ 0, 3, 4, 5, 6, 7, 8, 14, 15, 16,
+ 17, 18, 19, 24, 25, 26, 27, 29, 22, 28,
+ 28, 28, 20, 19, 10, 11, 12, 0, 13, 27,
+ 28, 20, 20, 20, 10, 12, 15, 19, 15, 25,
+ 12, 15, 15, 12, 15, 15
};
#define yyerrok (yyerrstatus = 0)
@@ -683,7 +705,7 @@ do \
} \
else \
{ \
- yyerror (tsrm_ls, YY_("syntax error: cannot back up")); \
+ yyerror (YY_("syntax error: cannot back up")); \
YYERROR; \
} \
while (YYID (0))
@@ -726,7 +748,7 @@ do { \
{ \
YYFPRINTF (stderr, "%s ", Title); \
yy_symbol_print (stderr, \
- Type, Value, tsrm_ls); \
+ Type, Value); \
YYFPRINTF (stderr, "\n"); \
} \
} while (YYID (0))
@@ -740,21 +762,19 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
-yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *tsrm_ls)
+yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
#else
static void
-yy_symbol_value_print (yyoutput, yytype, yyvaluep, tsrm_ls)
+yy_symbol_value_print (yyoutput, yytype, yyvaluep)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
- void *tsrm_ls;
#endif
{
FILE *yyo = yyoutput;
YYUSE (yyo);
if (!yyvaluep)
return;
- YYUSE (tsrm_ls);
# ifdef YYPRINT
if (yytype < YYNTOKENS)
YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
@@ -772,14 +792,13 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, tsrm_ls)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
-yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, void *tsrm_ls)
+yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
#else
static void
-yy_symbol_print (yyoutput, yytype, yyvaluep, tsrm_ls)
+yy_symbol_print (yyoutput, yytype, yyvaluep)
FILE *yyoutput;
int yytype;
YYSTYPE const * const yyvaluep;
- void *tsrm_ls;
#endif
{
if (yytype < YYNTOKENS)
@@ -787,7 +806,7 @@ yy_symbol_print (yyoutput, yytype, yyvaluep, tsrm_ls)
else
YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
- yy_symbol_value_print (yyoutput, yytype, yyvaluep, tsrm_ls);
+ yy_symbol_value_print (yyoutput, yytype, yyvaluep);
YYFPRINTF (yyoutput, ")");
}
@@ -830,13 +849,12 @@ do { \
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
-yy_reduce_print (YYSTYPE *yyvsp, int yyrule, void *tsrm_ls)
+yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
#else
static void
-yy_reduce_print (yyvsp, yyrule, tsrm_ls)
+yy_reduce_print (yyvsp, yyrule)
YYSTYPE *yyvsp;
int yyrule;
- void *tsrm_ls;
#endif
{
int yynrhs = yyr2[yyrule];
@@ -850,7 +868,7 @@ yy_reduce_print (yyvsp, yyrule, tsrm_ls)
YYFPRINTF (stderr, " $%d = ", yyi + 1);
yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
&(yyvsp[(yyi + 1) - (yynrhs)])
- , tsrm_ls);
+ );
YYFPRINTF (stderr, "\n");
}
}
@@ -858,7 +876,7 @@ yy_reduce_print (yyvsp, yyrule, tsrm_ls)
# define YY_REDUCE_PRINT(Rule) \
do { \
if (yydebug) \
- yy_reduce_print (yyvsp, Rule, tsrm_ls); \
+ yy_reduce_print (yyvsp, Rule); \
} while (YYID (0))
/* Nonzero means print parse trace. It is left uninitialized so that
@@ -1138,18 +1156,16 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
static void
-yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, void *tsrm_ls)
+yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
#else
static void
-yydestruct (yymsg, yytype, yyvaluep, tsrm_ls)
+yydestruct (yymsg, yytype, yyvaluep)
const char *yymsg;
int yytype;
YYSTYPE *yyvaluep;
- void *tsrm_ls;
#endif
{
YYUSE (yyvaluep);
- YYUSE (tsrm_ls);
if (!yymsg)
yymsg = "Deleting";
@@ -1179,11 +1195,11 @@ yyparse (YYPARSE_PARAM)
#if (defined __STDC__ || defined __C99__FUNC__ \
|| defined __cplusplus || defined _MSC_VER)
int
-yyparse (void *tsrm_ls)
+yyparse (void)
#else
int
-yyparse (tsrm_ls)
- void *tsrm_ls;
+yyparse ()
+
#endif
#endif
{
@@ -1451,37 +1467,61 @@ yyreduce:
YY_REDUCE_PRINT (yyn);
switch (yyn)
{
- case 3:
+ case 2:
+/* Line 1802 of yacc.c */
+#line 71 "sapi/phpdbg/phpdbg_parser.y"
+ { (yyval) = (yyvsp[(1) - (1)]); }
+ break;
+
+ case 3:
/* Line 1802 of yacc.c */
-#line 67 "sapi/phpdbg/phpdbg_parser.y"
- { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(1) - (1)])); }
+#line 72 "sapi/phpdbg/phpdbg_parser.y"
+ { phpdbg_stack_separate((yyvsp[(1) - (3)]).top); (yyval) = (yyvsp[(3) - (3)]); }
break;
case 5:
/* Line 1802 of yacc.c */
-#line 72 "sapi/phpdbg/phpdbg_parser.y"
- { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(1) - (1)])); }
+#line 77 "sapi/phpdbg/phpdbg_parser.y"
+ { (yyval).top = PHPDBG_G(parser_stack)->top; }
break;
case 6:
/* Line 1802 of yacc.c */
-#line 73 "sapi/phpdbg/phpdbg_parser.y"
- { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(2) - (2)])); }
+#line 78 "sapi/phpdbg/phpdbg_parser.y"
+ { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(1) - (1)])); (yyval).top = PHPDBG_G(parser_stack)->top; }
break;
case 7:
/* Line 1802 of yacc.c */
-#line 77 "sapi/phpdbg/phpdbg_parser.y"
- {
+#line 82 "sapi/phpdbg/phpdbg_parser.y"
+ { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(1) - (1)])); (yyval).top = PHPDBG_G(parser_stack)->top; }
+ break;
+
+ case 8:
+/* Line 1802 of yacc.c */
+#line 83 "sapi/phpdbg/phpdbg_parser.y"
+ { phpdbg_stack_push(PHPDBG_G(parser_stack), &(yyvsp[(2) - (2)])); (yyval).top = PHPDBG_G(parser_stack)->top; }
+ break;
+
+ case 9:
+/* Line 1802 of yacc.c */
+#line 84 "sapi/phpdbg/phpdbg_parser.y"
+ { (yyval) = (yyvsp[(1) - (2)]); }
+ break;
+
+ case 10:
+/* Line 1802 of yacc.c */
+#line 88 "sapi/phpdbg/phpdbg_parser.y"
+ {
(yyval).type = FILE_PARAM;
(yyval).file.name = (yyvsp[(2) - (3)]).str;
(yyval).file.line = (yyvsp[(3) - (3)]).num;
}
break;
- case 8:
+ case 11:
/* Line 1802 of yacc.c */
-#line 82 "sapi/phpdbg/phpdbg_parser.y"
+#line 93 "sapi/phpdbg/phpdbg_parser.y"
{
(yyval).type = NUMERIC_FILE_PARAM;
(yyval).file.name = (yyvsp[(1) - (4)]).str;
@@ -1489,9 +1529,9 @@ yyreduce:
}
break;
- case 9:
+ case 12:
/* Line 1802 of yacc.c */
-#line 87 "sapi/phpdbg/phpdbg_parser.y"
+#line 98 "sapi/phpdbg/phpdbg_parser.y"
{
(yyval).type = FILE_PARAM;
(yyval).file.name = malloc((yyvsp[(1) - (4)]).len + (yyvsp[(2) - (4)]).len + 1);
@@ -1504,9 +1544,9 @@ yyreduce:
}
break;
- case 10:
+ case 13:
/* Line 1802 of yacc.c */
-#line 97 "sapi/phpdbg/phpdbg_parser.y"
+#line 108 "sapi/phpdbg/phpdbg_parser.y"
{
(yyval).type = NUMERIC_FILE_PARAM;
(yyval).file.name = malloc((yyvsp[(1) - (5)]).len + (yyvsp[(2) - (5)]).len + 1);
@@ -1519,132 +1559,138 @@ yyreduce:
}
break;
- case 11:
+ case 14:
/* Line 1802 of yacc.c */
-#line 107 "sapi/phpdbg/phpdbg_parser.y"
- {
+#line 118 "sapi/phpdbg/phpdbg_parser.y"
+ {
(yyval).type = METHOD_PARAM;
(yyval).method.class = (yyvsp[(1) - (3)]).str;
(yyval).method.name = (yyvsp[(3) - (3)]).str;
}
break;
- case 12:
+ case 15:
/* Line 1802 of yacc.c */
-#line 112 "sapi/phpdbg/phpdbg_parser.y"
- {
+#line 123 "sapi/phpdbg/phpdbg_parser.y"
+ {
(yyval).type = NUMERIC_METHOD_PARAM;
(yyval).method.class = (yyvsp[(1) - (5)]).str;
(yyval).method.name = (yyvsp[(3) - (5)]).str;
- (yyval).num = (yyvsp[(5) - (5)]).num;
+ (yyval).num = (yyvsp[(5) - (5)]).num;
}
break;
- case 13:
+ case 16:
/* Line 1802 of yacc.c */
-#line 118 "sapi/phpdbg/phpdbg_parser.y"
+#line 129 "sapi/phpdbg/phpdbg_parser.y"
{
(yyval).type = NUMERIC_FUNCTION_PARAM;
(yyval).str = (yyvsp[(1) - (3)]).str;
(yyval).len = (yyvsp[(1) - (3)]).len;
- (yyval).num = (yyvsp[(3) - (3)]).num;
+ (yyval).num = (yyvsp[(3) - (3)]).num;
}
break;
- case 14:
+ case 17:
/* Line 1802 of yacc.c */
-#line 124 "sapi/phpdbg/phpdbg_parser.y"
+#line 135 "sapi/phpdbg/phpdbg_parser.y"
{
- (yyval).type = COND_PARAM;
+ (yyval).type = COND_PARAM;
(yyval).str = (yyvsp[(2) - (2)]).str;
(yyval).len = (yyvsp[(2) - (2)]).len;
}
break;
- case 15:
+ case 18:
/* Line 1802 of yacc.c */
-#line 129 "sapi/phpdbg/phpdbg_parser.y"
+#line 140 "sapi/phpdbg/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); }
break;
- case 16:
+ case 19:
/* Line 1802 of yacc.c */
-#line 130 "sapi/phpdbg/phpdbg_parser.y"
+#line 141 "sapi/phpdbg/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); }
break;
- case 17:
+ case 20:
/* Line 1802 of yacc.c */
-#line 131 "sapi/phpdbg/phpdbg_parser.y"
+#line 142 "sapi/phpdbg/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); }
break;
- case 18:
+ case 21:
/* Line 1802 of yacc.c */
-#line 132 "sapi/phpdbg/phpdbg_parser.y"
+#line 143 "sapi/phpdbg/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); }
break;
- case 19:
+ case 22:
/* Line 1802 of yacc.c */
-#line 133 "sapi/phpdbg/phpdbg_parser.y"
+#line 144 "sapi/phpdbg/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); }
break;
- case 20:
+ case 23:
/* Line 1802 of yacc.c */
-#line 134 "sapi/phpdbg/phpdbg_parser.y"
+#line 145 "sapi/phpdbg/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); }
break;
- case 21:
+ case 24:
/* Line 1802 of yacc.c */
-#line 135 "sapi/phpdbg/phpdbg_parser.y"
+#line 146 "sapi/phpdbg/phpdbg_parser.y"
{ (yyval) = (yyvsp[(1) - (1)]); }
break;
- case 22:
+ case 25:
/* Line 1802 of yacc.c */
-#line 139 "sapi/phpdbg/phpdbg_parser.y"
- {
- (yyval).type = EVAL_PARAM;
- (yyval).str = (yyvsp[(2) - (2)]).str;
- (yyval).len = (yyvsp[(2) - (2)]).len;
+#line 150 "sapi/phpdbg/phpdbg_parser.y"
+ { PHPDBG_G(req_id) = (yyvsp[(1) - (1)]).num; }
+ break;
+
+ case 27:
+/* Line 1802 of yacc.c */
+#line 155 "sapi/phpdbg/phpdbg_parser.y"
+ {
+ (yyval).type = EVAL_PARAM;
+ (yyval).str = (yyvsp[(3) - (3)]).str;
+ (yyval).len = (yyvsp[(3) - (3)]).len;
}
break;
- case 23:
+ case 28:
/* Line 1802 of yacc.c */
-#line 144 "sapi/phpdbg/phpdbg_parser.y"
- {
- (yyval).type = SHELL_PARAM;
- (yyval).str = (yyvsp[(2) - (2)]).str;
- (yyval).len = (yyvsp[(2) - (2)]).len;
+#line 160 "sapi/phpdbg/phpdbg_parser.y"
+ {
+ (yyval).type = SHELL_PARAM;
+ (yyval).str = (yyvsp[(3) - (3)]).str;
+ (yyval).len = (yyvsp[(3) - (3)]).len;
}
break;
- case 24:
+ case 29:
/* Line 1802 of yacc.c */
-#line 149 "sapi/phpdbg/phpdbg_parser.y"
+#line 165 "sapi/phpdbg/phpdbg_parser.y"
{
(yyval).type = RUN_PARAM;
(yyval).len = 0;
}
break;
- case 25:
+ case 30:
/* Line 1802 of yacc.c */
-#line 153 "sapi/phpdbg/phpdbg_parser.y"
- {
- (yyval).type = RUN_PARAM;
- (yyval).str = (yyvsp[(2) - (2)]).str;
- (yyval).len = (yyvsp[(2) - (2)]).len;
+#line 169 "sapi/phpdbg/phpdbg_parser.y"
+ {
+ (yyval).type = RUN_PARAM;
+ (yyval).str = (yyvsp[(3) - (3)]).str;
+ (yyval).len = (yyvsp[(3) - (3)]).len;
}
break;
/* Line 1802 of yacc.c */
-#line 1648 "sapi/phpdbg/phpdbg_parser.c"
+#line 1694 "sapi/phpdbg/phpdbg_parser.c"
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@@ -1694,7 +1740,7 @@ yyerrlab:
{
++yynerrs;
#if ! YYERROR_VERBOSE
- yyerror (tsrm_ls, YY_("syntax error"));
+ yyerror (YY_("syntax error"));
#else
# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
yyssp, yytoken)
@@ -1721,7 +1767,7 @@ yyerrlab:
yymsgp = yymsg;
}
}
- yyerror (tsrm_ls, yymsgp);
+ yyerror (yymsgp);
if (yysyntax_error_status == 2)
goto yyexhaustedlab;
}
@@ -1745,7 +1791,7 @@ yyerrlab:
else
{
yydestruct ("Error: discarding",
- yytoken, &yylval, tsrm_ls);
+ yytoken, &yylval);
yychar = YYEMPTY;
}
}
@@ -1801,7 +1847,7 @@ yyerrlab1:
yydestruct ("Error: popping",
- yystos[yystate], yyvsp, tsrm_ls);
+ yystos[yystate], yyvsp);
YYPOPSTACK (1);
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
@@ -1838,7 +1884,7 @@ yyabortlab:
| yyexhaustedlab -- memory exhaustion comes here. |
`-------------------------------------------------*/
yyexhaustedlab:
- yyerror (tsrm_ls, YY_("memory exhausted"));
+ yyerror (YY_("memory exhausted"));
yyresult = 2;
/* Fall through. */
#endif
@@ -1850,7 +1896,7 @@ yyreturn:
user semantic actions for why this is necessary. */
yytoken = YYTRANSLATE (yychar);
yydestruct ("Cleanup: discarding lookahead",
- yytoken, &yylval, tsrm_ls);
+ yytoken, &yylval);
}
/* Do not reclaim the symbols of the rule which action triggered
this YYABORT or YYACCEPT. */
@@ -1859,7 +1905,7 @@ yyreturn:
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
- yystos[*yyssp], yyvsp, tsrm_ls);
+ yystos[*yyssp], yyvsp);
YYPOPSTACK (1);
}
#ifndef yyoverflow
@@ -1876,15 +1922,15 @@ yyreturn:
/* Line 2050 of yacc.c */
-#line 160 "sapi/phpdbg/phpdbg_parser.y"
+#line 176 "sapi/phpdbg/phpdbg_parser.y"
-static int yyerror(void ***tsrm_ls, const char *msg) {
- phpdbg_error("Parse Error: %s", msg);
+static int yyerror(const char *msg) {
+ phpdbg_error("command", "type=\"parseerror\" msg=\"%s\"", "Parse Error: %s", msg);
{
const phpdbg_param_t *top = PHPDBG_G(parser_stack);
-
+
while (top) {
phpdbg_param_debug(top, "--> ");
top = top->next;
@@ -1893,12 +1939,12 @@ static int yyerror(void ***tsrm_ls, const char *msg) {
return 0;
}
-int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC) {
- phpdbg_init_lexer(stack, input TSRMLS_CC);
+int phpdbg_do_parse(phpdbg_param_t *stack, char *input) {
+ if (!*input) {
+ return 0;
+ }
-#ifdef ZTS
- return yyparse(TSRMLS_C);
-#else
- return yyparse(NULL);
-#endif
+ phpdbg_init_lexer(stack, input);
+
+ return yyparse();
}
diff --git a/sapi/phpdbg/phpdbg_parser.h b/sapi/phpdbg/phpdbg_parser.h
index da5892ac99..38d3ecbf70 100644
--- a/sapi/phpdbg/phpdbg_parser.h
+++ b/sapi/phpdbg/phpdbg_parser.h
@@ -41,7 +41,7 @@ extern int phpdbg_debug;
#endif
/* "%code requires" blocks. */
/* Line 2060 of yacc.c */
-#line 31 "/Users/Bob/php-src-5.6/sapi/phpdbg/phpdbg_parser.y"
+#line 36 "/Users/Bob/php-src-X/sapi/phpdbg/phpdbg_parser.y"
#include "phpdbg.h"
#ifndef YY_TYPEDEF_YY_SCANNER_T
@@ -69,14 +69,16 @@ typedef void* yyscan_t;
T_COLON = 265,
T_DCOLON = 266,
T_POUND = 267,
- T_PROTO = 268,
- T_DIGITS = 269,
- T_LITERAL = 270,
- T_ADDR = 271,
- T_OPCODE = 272,
- T_ID = 273,
- T_INPUT = 274,
- T_UNEXPECTED = 275
+ T_SEPARATOR = 268,
+ T_PROTO = 269,
+ T_DIGITS = 270,
+ T_LITERAL = 271,
+ T_ADDR = 272,
+ T_OPCODE = 273,
+ T_ID = 274,
+ T_INPUT = 275,
+ T_UNEXPECTED = 276,
+ T_REQ_ID = 277
};
#endif
/* Tokens. */
@@ -90,14 +92,16 @@ typedef void* yyscan_t;
#define T_COLON 265
#define T_DCOLON 266
#define T_POUND 267
-#define T_PROTO 268
-#define T_DIGITS 269
-#define T_LITERAL 270
-#define T_ADDR 271
-#define T_OPCODE 272
-#define T_ID 273
-#define T_INPUT 274
-#define T_UNEXPECTED 275
+#define T_SEPARATOR 268
+#define T_PROTO 269
+#define T_DIGITS 270
+#define T_LITERAL 271
+#define T_ADDR 272
+#define T_OPCODE 273
+#define T_ID 274
+#define T_INPUT 275
+#define T_UNEXPECTED 276
+#define T_REQ_ID 277
@@ -117,7 +121,7 @@ int phpdbg_parse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
-int phpdbg_parse (void *tsrm_ls);
+int phpdbg_parse (void);
#else
int phpdbg_parse ();
#endif
diff --git a/sapi/phpdbg/phpdbg_parser.y b/sapi/phpdbg/phpdbg_parser.y
index 702bf78455..2b8f357763 100644
--- a/sapi/phpdbg/phpdbg_parser.y
+++ b/sapi/phpdbg/phpdbg_parser.y
@@ -1,12 +1,12 @@
%{
-
+
/*
* phpdbg_parser.y
* (from php-src root)
* flex sapi/phpdbg/dev/phpdbg_lexer.l
* bison sapi/phpdbg/dev/phpdbg_parser.y
*/
-
+
#include "phpdbg.h"
#include "phpdbg_cmd.h"
#include "phpdbg_utils.h"
@@ -19,15 +19,20 @@
#include "phpdbg_lexer.h"
#undef yyerror
-static int yyerror(void ***tsrm_ls, const char *msg);
+static int yyerror(const char *msg);
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+#ifdef _MSC_VER
+#define YYMALLOC malloc
+#define YYFREE free
+#endif
+
%}
%pure-parser
%error-verbose
-
+
%code requires {
#include "phpdbg.h"
#ifndef YY_TYPEDEF_YY_SCANNER_T
@@ -36,8 +41,6 @@ typedef void* yyscan_t;
#endif
}
-%parse-param { void *tsrm_ls }
-
%output "sapi/phpdbg/phpdbg_parser.c"
%defines "sapi/phpdbg/phpdbg_parser.h"
@@ -50,7 +53,8 @@ typedef void* yyscan_t;
%token T_STRING "string (some input, perhaps)"
%token T_COLON ": (colon)"
%token T_DCOLON ":: (double colon)"
-%token T_POUND "# (pound sign)"
+%token T_POUND "# (pound sign followed by digits)"
+%token T_SEPARATOR "# (pound sign)"
%token T_PROTO "protocol (file://)"
%token T_DIGITS "digits (numbers)"
%token T_LITERAL "literal (string)"
@@ -59,22 +63,29 @@ typedef void* yyscan_t;
%token T_ID "identifier (command or function name)"
%token T_INPUT "input (input string or data)"
%token T_UNEXPECTED "input"
+%token T_REQ_ID "request id (-r %d)"
%% /* Rules */
input
- : parameters
- | full_expression { phpdbg_stack_push(PHPDBG_G(parser_stack), &$1); }
+ : command { $$ = $1; }
+ | input T_SEPARATOR command { phpdbg_stack_separate($1.top); $$ = $3; }
| /* nothing */
;
+command
+ : parameters { $$.top = PHPDBG_G(parser_stack)->top; }
+ | full_expression { phpdbg_stack_push(PHPDBG_G(parser_stack), &$1); $$.top = PHPDBG_G(parser_stack)->top; }
+ ;
+
parameters
- : parameter { phpdbg_stack_push(PHPDBG_G(parser_stack), &$1); }
- | parameters parameter { phpdbg_stack_push(PHPDBG_G(parser_stack), &$2); }
+ : parameter { phpdbg_stack_push(PHPDBG_G(parser_stack), &$1); $$.top = PHPDBG_G(parser_stack)->top; }
+ | parameters parameter { phpdbg_stack_push(PHPDBG_G(parser_stack), &$2); $$.top = PHPDBG_G(parser_stack)->top; }
+ | parameters req_id { $$ = $1; }
;
parameter
- : T_ID T_COLON T_DIGITS {
+ : T_ID T_COLON T_DIGITS {
$$.type = FILE_PARAM;
$$.file.name = $2.str;
$$.file.line = $3.num;
@@ -104,25 +115,25 @@ parameter
}
$$.file.line = $5.num;
}
- | T_ID T_DCOLON T_ID {
+ | T_ID T_DCOLON T_ID {
$$.type = METHOD_PARAM;
$$.method.class = $1.str;
$$.method.name = $3.str;
}
- | T_ID T_DCOLON T_ID T_POUND T_DIGITS {
+ | T_ID T_DCOLON T_ID T_POUND T_DIGITS {
$$.type = NUMERIC_METHOD_PARAM;
$$.method.class = $1.str;
$$.method.name = $3.str;
- $$.num = $5.num;
+ $$.num = $5.num;
}
| T_ID T_POUND T_DIGITS {
$$.type = NUMERIC_FUNCTION_PARAM;
$$.str = $1.str;
$$.len = $1.len;
- $$.num = $3.num;
+ $$.num = $3.num;
}
| T_IF T_INPUT {
- $$.type = COND_PARAM;
+ $$.type = COND_PARAM;
$$.str = $2.str;
$$.len = $2.len;
}
@@ -135,36 +146,41 @@ parameter
| T_ID { $$ = $1; }
;
+req_id
+ : T_REQ_ID { PHPDBG_G(req_id) = $1.num; }
+ | /* empty */
+;
+
full_expression
- : T_EVAL T_INPUT {
- $$.type = EVAL_PARAM;
- $$.str = $2.str;
- $$.len = $2.len;
+ : T_EVAL req_id T_INPUT {
+ $$.type = EVAL_PARAM;
+ $$.str = $3.str;
+ $$.len = $3.len;
}
- | T_SHELL T_INPUT {
- $$.type = SHELL_PARAM;
- $$.str = $2.str;
- $$.len = $2.len;
+ | T_SHELL req_id T_INPUT {
+ $$.type = SHELL_PARAM;
+ $$.str = $3.str;
+ $$.len = $3.len;
}
- | T_RUN {
+ | T_RUN req_id {
$$.type = RUN_PARAM;
$$.len = 0;
}
- | T_RUN T_INPUT {
- $$.type = RUN_PARAM;
- $$.str = $2.str;
- $$.len = $2.len;
+ | T_RUN req_id T_INPUT {
+ $$.type = RUN_PARAM;
+ $$.str = $3.str;
+ $$.len = $3.len;
}
;
%%
-static int yyerror(void ***tsrm_ls, const char *msg) {
- phpdbg_error("Parse Error: %s", msg);
+static int yyerror(const char *msg) {
+ phpdbg_error("command", "type=\"parseerror\" msg=\"%s\"", "Parse Error: %s", msg);
{
const phpdbg_param_t *top = PHPDBG_G(parser_stack);
-
+
while (top) {
phpdbg_param_debug(top, "--> ");
top = top->next;
@@ -173,12 +189,12 @@ static int yyerror(void ***tsrm_ls, const char *msg) {
return 0;
}
-int phpdbg_do_parse(phpdbg_param_t *stack, char *input TSRMLS_DC) {
- phpdbg_init_lexer(stack, input TSRMLS_CC);
+int phpdbg_do_parse(phpdbg_param_t *stack, char *input) {
+ if (!*input) {
+ return 0;
+ }
-#ifdef ZTS
- return yyparse(TSRMLS_C);
-#else
- return yyparse(NULL);
-#endif
+ phpdbg_init_lexer(stack, input);
+
+ return yyparse();
}
diff --git a/sapi/phpdbg/phpdbg_print.c b/sapi/phpdbg/phpdbg_print.c
index ddd8725337..ccf561148c 100644
--- a/sapi/phpdbg/phpdbg_print.c
+++ b/sapi/phpdbg/phpdbg_print.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -26,80 +26,77 @@
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-#define PHPDBG_PRINT_COMMAND_D(f, h, a, m, l, s) \
- PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[9])
+#define PHPDBG_PRINT_COMMAND_D(f, h, a, m, l, s, flags) \
+ PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[8], flags)
const phpdbg_command_t phpdbg_print_commands[] = {
- PHPDBG_PRINT_COMMAND_D(exec, "print out the instructions in the execution context", 'e', print_exec, NULL, 0),
- PHPDBG_PRINT_COMMAND_D(opline, "print out the instruction in the current opline", 'o', print_opline, NULL, 0),
- PHPDBG_PRINT_COMMAND_D(class, "print out the instructions in the specified class", 'c', print_class, NULL, "s"),
- PHPDBG_PRINT_COMMAND_D(method, "print out the instructions in the specified method", 'm', print_method, NULL, "m"),
- PHPDBG_PRINT_COMMAND_D(func, "print out the instructions in the specified function", 'f', print_func, NULL, "s"),
- PHPDBG_PRINT_COMMAND_D(stack, "print out the instructions in the current stack", 's', print_stack, NULL, 0),
+ PHPDBG_PRINT_COMMAND_D(exec, "print out the instructions in the main execution context", 'e', print_exec, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_PRINT_COMMAND_D(opline, "print out the instruction in the current opline", 'o', print_opline, NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_PRINT_COMMAND_D(class, "print out the instructions in the specified class", 'c', print_class, NULL, "s", PHPDBG_ASYNC_SAFE),
+ PHPDBG_PRINT_COMMAND_D(method, "print out the instructions in the specified method", 'm', print_method, NULL, "m", PHPDBG_ASYNC_SAFE),
+ PHPDBG_PRINT_COMMAND_D(func, "print out the instructions in the specified function", 'f', print_func, NULL, "s", PHPDBG_ASYNC_SAFE),
+ PHPDBG_PRINT_COMMAND_D(stack, "print out the instructions in the current stack", 's', print_stack, NULL, 0, PHPDBG_ASYNC_SAFE),
PHPDBG_END_COMMAND
};
PHPDBG_PRINT(opline) /* {{{ */
{
- if (EG(in_execution) && EG(current_execute_data)) {
- phpdbg_print_opline(EG(current_execute_data), 1 TSRMLS_CC);
+ if (PHPDBG_G(in_execution) && EG(current_execute_data)) {
+ phpdbg_print_opline(EG(current_execute_data), 1);
} else {
- phpdbg_error("Not Executing!");
+ phpdbg_error("inactive", "type=\"execution\"", "Not Executing!");
}
return SUCCESS;
} /* }}} */
-static inline void phpdbg_print_function_helper(zend_function *method TSRMLS_DC) /* {{{ */
+static inline void phpdbg_print_function_helper(zend_function *method) /* {{{ */
{
switch (method->type) {
case ZEND_USER_FUNCTION: {
zend_op_array* op_array = &(method->op_array);
- HashTable vars;
-
+
if (op_array) {
zend_op *opline = &(op_array->opcodes[0]);
- zend_uint opcode = 0,
+ uint32_t opcode = 0,
end = op_array->last-1;
if (method->common.scope) {
- phpdbg_writeln("\tL%d-%d %s::%s() %s",
- op_array->line_start, op_array->line_end,
- method->common.scope->name,
- method->common.function_name,
- op_array->filename ? op_array->filename : "unknown");
+ phpdbg_writeln("printoplineinfo", "type=\"User\" startline=\"%d\" endline=\"%d\" method=\"%s::%s\" file=\"%s\" opline=\"%p\"", "L%d-%d %s::%s() %s - %p + %d ops",
+ op_array->line_start,
+ op_array->line_end,
+ ZSTR_VAL(method->common.scope->name),
+ ZSTR_VAL(method->common.function_name),
+ op_array->filename ? ZSTR_VAL(op_array->filename) : "unknown",
+ opline,
+ op_array->last);
} else {
- phpdbg_writeln("\tL%d-%d %s() %s",
- method->common.function_name ? op_array->line_start : 0,
- method->common.function_name ? op_array->line_end : 0,
- method->common.function_name ? method->common.function_name : "{main}",
- op_array->filename ? op_array->filename : "unknown");
+ phpdbg_writeln("printoplineinfo", "type=\"User\" startline=\"%d\" endline=\"%d\" function=\"%s\" file=\"%s\" opline=\"%p\"", "L%d-%d %s() %s - %p + %d ops",
+ op_array->line_start,
+ op_array->line_end,
+ method->common.function_name ? ZSTR_VAL(method->common.function_name) : "{main}",
+ op_array->filename ? ZSTR_VAL(op_array->filename) : "unknown",
+ opline,
+ op_array->last);
}
- zend_hash_init(&vars, op_array->last, NULL, NULL, 0);
do {
- char *decode = phpdbg_decode_opline(op_array, opline, &vars TSRMLS_CC);
- if (decode != NULL) {
- phpdbg_writeln("\t\tL%u\t%p %-30s %s",
- opline->lineno,
- opline,
- phpdbg_decode_opcode(opline->opcode),
- decode);
- free(decode);
- } else {
- phpdbg_error("\tFailed to decode opline %16p", opline);
- }
+ char *decode = phpdbg_decode_opline(op_array, opline);
+ phpdbg_writeln("print", "line=\"%u\" opnum=\"%u\" op=\"%s\"", " L%-4u #%-5u %s",
+ opline->lineno,
+ opcode,
+ decode);
+ efree(decode);
opline++;
} while (opcode++ < end);
- zend_hash_destroy(&vars);
}
} break;
default: {
if (method->common.scope) {
- phpdbg_writeln("\tInternal %s::%s()", method->common.scope->name, method->common.function_name);
+ phpdbg_writeln("printoplineinfo", "type=\"Internal\" method=\"%s::%s\"", "\tInternal %s::%s()", ZSTR_VAL(method->common.scope->name), ZSTR_VAL(method->common.function_name));
} else {
- phpdbg_writeln("\tInternal %s()", method->common.function_name);
+ phpdbg_writeln("printoplineinfo", "type=\"Internal\" function=\"%s\"", "\tInternal %s()", ZSTR_VAL(method->common.function_name));
}
}
}
@@ -108,17 +105,17 @@ static inline void phpdbg_print_function_helper(zend_function *method TSRMLS_DC)
PHPDBG_PRINT(exec) /* {{{ */
{
if (PHPDBG_G(exec)) {
- if (!PHPDBG_G(ops)) {
- phpdbg_compile(TSRMLS_C);
+ if (!PHPDBG_G(ops) && !(PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER)) {
+ phpdbg_compile();
}
if (PHPDBG_G(ops)) {
- phpdbg_notice("Context %s", PHPDBG_G(exec));
+ phpdbg_notice("printinfo", "file=\"%s\" num=\"%d\"", "Context %s (%d ops)", PHPDBG_G(exec), PHPDBG_G(ops)->last);
- phpdbg_print_function_helper((zend_function*) PHPDBG_G(ops) TSRMLS_CC);
+ phpdbg_print_function_helper((zend_function*) PHPDBG_G(ops));
}
} else {
- phpdbg_error("No execution context set");
+ phpdbg_error("inactive", "type=\"nocontext\"", "No execution context set");
}
return SUCCESS;
@@ -126,25 +123,24 @@ return SUCCESS;
PHPDBG_PRINT(stack) /* {{{ */
{
- zend_op_array *ops = EG(active_op_array);
-
- if (EG(in_execution) && ops) {
+ if (PHPDBG_G(in_execution) && EG(current_execute_data)) {
+ zend_op_array *ops = &EG(current_execute_data)->func->op_array;
if (ops->function_name) {
if (ops->scope) {
- phpdbg_notice("Stack in %s::%s()", ops->scope->name, ops->function_name);
+ phpdbg_notice("printinfo", "method=\"%s::%s\" num=\"%d\"", "Stack in %s::%s() (%d ops)", ZSTR_VAL(ops->scope->name), ZSTR_VAL(ops->function_name), ops->last);
} else {
- phpdbg_notice("Stack in %s()", ops->function_name);
+ phpdbg_notice("printinfo", "function=\"%s\" num=\"%d\"", "Stack in %s() (%d ops)", ZSTR_VAL(ops->function_name), ops->last);
}
} else {
if (ops->filename) {
- phpdbg_notice("Stack in %s", ops->filename);
+ phpdbg_notice("printinfo", "file=\"%s\" num=\"%d\"", "Stack in %s (%d ops)", ZSTR_VAL(ops->filename), ops->last);
} else {
- phpdbg_notice("Stack @ %p", ops);
+ phpdbg_notice("printinfo", "opline=\"%p\" num=\"%d\"", "Stack @ %p (%d ops)", ops, ops->last);
}
}
- phpdbg_print_function_helper((zend_function*) ops TSRMLS_CC);
+ phpdbg_print_function_helper((zend_function*) ops);
} else {
- phpdbg_error("Not Executing!");
+ phpdbg_error("inactive", "type=\"execution\"", "Not Executing!");
}
return SUCCESS;
@@ -152,32 +148,33 @@ PHPDBG_PRINT(stack) /* {{{ */
PHPDBG_PRINT(class) /* {{{ */
{
- zend_class_entry **ce;
+ zend_class_entry *ce;
- if (zend_lookup_class(param->str, param->len, &ce TSRMLS_CC) == SUCCESS) {
- phpdbg_notice("%s %s: %s",
- ((*ce)->type == ZEND_USER_CLASS) ?
+ if (phpdbg_safe_class_lookup(param->str, param->len, &ce) == SUCCESS) {
+ phpdbg_notice("printinfo", "type=\"%s\" flag=\"%s\" class=\"%s\" num=\"%d\"", "%s %s: %s (%d methods)",
+ (ce->type == ZEND_USER_CLASS) ?
"User" : "Internal",
- ((*ce)->ce_flags & ZEND_ACC_INTERFACE) ?
+ (ce->ce_flags & ZEND_ACC_INTERFACE) ?
"Interface" :
- ((*ce)->ce_flags & ZEND_ACC_ABSTRACT) ?
+ (ce->ce_flags & ZEND_ACC_ABSTRACT) ?
"Abstract Class" :
"Class",
- (*ce)->name);
+ ZSTR_VAL(ce->name),
+ zend_hash_num_elements(&ce->function_table));
+
+ phpdbg_xml("<printmethods %r>");
- phpdbg_writeln("Methods (%d):", zend_hash_num_elements(&(*ce)->function_table));
- if (zend_hash_num_elements(&(*ce)->function_table)) {
- HashPosition position;
+ if (zend_hash_num_elements(&ce->function_table)) {
zend_function *method;
- for (zend_hash_internal_pointer_reset_ex(&(*ce)->function_table, &position);
- zend_hash_get_current_data_ex(&(*ce)->function_table, (void**) &method, &position) == SUCCESS;
- zend_hash_move_forward_ex(&(*ce)->function_table, &position)) {
- phpdbg_print_function_helper(method TSRMLS_CC);
- }
+ ZEND_HASH_FOREACH_PTR(&ce->function_table, method) {
+ phpdbg_print_function_helper(method);
+ } ZEND_HASH_FOREACH_END();
}
+
+ phpdbg_xml("</printmethods>");
} else {
- phpdbg_error("The class %s could not be found", param->str);
+ phpdbg_error("print", "type=\"noclass\" class=\"%s\"", "The class %s could not be found", param->str);
}
return SUCCESS;
@@ -185,25 +182,27 @@ PHPDBG_PRINT(class) /* {{{ */
PHPDBG_PRINT(method) /* {{{ */
{
- zend_class_entry **ce;
+ zend_class_entry *ce;
- if (zend_lookup_class(param->method.class, strlen(param->method.class), &ce TSRMLS_CC) == SUCCESS) {
+ if (phpdbg_safe_class_lookup(param->method.class, strlen(param->method.class), &ce) == SUCCESS) {
zend_function *fbc;
- char *lcname = zend_str_tolower_dup(param->method.name, strlen(param->method.name));
+ zend_string *lcname = zend_string_alloc(strlen(param->method.name), 0);
+ zend_str_tolower_copy(ZSTR_VAL(lcname), param->method.name, ZSTR_LEN(lcname));
- if (zend_hash_find(&(*ce)->function_table, lcname, strlen(lcname)+1, (void**)&fbc) == SUCCESS) {
- phpdbg_notice("%s Method %s",
+ if ((fbc = zend_hash_find_ptr(&ce->function_table, lcname))) {
+ phpdbg_notice("printinfo", "type=\"%s\" flags=\"Method\" symbol=\"%s\" num=\"%d\"", "%s Method %s (%d ops)",
(fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal",
- fbc->common.function_name);
+ ZSTR_VAL(fbc->common.function_name),
+ (fbc->type == ZEND_USER_FUNCTION) ? fbc->op_array.last : 0);
- phpdbg_print_function_helper(fbc TSRMLS_CC);
+ phpdbg_print_function_helper(fbc);
} else {
- phpdbg_error("The method %s could not be found", param->method.name);
+ phpdbg_error("print", "type=\"nomethod\" method=\"%s::%s\"", "The method %s::%s could not be found", param->method.class, param->method.name);
}
- efree(lcname);
+ zend_string_release(lcname);
} else {
- phpdbg_error("The class %s could not be found", param->method.class);
+ phpdbg_error("print", "type=\"noclass\" class=\"%s\"", "The class %s could not be found", param->method.class);
}
return SUCCESS;
@@ -215,7 +214,7 @@ PHPDBG_PRINT(func) /* {{{ */
zend_function* fbc;
const char *func_name = param->str;
size_t func_name_len = param->len;
- char *lcname;
+ zend_string *lcname;
/* search active scope if begins with period */
if (func_name[0] == '.') {
if (EG(scope)) {
@@ -224,30 +223,197 @@ PHPDBG_PRINT(func) /* {{{ */
func_table = &EG(scope)->function_table;
} else {
- phpdbg_error("No active class");
+ phpdbg_error("inactive", "type=\"noclasses\"", "No active class");
return SUCCESS;
}
} else if (!EG(function_table)) {
- phpdbg_error("No function table loaded");
+ phpdbg_error("inactive", "type=\"function_table\"", "No function table loaded");
return SUCCESS;
} else {
func_table = EG(function_table);
}
- lcname = zend_str_tolower_dup(func_name, func_name_len);
+ lcname = zend_string_alloc(func_name_len, 0);
+ zend_str_tolower_copy(ZSTR_VAL(lcname), func_name, ZSTR_LEN(lcname));
- if (zend_hash_find(func_table, lcname, strlen(lcname)+1, (void**)&fbc) == SUCCESS) {
- phpdbg_notice("%s %s %s",
- (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal",
- (fbc->common.scope) ? "Method" : "Function",
- fbc->common.function_name);
+ phpdbg_try_access {
+ if ((fbc = zend_hash_find_ptr(func_table, lcname))) {
+ phpdbg_notice("printinfo", "type=\"%s\" flags=\"%s\" symbol=\"%s\" num=\"%d\"", "%s %s %s (%d ops)",
+ (fbc->type == ZEND_USER_FUNCTION) ? "User" : "Internal",
+ (fbc->common.scope) ? "Method" : "Function",
+ ZSTR_VAL(fbc->common.function_name),
+ (fbc->type == ZEND_USER_FUNCTION) ? fbc->op_array.last : 0);
- phpdbg_print_function_helper(fbc TSRMLS_CC);
- } else {
- phpdbg_error("The function %s could not be found", func_name);
- }
+ phpdbg_print_function_helper(fbc);
+ } else {
+ phpdbg_error("print", "type=\"nofunction\" function=\"%s\"", "The function %s could not be found", func_name);
+ }
+ } phpdbg_catch_access {
+ phpdbg_error("signalsegv", "function=\"%.*s\"", "Couldn't fetch function %.*s, invalid data source", (int) func_name_len, func_name);
+ } phpdbg_end_try_access();
efree(lcname);
return SUCCESS;
} /* }}} */
+
+void phpdbg_print_opcodes_main() {
+ phpdbg_out("function name: (null)\n");
+ phpdbg_print_function_helper((zend_function *) PHPDBG_G(ops));
+}
+
+void phpdbg_print_opcodes_function(const char *function, size_t len) {
+ zend_function *func = zend_hash_str_find_ptr(EG(function_table), function, len);
+
+ if (!func) {
+ zend_string *rt_name;
+ ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), rt_name, func) {
+ if (func->type == ZEND_USER_FUNCTION && *rt_name->val == '\0') {
+ if (func->op_array.function_name->len == len && !zend_binary_strcasecmp(function, len, func->op_array.function_name->val, func->op_array.function_name->len)) {
+ phpdbg_print_opcodes_function(rt_name->val, rt_name->len);
+ }
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ return;
+ }
+
+ phpdbg_out("function name: %.*s\n", ZSTR_LEN(func->op_array.function_name), ZSTR_VAL(func->op_array.function_name));
+ phpdbg_print_function_helper(func);
+}
+
+static void phpdbg_print_opcodes_method_ce(zend_class_entry *ce, const char *function) {
+ zend_function *func;
+
+ if (ce->type != ZEND_USER_CLASS) {
+ phpdbg_out("function name: %s::%s (internal)\n", ce->name->val, function);
+ return;
+ }
+
+ if (!(func = zend_hash_str_find_ptr(&ce->function_table, function, strlen(function)))) {
+ return;
+ }
+
+ phpdbg_out("function name: %s::%s\n", ce->name->val, function);
+ phpdbg_print_function_helper(func);
+}
+
+void phpdbg_print_opcodes_method(const char *class, const char *function) {
+ zend_class_entry *ce;
+
+ if (phpdbg_safe_class_lookup(class, strlen(class), &ce) != SUCCESS) {
+ zend_string *rt_name;
+ ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), rt_name, ce) {
+ if (ce->type == ZEND_USER_CLASS && *rt_name->val == '\0') {
+ if (ce->name->len == strlen(class) && !zend_binary_strcasecmp(class, strlen(class), ce->name->val, ce->name->len)) {
+ phpdbg_print_opcodes_method_ce(ce, function);
+ }
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ return;
+ }
+
+ phpdbg_print_opcodes_method_ce(ce, function);
+}
+
+static void phpdbg_print_opcodes_ce(zend_class_entry *ce) {
+ zend_function *method;
+ zend_string *method_name;
+ zend_bool first = 1;
+
+ phpdbg_out("%s %s: %s\n",
+ (ce->type == ZEND_USER_CLASS) ?
+ "user" : "internal",
+ (ce->ce_flags & ZEND_ACC_INTERFACE) ?
+ "interface" :
+ (ce->ce_flags & ZEND_ACC_ABSTRACT) ?
+ "abstract Class" :
+ "class",
+ ZSTR_VAL(ce->name));
+
+ if (ce->type != ZEND_USER_CLASS) {
+ return;
+ }
+
+ phpdbg_out("%d methods: ", zend_hash_num_elements(&ce->function_table));
+ ZEND_HASH_FOREACH_PTR(&ce->function_table, method) {
+ if (first) {
+ first = 0;
+ } else {
+ phpdbg_out(", ");
+ }
+ phpdbg_out("%s", ZSTR_VAL(method->common.function_name));
+ } ZEND_HASH_FOREACH_END();
+ if (first) {
+ phpdbg_out("-");
+ }
+ phpdbg_out("\n");
+
+ ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->function_table, method_name, method) {
+ phpdbg_out("\nfunction name: %s\n", method_name);
+ phpdbg_print_function_helper(method);
+ } ZEND_HASH_FOREACH_END();
+}
+
+void phpdbg_print_opcodes_class(const char *class) {
+ zend_class_entry *ce;
+
+ if (phpdbg_safe_class_lookup(class, strlen(class), &ce) != SUCCESS) {
+ zend_string *rt_name;
+ ZEND_HASH_FOREACH_STR_KEY_PTR(EG(class_table), rt_name, ce) {
+ if (ce->type == ZEND_USER_CLASS && *rt_name->val == '\0') {
+ if (ce->name->len == strlen(class) && !zend_binary_strcasecmp(class, strlen(class), ce->name->val, ce->name->len)) {
+ phpdbg_print_opcodes_ce(ce);
+ }
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ return;
+ }
+
+ phpdbg_print_opcodes_ce(ce);
+}
+
+PHPDBG_API void phpdbg_print_opcodes(char *function)
+{
+ if (function == NULL) {
+ phpdbg_print_opcodes_main();
+ } else if (function[0] == '*' && function[1] == 0) {
+ /* all */
+ zend_string *name;
+ zend_function *func;
+ zend_class_entry *ce;
+
+ phpdbg_print_opcodes_main();
+
+ ZEND_HASH_FOREACH_STR_KEY_PTR(EG(function_table), name, func) {
+ if (func->type == ZEND_USER_FUNCTION) {
+ phpdbg_out("\n");
+ phpdbg_print_opcodes_function(ZSTR_VAL(name), ZSTR_LEN(name));
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ ZEND_HASH_FOREACH_PTR(EG(class_table), ce) {
+ if (ce->type == ZEND_USER_CLASS) {
+ phpdbg_out("\n\n");
+ phpdbg_print_opcodes_ce(ce);
+ }
+ } ZEND_HASH_FOREACH_END();
+ } else {
+ function = zend_str_tolower_dup(function, strlen(function));
+
+ if (strstr(function, "::") == NULL) {
+ phpdbg_print_opcodes_function(function, strlen(function));
+ } else {
+ char *method_name, *class_name = strtok(function, "::");
+ if ((method_name = strtok(NULL, "::")) == NULL) {
+ phpdbg_print_opcodes_class(class_name);
+ } else {
+ phpdbg_print_opcodes_method(class_name, method_name);
+ }
+ }
+
+ efree(function);
+ }
+}
diff --git a/sapi/phpdbg/phpdbg_print.h b/sapi/phpdbg/phpdbg_print.h
index a331cb47d9..029c15946f 100644
--- a/sapi/phpdbg/phpdbg_print.h
+++ b/sapi/phpdbg/phpdbg_print.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -35,6 +35,8 @@ PHPDBG_PRINT(method);
PHPDBG_PRINT(func);
PHPDBG_PRINT(stack);
+PHPDBG_API void phpdbg_print_opcodes(char *function);
+
extern const phpdbg_command_t phpdbg_print_commands[];
#endif /* PHPDBG_PRINT_H */
diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c
index 48fabca3f9..50971b25ec 100644
--- a/sapi/phpdbg/phpdbg_prompt.c
+++ b/sapi/phpdbg/phpdbg_prompt.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -22,12 +22,16 @@
#include <string.h>
#include "zend.h"
#include "zend_compile.h"
+#include "zend_exceptions.h"
+#include "zend_vm.h"
+#include "zend_generators.h"
+#include "zend_interfaces.h"
#include "phpdbg.h"
+
#include "phpdbg_help.h"
#include "phpdbg_print.h"
#include "phpdbg_info.h"
#include "phpdbg_break.h"
-#include "phpdbg_bp.h"
#include "phpdbg_opcode.h"
#include "phpdbg_list.h"
#include "phpdbg_utils.h"
@@ -37,253 +41,300 @@
#include "phpdbg_frame.h"
#include "phpdbg_lexer.h"
#include "phpdbg_parser.h"
+#include "phpdbg_wait.h"
+#include "phpdbg_eol.h"
+
+#if ZEND_VM_KIND != ZEND_VM_KIND_CALL
+#error "phpdbg can only be built with CALL zend vm kind"
+#endif
+
+ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+extern int phpdbg_startup_run;
+
+#ifdef HAVE_LIBDL
+#ifdef PHP_WIN32
+#include "win32/param.h"
+#include "win32/winutil.h"
+#define GET_DL_ERROR() php_win_err()
+#elif defined(NETWARE)
+#include <sys/param.h>
+#define GET_DL_ERROR() dlerror()
+#else
+#include <sys/param.h>
+#define GET_DL_ERROR() DL_ERROR()
+#endif
+#endif
/* {{{ command declarations */
const phpdbg_command_t phpdbg_prompt_commands[] = {
- PHPDBG_COMMAND_D(exec, "set execution context", 'e', NULL, "s"),
- PHPDBG_COMMAND_D(step, "step through execution", 's', NULL, 0),
- PHPDBG_COMMAND_D(continue,"continue execution", 'c', NULL, 0),
- PHPDBG_COMMAND_D(run, "attempt execution", 'r', NULL, "|s"),
- PHPDBG_COMMAND_D(ev, "evaluate some code", 0, NULL, "i"),
- PHPDBG_COMMAND_D(until, "continue past the current line", 'u', NULL, 0),
- PHPDBG_COMMAND_D(finish, "continue past the end of the stack", 'F', NULL, 0),
- PHPDBG_COMMAND_D(leave, "continue until the end of the stack", 'L', NULL, 0),
- PHPDBG_COMMAND_D(print, "print something", 'p', phpdbg_print_commands, 0),
- PHPDBG_COMMAND_D(break, "set breakpoint", 'b', phpdbg_break_commands, "|*c"),
- PHPDBG_COMMAND_D(back, "show trace", 't', NULL, "|n"),
- PHPDBG_COMMAND_D(frame, "switch to a frame", 'f', NULL, "|n"),
- PHPDBG_COMMAND_D(list, "lists some code", 'l', phpdbg_list_commands, "*"),
- PHPDBG_COMMAND_D(info, "displays some informations", 'i', phpdbg_info_commands, "s"),
- PHPDBG_COMMAND_D(clean, "clean the execution environment", 'X', NULL, 0),
- PHPDBG_COMMAND_D(clear, "clear breakpoints", 'C', NULL, 0),
- PHPDBG_COMMAND_D(help, "show help menu", 'h', phpdbg_help_commands, "|s"),
- PHPDBG_COMMAND_D(set, "set phpdbg configuration", 'S', phpdbg_set_commands, "s"),
- PHPDBG_COMMAND_D(register,"register a function", 'R', NULL, "s"),
- PHPDBG_COMMAND_D(source, "execute a phpdbginit", '<', NULL, "s"),
- PHPDBG_COMMAND_D(export, "export breaks to a .phpdbginit script", '>', NULL, "s"),
- PHPDBG_COMMAND_D(sh, "shell a command", 0, NULL, "i"),
- PHPDBG_COMMAND_D(quit, "exit phpdbg", 'q', NULL, 0),
- PHPDBG_COMMAND_D(watch, "set watchpoint", 'w', phpdbg_watch_commands, "|ss"),
+ PHPDBG_COMMAND_D(exec, "set execution context", 'e', NULL, "s", 0),
+ PHPDBG_COMMAND_D(step, "step through execution", 's', NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_COMMAND_D(continue,"continue execution", 'c', NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_COMMAND_D(run, "attempt execution", 'r', NULL, "|s", 0),
+ PHPDBG_COMMAND_D(ev, "evaluate some code", 0 , NULL, "i", PHPDBG_ASYNC_SAFE), /* restricted ASYNC_SAFE */
+ PHPDBG_COMMAND_D(until, "continue past the current line", 'u', NULL, 0, 0),
+ PHPDBG_COMMAND_D(finish, "continue past the end of the stack", 'F', NULL, 0, 0),
+ PHPDBG_COMMAND_D(leave, "continue until the end of the stack", 'L', NULL, 0, 0),
+ PHPDBG_COMMAND_D(print, "print something", 'p', phpdbg_print_commands, "|*c", 0),
+ PHPDBG_COMMAND_D(break, "set breakpoint", 'b', phpdbg_break_commands, "|*c", 0),
+ PHPDBG_COMMAND_D(back, "show trace", 't', NULL, "|n", PHPDBG_ASYNC_SAFE),
+ PHPDBG_COMMAND_D(frame, "switch to a frame", 'f', NULL, "|n", PHPDBG_ASYNC_SAFE),
+ PHPDBG_COMMAND_D(list, "lists some code", 'l', phpdbg_list_commands, "*", PHPDBG_ASYNC_SAFE),
+ PHPDBG_COMMAND_D(info, "displays some informations", 'i', phpdbg_info_commands, "|s", PHPDBG_ASYNC_SAFE),
+ PHPDBG_COMMAND_D(clean, "clean the execution environment", 'X', NULL, 0, 0),
+ PHPDBG_COMMAND_D(clear, "clear breakpoints", 'C', NULL, 0, 0),
+ PHPDBG_COMMAND_D(help, "show help menu", 'h', phpdbg_help_commands, "|s", PHPDBG_ASYNC_SAFE),
+ PHPDBG_COMMAND_D(set, "set phpdbg configuration", 'S', phpdbg_set_commands, "s", PHPDBG_ASYNC_SAFE),
+ PHPDBG_COMMAND_D(register,"register a function", 'R', NULL, "s", 0),
+ PHPDBG_COMMAND_D(source, "execute a phpdbginit", '<', NULL, "s", 0),
+ PHPDBG_COMMAND_D(export, "export breaks to a .phpdbginit script", '>', NULL, "s", PHPDBG_ASYNC_SAFE),
+ PHPDBG_COMMAND_D(sh, "shell a command", 0 , NULL, "i", 0),
+ PHPDBG_COMMAND_D(quit, "exit phpdbg", 'q', NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_COMMAND_D(wait, "wait for other process", 'W', NULL, 0, 0),
+ PHPDBG_COMMAND_D(watch, "set watchpoint", 'w', phpdbg_watch_commands, "|ss", 0),
+ PHPDBG_COMMAND_D(next, "step over next line", 'n', NULL, 0, PHPDBG_ASYNC_SAFE),
+ PHPDBG_COMMAND_D(eol, "set EOL", 'E', NULL, "|s", 0),
PHPDBG_END_COMMAND
}; /* }}} */
-ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-
-static inline int phpdbg_call_register(phpdbg_param_t *stack TSRMLS_DC) /* {{{ */
+static inline int phpdbg_call_register(phpdbg_param_t *stack) /* {{{ */
{
phpdbg_param_t *name = NULL;
if (stack->type == STACK_PARAM) {
+ char *lc_name;
+
name = stack->next;
-
+
if (!name || name->type != STR_PARAM) {
return FAILURE;
}
-
- if (zend_hash_exists(
- &PHPDBG_G(registered), name->str, name->len+1)) {
- zval fname, *fretval;
- zend_fcall_info fci;
+ lc_name = zend_str_tolower_dup(name->str, name->len);
- ZVAL_STRINGL(&fname, name->str, name->len, 1);
+ if (zend_hash_str_exists(&PHPDBG_G(registered), lc_name, name->len)) {
+ zval fretval;
+ zend_fcall_info fci;
memset(&fci, 0, sizeof(zend_fcall_info));
+ ZVAL_STRINGL(&fci.function_name, lc_name, name->len);
fci.size = sizeof(zend_fcall_info);
fci.function_table = &PHPDBG_G(registered);
- fci.function_name = &fname;
- fci.symbol_table = EG(active_symbol_table);
- fci.object_ptr = NULL;
- fci.retval_ptr_ptr = &fretval;
+ fci.symbol_table = zend_rebuild_symbol_table();
+ fci.object = NULL;
+ fci.retval = &fretval;
fci.no_separation = 1;
if (name->next) {
zval params;
phpdbg_param_t *next = name->next;
-
+
array_init(&params);
while (next) {
char *buffered = NULL;
-
+
switch (next->type) {
case OP_PARAM:
case COND_PARAM:
case STR_PARAM:
- add_next_index_stringl(
- &params,
- next->str,
- next->len, 1);
+ add_next_index_stringl(&params, next->str, next->len);
break;
-
+
case NUMERIC_PARAM:
add_next_index_long(&params, next->num);
break;
-
+
case METHOD_PARAM:
- spprintf(&buffered, 0, "%s::%s",
- next->method.class, next->method.name);
- add_next_index_string(&params, buffered, 0);
+ spprintf(&buffered, 0, "%s::%s", next->method.class, next->method.name);
+ add_next_index_string(&params, buffered);
break;
-
+
case NUMERIC_METHOD_PARAM:
- spprintf(&buffered, 0, "%s::%s#%ld",
- next->method.class, next->method.name, next->num);
- add_next_index_string(&params, buffered, 0);
+ spprintf(&buffered, 0, "%s::%s#%ld", next->method.class, next->method.name, next->num);
+ add_next_index_string(&params, buffered);
break;
-
+
case NUMERIC_FUNCTION_PARAM:
- spprintf(&buffered, 0, "%s#%ld",
- next->str, next->num);
- add_next_index_string(&params, buffered, 0);
+ spprintf(&buffered, 0, "%s#%ld", next->str, next->num);
+ add_next_index_string(&params, buffered);
break;
-
+
case FILE_PARAM:
- spprintf(&buffered, 0, "%s:%ld",
- next->file.name, next->file.line);
- add_next_index_string(&params, buffered, 0);
+ spprintf(&buffered, 0, "%s:%ld", next->file.name, next->file.line);
+ add_next_index_string(&params, buffered);
break;
-
+
case NUMERIC_FILE_PARAM:
- spprintf(&buffered, 0, "%s:#%ld",
- next->file.name, next->file.line);
- add_next_index_string(&params, buffered, 0);
+ spprintf(&buffered, 0, "%s:#%ld", next->file.name, next->file.line);
+ add_next_index_string(&params, buffered);
break;
-
+
default: {
/* not yet */
}
}
-
- next = next->next;
+
+ next = next->next;
}
- zend_fcall_info_args(&fci, &params TSRMLS_CC);
+ zend_fcall_info_args(&fci, &params);
} else {
fci.params = NULL;
fci.param_count = 0;
}
- phpdbg_debug(
- "created %d params from arguments",
- fci.param_count);
+ phpdbg_activate_err_buf(0);
+ phpdbg_free_err_buf();
- zend_call_function(&fci, NULL TSRMLS_CC);
+ phpdbg_debug("created %d params from arguments", fci.param_count);
- if (fretval) {
- zend_print_zval_r(
- fretval, 0 TSRMLS_CC);
- phpdbg_writeln(EMPTY);
+ if (zend_call_function(&fci, NULL) == SUCCESS) {
+ zend_print_zval_r(&fretval, 0);
+ phpdbg_out("\n");
+ zval_ptr_dtor(&fretval);
}
- zval_dtor(&fname);
+ zval_dtor(&fci.function_name);
+ efree(lc_name);
return SUCCESS;
- }
+ }
+
+ efree(lc_name);
}
return FAILURE;
} /* }}} */
-void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC) /* {{{ */
-{
- struct stat sb;
-
- if (init_file && VCWD_STAT(init_file, &sb) != -1) {
- FILE *fp = fopen(init_file, "r");
- if (fp) {
- int line = 1;
+struct phpdbg_init_state {
+ int line;
+ zend_bool in_code;
+ char *code;
+ size_t code_len;
+ const char *init_file;
+};
- char cmd[PHPDBG_MAX_CMD];
- size_t cmd_len = 0L;
- char *code = NULL;
- size_t code_len = 0L;
- zend_bool in_code = 0;
+static void phpdbg_line_init(char *cmd, struct phpdbg_init_state *state) {
+ size_t cmd_len = strlen(cmd);
- while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) {
- cmd_len = strlen(cmd)-1;
-
- while (cmd_len > 0L && isspace(cmd[cmd_len-1]))
- cmd_len--;
-
- cmd[cmd_len] = '\0';
-
- if (*cmd && cmd_len > 0L && cmd[0] != '#') {
- if (cmd_len == 2) {
- if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) {
- in_code = 1;
- goto next_line;
- } else {
- if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) {
- in_code = 0;
- code[code_len] = '\0';
- {
- zend_eval_stringl(
- code, code_len, NULL, "phpdbginit code" TSRMLS_CC);
- }
- free(code);
- code = NULL;
- goto next_line;
- }
- }
- }
+ state->line++;
- if (in_code) {
- if (code == NULL) {
- code = malloc(cmd_len + 1);
- } else code = realloc(code, code_len + cmd_len + 1);
+ while (cmd_len > 0L && isspace(cmd[cmd_len-1])) {
+ cmd_len--;
+ }
- if (code) {
- memcpy(
- &code[code_len], cmd, cmd_len);
- code_len += cmd_len;
- }
- goto next_line;
- }
+ cmd[cmd_len] = '\0';
+
+ if (*cmd && cmd_len > 0L && cmd[0] != '#') {
+ if (cmd_len == 2) {
+ if (memcmp(cmd, "<:", sizeof("<:")-1) == SUCCESS) {
+ state->in_code = 1;
+ return;
+ } else {
+ if (memcmp(cmd, ":>", sizeof(":>")-1) == SUCCESS) {
+ state->in_code = 0;
+ state->code[state->code_len] = '\0';
+ zend_eval_stringl(state->code, state->code_len, NULL, "phpdbginit code");
+ free(state->code);
+ state->code = NULL;
+ return;
+ }
+ }
+ }
+
+ if (state->in_code) {
+ if (state->code == NULL) {
+ state->code = malloc(cmd_len + 1);
+ } else {
+ state->code = realloc(state->code, state->code_len + cmd_len + 1);
+ }
+
+ if (state->code) {
+ memcpy(&state->code[state->code_len], cmd, cmd_len);
+ state->code_len += cmd_len;
+ }
+
+ return;
+ }
+
+ zend_try {
+ char *input = phpdbg_read_input(cmd);
+ phpdbg_param_t stack;
+
+ phpdbg_init_param(&stack, STACK_PARAM);
- {
- char *why = NULL;
- char *input = phpdbg_read_input(cmd TSRMLS_CC);
- phpdbg_param_t stack;
-
- phpdbg_init_param(&stack, STACK_PARAM);
-
- if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) {
- switch (phpdbg_stack_execute(&stack, &why TSRMLS_CC)) {
- case FAILURE:
-// if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
- if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) {
- phpdbg_error(
- "Unrecognized command in %s:%d: %s, %s!",
- init_file, line, input, why);
- }
-// }
- break;
+ phpdbg_activate_err_buf(1);
+
+ if (phpdbg_do_parse(&stack, input) <= 0) {
+ switch (phpdbg_stack_execute(&stack, 1 /* allow_async_unsafe == 1 */)) {
+ case FAILURE:
+ phpdbg_activate_err_buf(0);
+ if (phpdbg_call_register(&stack) == FAILURE) {
+ if (state->init_file) {
+ phpdbg_output_err_buf("initfailure", "%b file=\"%s\" line=\"%d\" input=\"%s\"", "Unrecognized command in %s:%d: %s, %b!", state->init_file, state->line, input);
+ } else {
+ phpdbg_output_err_buf("initfailure", "%b line=\"%d\" input=\"%s\"", "Unrecognized command on line %d: %s, %b!", state->line, input);
}
}
+ break;
+ }
+ }
- if (why) {
- free(why);
- why = NULL;
- }
+ phpdbg_activate_err_buf(0);
+ phpdbg_free_err_buf();
- phpdbg_stack_free(&stack);
- phpdbg_destroy_input(&input TSRMLS_CC);
- }
- }
-next_line:
- line++;
+ phpdbg_stack_free(&stack);
+ phpdbg_destroy_input(&input);
+ } zend_catch {
+ PHPDBG_G(flags) &= ~(PHPDBG_IS_RUNNING | PHPDBG_IS_CLEANING);
+ if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) {
+ zend_bailout();
}
+ } zend_end_try();
+ }
+
+}
+
+void phpdbg_string_init(char *buffer) {
+ struct phpdbg_init_state state = {0};
+ char *str = strtok(buffer, "\n");
+
+ while (str) {
+ phpdbg_line_init(str, &state);
+
+ str = strtok(NULL, "\n");
+ }
+
+ if (state.code) {
+ free(state.code);
+ }
+}
+
+void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init) /* {{{ */
+{
+ zend_stat_t sb;
+
+ if (init_file && VCWD_STAT(init_file, &sb) != -1) {
+ FILE *fp = fopen(init_file, "r");
+ if (fp) {
+ char cmd[PHPDBG_MAX_CMD];
+ struct phpdbg_init_state state = {0};
- if (code) {
- free(code);
+ state.init_file = init_file;
+
+ while (fgets(cmd, PHPDBG_MAX_CMD, fp) != NULL) {
+ phpdbg_line_init(cmd, &state);
+ }
+
+ if (state.code) {
+ free(state.code);
}
fclose(fp);
} else {
- phpdbg_error(
- "Failed to open %s for initialization", init_file);
+ phpdbg_error("initfailure", "type=\"openfile\" file=\"%s\"", "Failed to open %s for initialization", init_file);
}
if (free_init) {
@@ -292,13 +343,16 @@ next_line:
}
} /* }}} */
-void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC) /* {{{ */
+void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default) /* {{{ */
{
if (!init_file && use_default) {
char *scan_dir = getenv("PHP_INI_SCAN_DIR");
+ char *sys_ini;
int i;
- phpdbg_try_file_init(PHPDBG_STRL(PHP_CONFIG_FILE_PATH "/" PHPDBG_INIT_FILENAME), 0 TSRMLS_CC);
+ ZEND_IGNORE_VALUE(asprintf(&sys_ini, "%s/" PHPDBG_INIT_FILENAME, PHP_CONFIG_FILE_PATH));
+ phpdbg_try_file_init(sys_ini, strlen(sys_ini), 0);
+ free(sys_ini);
if (!scan_dir) {
scan_dir = PHP_CONFIG_FILE_SCAN_DIR;
@@ -315,93 +369,135 @@ void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TS
scan_dir[i] = 0;
}
- asprintf(
- &init_file, "%s/%s", scan_dir, PHPDBG_INIT_FILENAME);
- phpdbg_try_file_init(init_file, strlen(init_file), 1 TSRMLS_CC);
+ ZEND_IGNORE_VALUE(asprintf(&init_file, "%s/%s", scan_dir, PHPDBG_INIT_FILENAME));
+ phpdbg_try_file_init(init_file, strlen(init_file), 1);
if (i == -1) {
break;
}
scan_dir += i + 1;
}
- phpdbg_try_file_init(PHPDBG_STRL(PHPDBG_INIT_FILENAME), 0 TSRMLS_CC);
+ phpdbg_try_file_init(PHPDBG_STRL(PHPDBG_INIT_FILENAME), 0);
} else {
- phpdbg_try_file_init(init_file, init_file_len, 1 TSRMLS_CC);
+ phpdbg_try_file_init(init_file, init_file_len, 1);
}
}
+/* }}} */
+
+void phpdbg_clean(zend_bool full) /* {{{ */
+{
+ /* this is implicitly required */
+ if (PHPDBG_G(ops)) {
+ destroy_op_array(PHPDBG_G(ops));
+ efree(PHPDBG_G(ops));
+ PHPDBG_G(ops) = NULL;
+ }
+
+ if (full) {
+ PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
+ }
+} /* }}} */
PHPDBG_COMMAND(exec) /* {{{ */
{
- struct stat sb;
+ zend_stat_t sb;
if (VCWD_STAT(param->str, &sb) != FAILURE) {
if (sb.st_mode & (S_IFREG|S_IFLNK)) {
- char *res = phpdbg_resolve_path(param->str TSRMLS_CC);
+ char *res = phpdbg_resolve_path(param->str);
size_t res_len = strlen(res);
if ((res_len != PHPDBG_G(exec_len)) || (memcmp(res, PHPDBG_G(exec), res_len) != SUCCESS)) {
+ if (PHPDBG_G(in_execution)) {
+ if (phpdbg_ask_user_permission("Do you really want to stop execution to set a new execution context?") == FAILURE) {
+ return FAILURE;
+ }
+ }
if (PHPDBG_G(exec)) {
- phpdbg_notice("Unsetting old execution context: %s", PHPDBG_G(exec));
+ phpdbg_notice("exec", "type=\"unset\" context=\"%s\"", "Unsetting old execution context: %s", PHPDBG_G(exec));
efree(PHPDBG_G(exec));
PHPDBG_G(exec) = NULL;
PHPDBG_G(exec_len) = 0L;
}
if (PHPDBG_G(ops)) {
- phpdbg_notice("Destroying compiled opcodes");
- phpdbg_clean(0 TSRMLS_CC);
+ phpdbg_notice("exec", "type=\"unsetops\"", "Destroying compiled opcodes");
+ phpdbg_clean(0);
}
PHPDBG_G(exec) = res;
PHPDBG_G(exec_len) = res_len;
-
+
+ VCWD_CHDIR_FILE(res);
+
*SG(request_info).argv = PHPDBG_G(exec);
- php_hash_environment(TSRMLS_C);
+ php_build_argv(NULL, &PG(http_globals)[TRACK_VARS_SERVER]);
- phpdbg_notice("Set execution context: %s", PHPDBG_G(exec));
+ phpdbg_notice("exec", "type=\"set\" context=\"%s\"", "Set execution context: %s", PHPDBG_G(exec));
- if (phpdbg_compile(TSRMLS_C) == FAILURE) {
- phpdbg_error("Failed to compile %s", PHPDBG_G(exec));
+ if (PHPDBG_G(in_execution)) {
+ phpdbg_clean(1);
+ return SUCCESS;
}
+
+ phpdbg_compile();
} else {
- phpdbg_notice("Execution context not changed");
+ phpdbg_notice("exec", "type=\"unchanged\"", "Execution context not changed");
}
} else {
- phpdbg_error("Cannot use %s as execution context, not a valid file or symlink", param->str);
+ phpdbg_error("exec", "type=\"invalid\" context=\"%s\"", "Cannot use %s as execution context, not a valid file or symlink", param->str);
}
} else {
- phpdbg_error("Cannot stat %s, ensure the file exists", param->str);
+ phpdbg_error("exec", "type=\"notfound\" context=\"%s\"", "Cannot stat %s, ensure the file exists", param->str);
}
return SUCCESS;
} /* }}} */
-int phpdbg_compile(TSRMLS_D) /* {{{ */
+int phpdbg_compile(void) /* {{{ */
{
zend_file_handle fh;
+ char *buf;
+ size_t len;
if (!PHPDBG_G(exec)) {
- phpdbg_error("No execution context");
- return SUCCESS;
- }
-
- if (EG(in_execution)) {
- phpdbg_error("Cannot compile while in execution");
+ phpdbg_error("inactive", "type=\"nocontext\"", "No execution context");
return FAILURE;
}
- phpdbg_notice("Attempting compilation of %s", PHPDBG_G(exec));
+ if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh, USE_PATH|STREAM_OPEN_FOR_INCLUDE) == SUCCESS && zend_stream_fixup(&fh, &buf, &len) == SUCCESS) {
+ /* Skip #! line */
+ if (len >= 3 && buf[0] == '#' && buf[1] == '!') {
+ char *end = buf + len;
+ do {
+ switch (fh.handle.stream.mmap.buf++[0]) {
+ case '\r':
+ if (fh.handle.stream.mmap.buf[0] == '\n') {
+ fh.handle.stream.mmap.buf++;
+ }
+ case '\n':
+ CG(start_lineno) = 2;
+ fh.handle.stream.mmap.len -= fh.handle.stream.mmap.buf - buf;
+ end = fh.handle.stream.mmap.buf;
+ }
+ } while (fh.handle.stream.mmap.buf + 1 < end);
+ }
+
+ PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE);
- if (php_stream_open_for_zend_ex(PHPDBG_G(exec), &fh,
- USE_PATH|STREAM_OPEN_FOR_INCLUDE TSRMLS_CC) == SUCCESS) {
+ fh.handle.stream.mmap.buf = buf;
+ fh.handle.stream.mmap.len = len;
+ zend_destroy_file_handle(&fh);
+ if (EG(exception)) {
+ zend_exception_error(EG(exception), E_ERROR);
+ zend_bailout();
+ }
- PHPDBG_G(ops) = zend_compile_file(&fh, ZEND_INCLUDE TSRMLS_CC);
- zend_destroy_file_handle(&fh TSRMLS_CC);
+ phpdbg_notice("compile", "context=\"%s\"", "Successful compilation of %s", PHPDBG_G(exec));
- phpdbg_notice("Success");
return SUCCESS;
} else {
- phpdbg_error("Could not open file %s", PHPDBG_G(exec));
+ phpdbg_error("compile", "type=\"openfailure\" context=\"%s\"", "Could not open file %s", PHPDBG_G(exec));
}
return FAILURE;
@@ -409,7 +505,7 @@ int phpdbg_compile(TSRMLS_D) /* {{{ */
PHPDBG_COMMAND(step) /* {{{ */
{
- if (EG(in_execution)) {
+ if (PHPDBG_G(in_execution)) {
PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
}
@@ -421,62 +517,81 @@ PHPDBG_COMMAND(continue) /* {{{ */
return PHPDBG_NEXT;
} /* }}} */
+int phpdbg_skip_line_helper() /* {{{ */ {
+ const zend_op_array *op_array = &EG(current_execute_data)->func->op_array;
+ const zend_op *opline = op_array->opcodes;
+
+ PHPDBG_G(flags) |= PHPDBG_IN_UNTIL;
+ PHPDBG_G(seek_ex) = EG(current_execute_data);
+ do {
+ if (opline->lineno != EG(current_execute_data)->opline->lineno
+ || opline->opcode == ZEND_RETURN
+ || opline->opcode == ZEND_FAST_RET
+ || opline->opcode == ZEND_GENERATOR_RETURN
+ || opline->opcode == ZEND_EXIT
+ || opline->opcode == ZEND_YIELD
+ || opline->opcode == ZEND_YIELD_FROM
+ ) {
+ zend_hash_index_update_ptr(&PHPDBG_G(seek), (zend_ulong) opline, (void *) opline);
+ }
+ } while (++opline < op_array->opcodes + op_array->last);
+
+ return PHPDBG_UNTIL;
+}
+/* }}} */
+
PHPDBG_COMMAND(until) /* {{{ */
{
- if (!EG(in_execution)) {
- phpdbg_error("Not executing");
+ if (!PHPDBG_G(in_execution)) {
+ phpdbg_error("inactive", "type=\"noexec\"", "Not executing");
return SUCCESS;
}
- PHPDBG_G(flags) |= PHPDBG_IN_UNTIL;
- {
- zend_uint next = 0,
- self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes);
- zend_op *opline = &EG(active_op_array)->opcodes[self];
-
- for (next = self; next < EG(active_op_array)->last; next++) {
- if (EG(active_op_array)->opcodes[next].lineno != opline->lineno) {
- zend_hash_index_update(
- &PHPDBG_G(seek),
- (zend_ulong) &EG(active_op_array)->opcodes[next],
- &EG(active_op_array)->opcodes[next],
- sizeof(zend_op), NULL);
- break;
- }
- }
+ return phpdbg_skip_line_helper();
+} /* }}} */
+
+PHPDBG_COMMAND(next) /* {{{ */
+{
+ if (!PHPDBG_G(in_execution)) {
+ phpdbg_error("inactive", "type=\"noexec\"", "Not executing");
+ return SUCCESS;
}
- return PHPDBG_UNTIL;
+ PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
+ return phpdbg_skip_line_helper();
} /* }}} */
+static void phpdbg_seek_to_end(void) /* {{{ */ {
+ const zend_op_array *op_array = &EG(current_execute_data)->func->op_array;
+ const zend_op *opline = op_array->opcodes;
+
+ PHPDBG_G(seek_ex) = EG(current_execute_data);
+ do {
+ switch (opline->opcode) {
+ case ZEND_RETURN:
+ case ZEND_FAST_RET:
+ case ZEND_GENERATOR_RETURN:
+ case ZEND_EXIT:
+ case ZEND_YIELD:
+ case ZEND_YIELD_FROM:
+ zend_hash_index_update_ptr(&PHPDBG_G(seek), (zend_ulong) opline, (void *) opline);
+ }
+ } while (++opline < op_array->opcodes + op_array->last);
+}
+/* }}} */
+
PHPDBG_COMMAND(finish) /* {{{ */
{
- if (!EG(in_execution)) {
- phpdbg_error("Not executing");
+ if (!PHPDBG_G(in_execution)) {
+ phpdbg_error("inactive", "type=\"noexec\"", "Not executing");
return SUCCESS;
}
- PHPDBG_G(flags) |= PHPDBG_IN_FINISH;
- {
- zend_uint next = 0,
- self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes);
-
- for (next = self; next < EG(active_op_array)->last; next++) {
- switch (EG(active_op_array)->opcodes[next].opcode) {
- case ZEND_RETURN:
- case ZEND_THROW:
- case ZEND_EXIT:
-#ifdef ZEND_YIELD
- case ZEND_YIELD:
-#endif
- zend_hash_index_update(
- &PHPDBG_G(seek),
- (zend_ulong) &EG(active_op_array)->opcodes[next],
- &EG(active_op_array)->opcodes[next],
- sizeof(zend_op), NULL);
- break;
- }
- }
+ phpdbg_seek_to_end();
+ if (zend_hash_index_exists(&PHPDBG_G(seek), (zend_ulong) EG(current_execute_data)->opline)) {
+ zend_hash_clean(&PHPDBG_G(seek));
+ } else {
+ PHPDBG_G(flags) |= PHPDBG_IN_FINISH;
}
return PHPDBG_FINISH;
@@ -484,142 +599,114 @@ PHPDBG_COMMAND(finish) /* {{{ */
PHPDBG_COMMAND(leave) /* {{{ */
{
- if (!EG(in_execution)) {
- phpdbg_error("Not executing");
+ if (!PHPDBG_G(in_execution)) {
+ phpdbg_error("inactive", "type=\"noexec\"", "Not executing");
return SUCCESS;
}
- PHPDBG_G(flags) |= PHPDBG_IN_LEAVE;
- {
- zend_uint next = 0,
- self = (EG(current_execute_data)->opline - EG(active_op_array)->opcodes);
-
- for (next = self; next < EG(active_op_array)->last; next++) {
- switch (EG(active_op_array)->opcodes[next].opcode) {
- case ZEND_RETURN:
- case ZEND_THROW:
- case ZEND_EXIT:
-#ifdef ZEND_YIELD
- case ZEND_YIELD:
-#endif
- zend_hash_index_update(
- &PHPDBG_G(seek),
- (zend_ulong) &EG(active_op_array)->opcodes[next],
- &EG(active_op_array)->opcodes[next],
- sizeof(zend_op), NULL);
- break;
- }
- }
+ phpdbg_seek_to_end();
+ if (zend_hash_index_exists(&PHPDBG_G(seek), (zend_ulong) EG(current_execute_data)->opline)) {
+ zend_hash_clean(&PHPDBG_G(seek));
+ phpdbg_notice("leave", "type=\"end\"", "Already at the end of the function");
+ return SUCCESS;
+ } else {
+ PHPDBG_G(flags) |= PHPDBG_IN_LEAVE;
+ return PHPDBG_LEAVE;
}
-
- return PHPDBG_LEAVE;
} /* }}} */
PHPDBG_COMMAND(frame) /* {{{ */
{
if (!param) {
- phpdbg_notice("Currently in frame #%d", PHPDBG_G(frame).num);
- } else phpdbg_switch_frame(param->num TSRMLS_CC);
+ phpdbg_notice("frame", "id=\"%d\"", "Currently in frame #%d", PHPDBG_G(frame).num);
+ } else {
+ phpdbg_switch_frame(param->num);
+ }
return SUCCESS;
} /* }}} */
-static inline void phpdbg_handle_exception(TSRMLS_D) /* }}} */
+static inline void phpdbg_handle_exception(void) /* {{{ */
{
- zend_fcall_info fci;
+ zend_object *ex = EG(exception);
+ zend_string *msg, *file;
+ zend_long line;
+ zval zv, rv, tmp;
- zval fname,
- *trace,
- exception;
-
- /* get filename and linenumber before unsetting exception */
- const char *filename = zend_get_executed_filename(TSRMLS_C);
- zend_uint lineno = zend_get_executed_lineno(TSRMLS_C);
-
- /* copy exception */
- exception = *EG(exception);
- zval_copy_ctor(&exception);
EG(exception) = NULL;
- phpdbg_error(
- "Uncaught %s!",
- Z_OBJCE(exception)->name);
-
- /* call __toString */
- ZVAL_STRINGL(&fname, "__tostring", sizeof("__tostring")-1, 1);
- fci.size = sizeof(fci);
- fci.function_table = &Z_OBJCE(exception)->function_table;
- fci.function_name = &fname;
- fci.symbol_table = NULL;
- fci.object_ptr = &exception;
- fci.retval_ptr_ptr = &trace;
- fci.param_count = 0;
- fci.params = NULL;
- fci.no_separation = 1;
- zend_call_function(&fci, NULL TSRMLS_CC);
-
- if (trace) {
- phpdbg_writeln(
- "Uncaught %s", Z_STRVAL_P(trace));
- /* remember to dtor trace */
- zval_ptr_dtor(&trace);
+ ZVAL_OBJ(&zv, ex);
+ zend_call_method_with_0_params(&zv, ex->ce, NULL, "__tostring", &tmp);
+ file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("file"), 1, &rv));
+ line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("line"), 1, &rv));
+
+ if (EG(exception)) {
+ EG(exception) = NULL;
+ msg = ZSTR_EMPTY_ALLOC();
+ } else {
+ zend_update_property_string(zend_get_exception_base(&zv), &zv, ZEND_STRL("string"), Z_STRVAL(tmp));
+ zval_ptr_dtor(&tmp);
+ msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("string"), 1, &rv));
}
- /* output useful information about address */
- phpdbg_writeln(
- "Stacked entered at %p in %s on line %u",
- EG(active_op_array)->opcodes, filename, lineno);
+ phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", "Uncaught %s in %s on line " ZEND_LONG_FMT, ZSTR_VAL(ex->ce->name), ZSTR_VAL(file), line);
+ zend_string_release(file);
+ phpdbg_writeln("exceptionmsg", "msg=\"%s\"", ZSTR_VAL(msg));
+ zend_string_release(msg);
+
+ if (EG(prev_exception)) {
+ OBJ_RELEASE(EG(prev_exception));
+ EG(prev_exception) = 0;
+ }
+ OBJ_RELEASE(ex);
+ EG(opline_before_exception) = NULL;
- zval_dtor(&fname);
- zval_dtor(&exception);
+ EG(exit_status) = 255;
} /* }}} */
PHPDBG_COMMAND(run) /* {{{ */
{
- if (EG(in_execution)) {
- phpdbg_error("Cannot start another execution while one is in progress");
- return SUCCESS;
- }
-
if (PHPDBG_G(ops) || PHPDBG_G(exec)) {
- zend_op **orig_opline = EG(opline_ptr);
- zend_op_array *orig_op_array = EG(active_op_array);
- zval **orig_retval_ptr = EG(return_value_ptr_ptr);
- zend_bool restore = 1;
zend_execute_data *ex = EG(current_execute_data);
-
- if (!PHPDBG_G(ops)) {
- if (phpdbg_compile(TSRMLS_C) == FAILURE) {
- phpdbg_error("Failed to compile %s, cannot run", PHPDBG_G(exec));
- goto out;
+ zend_bool restore = 1;
+
+ if (PHPDBG_G(in_execution)) {
+ if (phpdbg_ask_user_permission("Do you really want to restart execution?") == SUCCESS) {
+ phpdbg_startup_run++;
+ phpdbg_clean(1);
}
+ return SUCCESS;
}
- EG(active_op_array) = PHPDBG_G(ops);
- EG(return_value_ptr_ptr) = &PHPDBG_G(retval);
- if (!EG(active_symbol_table)) {
- zend_rebuild_symbol_table(TSRMLS_C);
+ if (!PHPDBG_G(ops)) {
+ if (phpdbg_compile() == FAILURE) {
+ phpdbg_error("compile", "type=\"compilefailure\" context=\"%s\"", "Failed to compile %s, cannot run", PHPDBG_G(exec));
+ goto out;
+ }
}
/* clean up from last execution */
if (ex && ex->symbol_table) {
zend_hash_clean(ex->symbol_table);
+ } else {
+ zend_rebuild_symbol_table();
}
+ PHPDBG_G(handled_exception) = NULL;
/* clean seek state */
PHPDBG_G(flags) &= ~PHPDBG_SEEK_MASK;
- zend_hash_clean(
- &PHPDBG_G(seek));
+ zend_hash_clean(&PHPDBG_G(seek));
/* reset hit counters */
- phpdbg_reset_breakpoints(TSRMLS_C);
+ phpdbg_reset_breakpoints();
if (param && param->type != EMPTY_PARAM && param->len != 0) {
char **argv = emalloc(5 * sizeof(char *));
int argc = 0;
int i;
+ /* TODO allow proper escaping with \, "" and '' here */
char *argv_str = strtok(param->str, " ");
-
+
while (argv_str) {
if (argc >= 4 && argc == (argc & -argc)) {
argv = erealloc(argv, (argc * 2 + 1) * sizeof(char *));
@@ -635,38 +722,53 @@ PHPDBG_COMMAND(run) /* {{{ */
efree(SG(request_info).argv);
SG(request_info).argv = erealloc(argv, ++argc * sizeof(char *));
SG(request_info).argc = argc;
-
- php_hash_environment(TSRMLS_C);
+
+ php_build_argv(NULL, &PG(http_globals)[TRACK_VARS_SERVER]);
}
zend_try {
- php_output_activate(TSRMLS_C);
PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE;
- zend_execute(EG(active_op_array) TSRMLS_CC);
+ PHPDBG_G(flags) |= PHPDBG_IS_RUNNING;
+ zend_execute(PHPDBG_G(ops), &PHPDBG_G(retval));
PHPDBG_G(flags) ^= PHPDBG_IS_INTERACTIVE;
- php_output_deactivate(TSRMLS_C);
} zend_catch {
- EG(active_op_array) = orig_op_array;
- EG(opline_ptr) = orig_opline;
- EG(return_value_ptr_ptr) = orig_retval_ptr;
+ PHPDBG_G(in_execution) = 0;
- if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
- phpdbg_error("Caught exit/error from VM");
+ if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) {
restore = 0;
+ } else {
+ zend_bailout();
}
} zend_end_try();
+ if (PHPDBG_G(socket_fd) != -1) {
+ close(PHPDBG_G(socket_fd));
+ PHPDBG_G(socket_fd) = -1;
+ }
+
if (restore) {
+ zend_exception_restore();
+ zend_try {
+ zend_try_exception_handler();
+ PHPDBG_G(in_execution) = 1;
+ } zend_catch {
+ PHPDBG_G(in_execution) = 0;
+
+ if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) {
+ zend_bailout();
+ }
+ } zend_end_try();
+
if (EG(exception)) {
- phpdbg_handle_exception(TSRMLS_C);
+ phpdbg_handle_exception();
}
-
- EG(active_op_array) = orig_op_array;
- EG(opline_ptr) = orig_opline;
- EG(return_value_ptr_ptr) = orig_retval_ptr;
}
+
+ PHPDBG_G(flags) &= ~PHPDBG_IS_RUNNING;
+
+ phpdbg_clean(1);
} else {
- phpdbg_error("Nothing to execute!");
+ phpdbg_error("inactive", "type=\"nocontext\"", "Nothing to execute!");
}
out:
@@ -674,50 +776,106 @@ out:
return SUCCESS;
} /* }}} */
+int phpdbg_output_ev_variable(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv) /* {{{ */ {
+ phpdbg_notice("eval", "variable=\"%.*s\"", "Printing variable %.*s", (int) len, name);
+ phpdbg_xml("<eval %r>");
+ zend_print_zval_r(zv, 0);
+ phpdbg_xml("</eval>");
+ phpdbg_out("\n");
+
+ efree(name);
+ efree(keyname);
+
+ return SUCCESS;
+}
+/* }}} */
+
PHPDBG_COMMAND(ev) /* {{{ */
{
- zend_bool stepping = ((PHPDBG_G(flags) & PHPDBG_IS_STEPPING)==PHPDBG_IS_STEPPING);
+ zend_bool stepping = ((PHPDBG_G(flags) & PHPDBG_IS_STEPPING) == PHPDBG_IS_STEPPING);
zval retval;
+ zend_execute_data *original_execute_data = EG(current_execute_data);
+ zend_class_entry *original_scope = EG(scope);
+ zend_vm_stack original_stack = EG(vm_stack);
+ zend_object *ex = NULL;
+
+ PHPDBG_OUTPUT_BACKUP();
+
+ original_stack->top = EG(vm_stack_top);
+
+ if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
+ phpdbg_try_access {
+ phpdbg_parse_variable(param->str, param->len, &EG(symbol_table), 0, phpdbg_output_ev_variable, 0);
+ } phpdbg_catch_access {
+ phpdbg_error("signalsegv", "", "Could not fetch data, invalid data source");
+ } phpdbg_end_try_access();
+
+ PHPDBG_OUTPUT_BACKUP_RESTORE();
+ return SUCCESS;
+ }
+
if (!(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) {
- PHPDBG_G(flags) &= ~ PHPDBG_IS_STEPPING;
+ PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING;
}
/* disable stepping while eval() in progress */
PHPDBG_G(flags) |= PHPDBG_IN_EVAL;
zend_try {
- if (zend_eval_stringl(param->str, param->len,
- &retval, "eval()'d code" TSRMLS_CC) == SUCCESS) {
- zend_print_zval_r(
- &retval, 0 TSRMLS_CC);
- phpdbg_writeln(EMPTY);
- zval_dtor(&retval);
+ if (zend_eval_stringl(param->str, param->len, &retval, "eval()'d code") == SUCCESS) {
+ if (EG(exception)) {
+ ex = EG(exception);
+ zend_exception_error(EG(exception), E_ERROR);
+ } else {
+ phpdbg_xml("<eval %r>");
+ if (PHPDBG_G(flags) & PHPDBG_WRITE_XML) {
+ zval *zvp = &retval;
+ phpdbg_xml_var_dump(zvp);
+ }
+ zend_print_zval_r(&retval, 0);
+ phpdbg_xml("</eval>");
+ phpdbg_out("\n");
+ zval_ptr_dtor(&retval);
+ }
+ }
+ } zend_catch {
+ PHPDBG_G(unclean_eval) = 1;
+ if (ex) {
+ OBJ_RELEASE(ex);
}
+ EG(current_execute_data) = original_execute_data;
+ EG(scope) = original_scope;
+ EG(vm_stack_top) = original_stack->top;
+ EG(vm_stack_end) = original_stack->end;
+ EG(vm_stack) = original_stack;
+ EG(exit_status) = 0;
} zend_end_try();
+
PHPDBG_G(flags) &= ~PHPDBG_IN_EVAL;
/* switch stepping back on */
- if (stepping &&
- !(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) {
+ if (stepping && !(PHPDBG_G(flags) & PHPDBG_IS_STEPONEVAL)) {
PHPDBG_G(flags) |= PHPDBG_IS_STEPPING;
}
CG(unclean_shutdown) = 0;
+ PHPDBG_OUTPUT_BACKUP_RESTORE();
+
return SUCCESS;
} /* }}} */
PHPDBG_COMMAND(back) /* {{{ */
{
- if (!EG(in_execution)) {
- phpdbg_error("Not executing!");
+ if (!PHPDBG_G(in_execution)) {
+ phpdbg_error("inactive", "type=\"noexec\"", "Not executing!");
return SUCCESS;
}
if (!param) {
- phpdbg_dump_backtrace(0 TSRMLS_CC);
+ phpdbg_dump_backtrace(0);
} else {
- phpdbg_dump_backtrace(param->num TSRMLS_CC);
+ phpdbg_dump_backtrace(param->num);
}
return SUCCESS;
@@ -725,62 +883,62 @@ PHPDBG_COMMAND(back) /* {{{ */
PHPDBG_COMMAND(print) /* {{{ */
{
- phpdbg_writeln(SEPARATE);
- phpdbg_notice("Execution Context Information");
+ if (!param || param->type == EMPTY_PARAM) {
+ return phpdbg_do_print_stack(param);
+ } else switch (param->type) {
+ case STR_PARAM:
+ return phpdbg_do_print_func(param);
+ case METHOD_PARAM:
+ return phpdbg_do_print_method(param);
+ default:
+ phpdbg_error("print", "type=\"invalidarg\"", "Invalid arguments to print, expected nothing, function name or method name");
+ return SUCCESS;
+ }
+} /* }}} */
+
+PHPDBG_COMMAND(info) /* {{{ */
+{
+ phpdbg_out("Execution Context Information\n\n");
+ phpdbg_xml("<printinfo %r>");
#ifdef HAVE_LIBREADLINE
- phpdbg_writeln("Readline\tyes");
+ phpdbg_writeln("info", "readline=\"yes\"", "Readline yes");
#else
- phpdbg_writeln("Readline\tno");
+ phpdbg_writeln("info", "readline=\"no\"", "Readline no");
#endif
#ifdef HAVE_LIBEDIT
- phpdbg_writeln("Libedit\t\tyes");
+ phpdbg_writeln("info", "libedit=\"yes\"", "Libedit yes");
#else
- phpdbg_writeln("Libedit\t\tno");
+ phpdbg_writeln("info", "libedit=\"no\"", "Libedit no");
#endif
- phpdbg_writeln("Exec\t\t%s", PHPDBG_G(exec) ? PHPDBG_G(exec) : "none");
- phpdbg_writeln("Compiled\t%s", PHPDBG_G(ops) ? "yes" : "no");
- phpdbg_writeln("Stepping\t%s", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
- phpdbg_writeln("Quietness\t%s", (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "on" : "off");
- phpdbg_writeln("Oplog\t\t%s", PHPDBG_G(oplog) ? "on" : "off");
+ phpdbg_writeln("info", "context=\"%s\"", "Exec %s", PHPDBG_G(exec) ? PHPDBG_G(exec) : "none");
+ phpdbg_writeln("info", "compiled=\"%s\"", "Compiled %s", PHPDBG_G(ops) ? "yes" : "no");
+ phpdbg_writeln("info", "stepping=\"%s\"", "Stepping %s", (PHPDBG_G(flags) & PHPDBG_IS_STEPPING) ? "on" : "off");
+ phpdbg_writeln("info", "quiet=\"%s\"", "Quietness %s", (PHPDBG_G(flags) & PHPDBG_IS_QUIET) ? "on" : "off");
+ phpdbg_writeln("info", "oplog=\"%s\"", "Oplog %s", PHPDBG_G(oplog) ? "on" : "off");
if (PHPDBG_G(ops)) {
- phpdbg_writeln("Opcodes\t\t%d", PHPDBG_G(ops)->last);
-
- if (PHPDBG_G(ops)->last_var) {
- phpdbg_writeln("Variables\t%d", PHPDBG_G(ops)->last_var-1);
- } else {
- phpdbg_writeln("Variables\tNone");
- }
+ phpdbg_writeln("info", "ops=\"%d\"", "Opcodes %d", PHPDBG_G(ops)->last);
+ phpdbg_writeln("info", "vars=\"%d\"", "Variables %d", PHPDBG_G(ops)->last_var ? PHPDBG_G(ops)->last_var - 1 : 0);
}
- phpdbg_writeln("Executing\t%s", EG(in_execution) ? "yes" : "no");
- if (EG(in_execution)) {
- phpdbg_writeln("VM Return\t%d", PHPDBG_G(vmret));
+ phpdbg_writeln("info", "executing=\"%d\"", "Executing %s", PHPDBG_G(in_execution) ? "yes" : "no");
+ if (PHPDBG_G(in_execution)) {
+ phpdbg_writeln("info", "vmret=\"%d\"", "VM Return %d", PHPDBG_G(vmret));
}
- phpdbg_writeln("Classes\t\t%d", zend_hash_num_elements(EG(class_table)));
- phpdbg_writeln("Functions\t%d", zend_hash_num_elements(EG(function_table)));
- phpdbg_writeln("Constants\t%d", zend_hash_num_elements(EG(zend_constants)));
- phpdbg_writeln("Included\t%d", zend_hash_num_elements(&EG(included_files)));
-
- phpdbg_writeln(SEPARATE);
-
- return SUCCESS;
-} /* }}} */
-
-PHPDBG_COMMAND(info) /* {{{ */
-{
- phpdbg_error(
- "No information command selected!");
+ phpdbg_writeln("info", "classes=\"%d\"", "Classes %d", zend_hash_num_elements(EG(class_table)));
+ phpdbg_writeln("info", "functions=\"%d\"", "Functions %d", zend_hash_num_elements(EG(function_table)));
+ phpdbg_writeln("info", "constants=\"%d\"", "Constants %d", zend_hash_num_elements(EG(zend_constants)));
+ phpdbg_writeln("info", "includes=\"%d\"", "Included %d", zend_hash_num_elements(&EG(included_files)));
+ phpdbg_xml("</printinfo>");
return SUCCESS;
} /* }}} */
PHPDBG_COMMAND(set) /* {{{ */
{
- phpdbg_error(
- "No set command selected!");
+ phpdbg_error("set", "type=\"toofewargs\" expected=\"1\"", "No set command selected!");
return SUCCESS;
} /* }}} */
@@ -789,42 +947,42 @@ PHPDBG_COMMAND(break) /* {{{ */
{
if (!param) {
phpdbg_set_breakpoint_file(
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C) TSRMLS_CC);
+ zend_get_executed_filename(),
+ zend_get_executed_lineno());
} else switch (param->type) {
case ADDR_PARAM:
- phpdbg_set_breakpoint_opline(param->addr TSRMLS_CC);
+ phpdbg_set_breakpoint_opline(param->addr);
break;
case NUMERIC_PARAM:
if (PHPDBG_G(exec)) {
- phpdbg_set_breakpoint_file(phpdbg_current_file(TSRMLS_C), param->num TSRMLS_CC);
+ phpdbg_set_breakpoint_file(phpdbg_current_file(), param->num);
} else {
- phpdbg_error("Execution context not set!");
+ phpdbg_error("inactive", "type=\"noexec\"", "Execution context not set!");
}
break;
case METHOD_PARAM:
- phpdbg_set_breakpoint_method(param->method.class, param->method.name TSRMLS_CC);
+ phpdbg_set_breakpoint_method(param->method.class, param->method.name);
break;
case NUMERIC_METHOD_PARAM:
- phpdbg_set_breakpoint_method_opline(param->method.class, param->method.name, param->num TSRMLS_CC);
+ phpdbg_set_breakpoint_method_opline(param->method.class, param->method.name, param->num);
break;
case NUMERIC_FUNCTION_PARAM:
- phpdbg_set_breakpoint_function_opline(param->str, param->num TSRMLS_CC);
+ phpdbg_set_breakpoint_function_opline(param->str, param->num);
break;
case FILE_PARAM:
- phpdbg_set_breakpoint_file(param->file.name, param->file.line TSRMLS_CC);
+ phpdbg_set_breakpoint_file(param->file.name, param->file.line);
break;
case NUMERIC_FILE_PARAM:
- phpdbg_set_breakpoint_file_opline(param->file.name, param->file.line TSRMLS_CC);
+ phpdbg_set_breakpoint_file_opline(param->file.name, param->file.line);
break;
case COND_PARAM:
- phpdbg_set_breakpoint_expression(param->str, param->len TSRMLS_CC);
+ phpdbg_set_breakpoint_expression(param->str, param->len);
break;
case STR_PARAM:
- phpdbg_set_breakpoint_symbol(param->str, param->len TSRMLS_CC);
+ phpdbg_set_breakpoint_symbol(param->str, param->len);
break;
case OP_PARAM:
- phpdbg_set_breakpoint_opcode(param->str, param->len TSRMLS_CC);
+ phpdbg_set_breakpoint_opcode(param->str, param->len);
break;
phpdbg_default_switch_case();
@@ -837,42 +995,229 @@ PHPDBG_COMMAND(sh) /* {{{ */
{
FILE *fd = NULL;
if ((fd=VCWD_POPEN((char*)param->str, "w"))) {
- /* do something perhaps ?? do we want input ?? */
- fclose(fd);
+ /* TODO: do something perhaps ?? do we want input ?? */
+ pclose(fd);
} else {
- phpdbg_error(
- "Failed to execute %s", param->str);
+ phpdbg_error("sh", "type=\"failure\" smd=\"%s\"", "Failed to execute %s", param->str);
}
-
+
+ return SUCCESS;
+} /* }}} */
+
+static int add_module_info(zend_module_entry *module) /* {{{ */ {
+ phpdbg_write("module", "name=\"%s\"", "%s\n", module->name);
+ return 0;
+}
+/* }}} */
+
+static int add_zendext_info(zend_extension *ext) /* {{{ */ {
+ phpdbg_write("extension", "name=\"%s\"", "%s\n", ext->name);
+ return 0;
+}
+/* }}} */
+
+PHPDBG_API const char *phpdbg_load_module_or_extension(char **path, char **name) /* {{{ */ {
+ DL_HANDLE handle;
+ char *extension_dir;
+
+ extension_dir = INI_STR("extension_dir");
+
+ if (strchr(*path, '/') != NULL || strchr(*path, DEFAULT_SLASH) != NULL) {
+ /* path is fine */
+ } else if (extension_dir && extension_dir[0]) {
+ char *libpath;
+ int extension_dir_len = strlen(extension_dir);
+ if (IS_SLASH(extension_dir[extension_dir_len-1])) {
+ spprintf(&libpath, 0, "%s%s", extension_dir, *path); /* SAFE */
+ } else {
+ spprintf(&libpath, 0, "%s%c%s", extension_dir, DEFAULT_SLASH, *path); /* SAFE */
+ }
+ efree(*path);
+ *path = libpath;
+ } else {
+ phpdbg_error("dl", "type=\"relpath\"", "Not a full path given or extension_dir ini setting is not set");
+
+ return NULL;
+ }
+
+ handle = DL_LOAD(*path);
+
+ if (!handle) {
+#if PHP_WIN32
+ char *err = GET_DL_ERROR();
+ if (err && *err != "") {
+ phpdbg_error("dl", "type=\"unknown\"", "%s", err);
+ LocalFree(err);
+ } else {
+ phpdbg_error("dl", "type=\"unknown\"", "Unknown reason");
+ }
+#else
+ phpdbg_error("dl", "type=\"unknown\"", "%s", GET_DL_ERROR());
+#endif
+ return NULL;
+ }
+
+#if ZEND_EXTENSIONS_SUPPORT
+ do {
+ zend_extension *new_extension;
+ zend_extension_version_info *extension_version_info;
+
+ extension_version_info = (zend_extension_version_info *) DL_FETCH_SYMBOL(handle, "extension_version_info");
+ if (!extension_version_info) {
+ extension_version_info = (zend_extension_version_info *) DL_FETCH_SYMBOL(handle, "_extension_version_info");
+ }
+ new_extension = (zend_extension *) DL_FETCH_SYMBOL(handle, "zend_extension_entry");
+ if (!new_extension) {
+ new_extension = (zend_extension *) DL_FETCH_SYMBOL(handle, "_zend_extension_entry");
+ }
+ if (!extension_version_info || !new_extension) {
+ break;
+ }
+ if (extension_version_info->zend_extension_api_no != ZEND_EXTENSION_API_NO &&(!new_extension->api_no_check || new_extension->api_no_check(ZEND_EXTENSION_API_NO) != SUCCESS)) {
+ phpdbg_error("dl", "type=\"wrongapi\" extension=\"%s\" apineeded=\"%d\" apiinstalled=\"%d\"", "%s requires Zend Engine API version %d, which does not match the installed Zend Engine API version %d", new_extension->name, extension_version_info->zend_extension_api_no, ZEND_EXTENSION_API_NO);
+
+ goto quit;
+ } else if (strcmp(ZEND_EXTENSION_BUILD_ID, extension_version_info->build_id) && (!new_extension->build_id_check || new_extension->build_id_check(ZEND_EXTENSION_BUILD_ID) != SUCCESS)) {
+ phpdbg_error("dl", "type=\"wrongbuild\" extension=\"%s\" buildneeded=\"%s\" buildinstalled=\"%s\"", "%s was built with configuration %s, whereas running engine is %s", new_extension->name, extension_version_info->build_id, ZEND_EXTENSION_BUILD_ID);
+
+ goto quit;
+ }
+
+ *name = new_extension->name;
+
+ zend_register_extension(new_extension, handle);
+
+ if (new_extension->startup) {
+ if (new_extension->startup(new_extension) != SUCCESS) {
+ phpdbg_error("dl", "type=\"startupfailure\" extension=\"%s\"", "Unable to startup Zend extension %s", new_extension->name);
+
+ goto quit;
+ }
+ zend_append_version_info(new_extension);
+ }
+
+ return "Zend extension";
+ } while (0);
+#endif
+
+ do {
+ zend_module_entry *module_entry;
+ zend_module_entry *(*get_module)(void);
+
+ get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "get_module");
+ if (!get_module) {
+ get_module = (zend_module_entry *(*)(void)) DL_FETCH_SYMBOL(handle, "_get_module");
+ }
+
+ if (!get_module) {
+ break;
+ }
+
+ module_entry = get_module();
+ *name = (char *) module_entry->name;
+
+ if (strcmp(ZEND_EXTENSION_BUILD_ID, module_entry->build_id)) {
+ phpdbg_error("dl", "type=\"wrongbuild\" module=\"%s\" buildneeded=\"%s\" buildinstalled=\"%s\"", "%s was built with configuration %s, whereas running engine is %s", module_entry->name, module_entry->build_id, ZEND_EXTENSION_BUILD_ID);
+
+ goto quit;
+ }
+
+ module_entry->type = MODULE_PERSISTENT;
+ module_entry->module_number = zend_next_free_module();
+ module_entry->handle = handle;
+
+ if ((module_entry = zend_register_module_ex(module_entry)) == NULL) {
+ phpdbg_error("dl", "type=\"registerfailure\" module=\"%s\"", "Unable to register module %s", module_entry->name);
+
+ goto quit;
+ }
+
+ if (zend_startup_module_ex(module_entry) == FAILURE) {
+ phpdbg_error("dl", "type=\"startupfailure\" module=\"%s\"", "Unable to startup module %s", module_entry->name);
+
+ goto quit;
+ }
+
+ if (module_entry->request_startup_func) {
+ if (module_entry->request_startup_func(MODULE_PERSISTENT, module_entry->module_number) == FAILURE) {
+ phpdbg_error("dl", "type=\"initfailure\" module=\"%s\"", "Unable to initialize module %s", module_entry->name);
+
+ goto quit;
+ }
+ }
+
+ return "module";
+ } while (0);
+
+ phpdbg_error("dl", "type=\"nophpso\"", "This shared object is nor a Zend extension nor a module");
+
+quit:
+ DL_UNLOAD(handle);
+ return NULL;
+}
+/* }}} */
+
+PHPDBG_COMMAND(dl) /* {{{ */
+{
+ const char *type;
+ char *name, *path;
+
+ if (!param || param->type == EMPTY_PARAM) {
+ phpdbg_notice("dl", "extensiontype=\"Zend extension\"", "Zend extensions");
+ zend_llist_apply(&zend_extensions, (llist_apply_func_t) add_zendext_info);
+ phpdbg_out("\n");
+ phpdbg_notice("dl", "extensiontype=\"module\"", "Modules");
+ zend_hash_apply(&module_registry, (apply_func_t) add_module_info);
+ } else switch (param->type) {
+ case STR_PARAM:
+#ifdef HAVE_LIBDL
+ path = estrndup(param->str, param->len);
+
+ phpdbg_activate_err_buf(1);
+ if ((type = phpdbg_load_module_or_extension(&path, &name)) == NULL) {
+ phpdbg_error("dl", "path=\"%s\" %b", "Could not load %s, not found or invalid zend extension / module: %b", path);
+ efree(name);
+ } else {
+ phpdbg_notice("dl", "extensiontype=\"%s\" name=\"%s\" path=\"%s\"", "Successfully loaded the %s %s at path %s", type, name, path);
+ }
+ phpdbg_activate_err_buf(0);
+ phpdbg_free_err_buf();
+ efree(path);
+#else
+ phpdbg_error("dl", "type=\"unsupported\" path=\"%.*s\"", "Cannot dynamically load %.*s - dynamic modules are not supported", (int) param->len, param->str);
+#endif
+ break;
+
+ phpdbg_default_switch_case();
+ }
+
return SUCCESS;
} /* }}} */
PHPDBG_COMMAND(source) /* {{{ */
{
- struct stat sb;
-
+ zend_stat_t sb;
+
if (VCWD_STAT(param->str, &sb) != -1) {
- phpdbg_try_file_init(param->str, param->len, 0 TSRMLS_CC);
+ phpdbg_try_file_init(param->str, param->len, 0);
} else {
- phpdbg_error(
- "Failed to stat %s, file does not exist", param->str);
+ phpdbg_error("source", "type=\"notfound\" file=\"%s\"", "Failed to stat %s, file does not exist", param->str);
}
-
+
return SUCCESS;
} /* }}} */
PHPDBG_COMMAND(export) /* {{{ */
{
FILE *handle = VCWD_FOPEN(param->str, "w+");
-
+
if (handle) {
- phpdbg_export_breakpoints(handle TSRMLS_CC);
+ phpdbg_export_breakpoints(handle);
fclose(handle);
} else {
- phpdbg_error(
- "Failed to open or create %s, check path and permissions", param->str);
+ phpdbg_error("export", "type=\"openfailure\" file=\"%s\"", "Failed to open or create %s, check path and permissions", param->str);
}
-
+
return SUCCESS;
} /* }}} */
@@ -882,20 +1227,17 @@ PHPDBG_COMMAND(register) /* {{{ */
char *lcname = zend_str_tolower_dup(param->str, param->len);
size_t lcname_len = strlen(lcname);
- if (!zend_hash_exists(&PHPDBG_G(registered), lcname, lcname_len+1)) {
- if (zend_hash_find(EG(function_table), lcname, lcname_len+1, (void**) &function) == SUCCESS) {
- zend_hash_update(
- &PHPDBG_G(registered), lcname, lcname_len+1, (void*)&function, sizeof(zend_function), NULL);
+ if (!zend_hash_str_exists(&PHPDBG_G(registered), lcname, lcname_len)) {
+ if ((function = zend_hash_str_find_ptr(EG(function_table), lcname, lcname_len))) {
+ zend_hash_str_update_ptr(&PHPDBG_G(registered), lcname, lcname_len, function);
function_add_ref(function);
- phpdbg_notice(
- "Registered %s", lcname);
+ phpdbg_notice("register", "function=\"%s\"", "Registered %s", lcname);
} else {
- phpdbg_error("The requested function (%s) could not be found", param->str);
+ phpdbg_error("register", "type=\"notfound\" function=\"%s\"", "The requested function (%s) could not be found", param->str);
}
} else {
- phpdbg_error(
- "The requested name (%s) is already in use", lcname);
+ phpdbg_error("register", "type=\"inuse\" function=\"%s\"", "The requested name (%s) is already in use", lcname);
}
efree(lcname);
@@ -904,48 +1246,52 @@ PHPDBG_COMMAND(register) /* {{{ */
PHPDBG_COMMAND(quit) /* {{{ */
{
- /* don't allow this to loop, ever ... */
- if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
- PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
- zend_bailout();
- }
+ PHPDBG_G(flags) |= PHPDBG_IS_QUITTING;
+ PHPDBG_G(flags) &= ~PHPDBG_IS_CLEANING;
- return PHPDBG_NEXT;
+ return SUCCESS;
} /* }}} */
PHPDBG_COMMAND(clean) /* {{{ */
{
- if (EG(in_execution)) {
- phpdbg_error("Cannot clean environment while executing");
- return SUCCESS;
+ if (PHPDBG_G(in_execution)) {
+ if (phpdbg_ask_user_permission("Do you really want to clean your current environment?") == FAILURE) {
+ return SUCCESS;
+ }
}
- phpdbg_notice("Cleaning Execution Environment");
+ phpdbg_out("Cleaning Execution Environment\n");
+ phpdbg_xml("<cleaninfo %r>");
- phpdbg_writeln("Classes\t\t\t%d", zend_hash_num_elements(EG(class_table)));
- phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(EG(function_table)));
- phpdbg_writeln("Constants\t\t%d", zend_hash_num_elements(EG(zend_constants)));
- phpdbg_writeln("Includes\t\t%d", zend_hash_num_elements(&EG(included_files)));
+ phpdbg_writeln("clean", "classes=\"%d\"", "Classes %d", zend_hash_num_elements(EG(class_table)));
+ phpdbg_writeln("clean", "functions=\"%d\"", "Functions %d", zend_hash_num_elements(EG(function_table)));
+ phpdbg_writeln("clean", "constants=\"%d\"", "Constants %d", zend_hash_num_elements(EG(zend_constants)));
+ phpdbg_writeln("clean", "includes=\"%d\"", "Includes %d", zend_hash_num_elements(&EG(included_files)));
- phpdbg_clean(1 TSRMLS_CC);
+ phpdbg_clean(1);
+
+ phpdbg_xml("</cleaninfo>");
return SUCCESS;
} /* }}} */
PHPDBG_COMMAND(clear) /* {{{ */
{
- phpdbg_notice("Clearing Breakpoints");
+ phpdbg_out("Clearing Breakpoints\n");
+ phpdbg_xml("<clearinfo %r>");
+
+ phpdbg_writeln("clear", "files=\"%d\"", "File %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]));
+ phpdbg_writeln("clear", "functions=\"%d\"", "Functions %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]));
+ phpdbg_writeln("clear", "methods=\"%d\"", "Methods %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]));
+ phpdbg_writeln("clear", "oplines=\"%d\"", "Oplines %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]));
+ phpdbg_writeln("clear", "fileoplines=\"%d\"", "File oplines %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE]));
+ phpdbg_writeln("clear", "functionoplines=\"%d\"", "Function oplines %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE]));
+ phpdbg_writeln("clear", "methodoplines=\"%d\"", "Method oplines %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE]));
+ phpdbg_writeln("clear", "eval=\"%d\"", "Conditionals %d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_COND]));
- phpdbg_writeln("File\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE]));
- phpdbg_writeln("Functions\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_SYM]));
- phpdbg_writeln("Methods\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD]));
- phpdbg_writeln("Oplines\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_OPLINE]));
- phpdbg_writeln("File oplines\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FILE_OPLINE]));
- phpdbg_writeln("Function oplines\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_FUNCTION_OPLINE]));
- phpdbg_writeln("Method oplines\t\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_METHOD_OPLINE]));
- phpdbg_writeln("Conditionals\t\t%d", zend_hash_num_elements(&PHPDBG_G(bp)[PHPDBG_BREAK_COND]));
+ phpdbg_clear_breakpoints();
- phpdbg_clear_breakpoints(TSRMLS_C);
+ phpdbg_xml("</clearinfo>");
return SUCCESS;
} /* }}} */
@@ -962,7 +1308,7 @@ PHPDBG_COMMAND(list) /* {{{ */
return PHPDBG_LIST_HANDLER(lines)(PHPDBG_COMMAND_ARGS);
case STR_PARAM:
- phpdbg_list_function_byname(param->str, param->len TSRMLS_CC);
+ phpdbg_list_function_byname(param->str, param->len);
break;
case METHOD_PARAM:
@@ -977,11 +1323,11 @@ PHPDBG_COMMAND(list) /* {{{ */
PHPDBG_COMMAND(watch) /* {{{ */
{
if (!param || param->type == EMPTY_PARAM) {
- phpdbg_list_watchpoints(TSRMLS_C);
+ phpdbg_list_watchpoints();
} else switch (param->type) {
case STR_PARAM:
- if (phpdbg_create_var_watchpoint(param->str, param->len TSRMLS_CC) != FAILURE) {
- phpdbg_notice("Set watchpoint on %.*s", (int)param->len, param->str);
+ if (phpdbg_create_var_watchpoint(param->str, param->len) != FAILURE) {
+ phpdbg_notice("watch", "variable=\"%.*s\"", "Set watchpoint on %.*s", (int) param->len, param->str);
}
break;
@@ -991,249 +1337,217 @@ PHPDBG_COMMAND(watch) /* {{{ */
return SUCCESS;
} /* }}} */
-int phpdbg_interactive(TSRMLS_D) /* {{{ */
+int phpdbg_interactive(zend_bool allow_async_unsafe) /* {{{ */
{
int ret = SUCCESS;
- char *why = NULL;
char *input = NULL;
phpdbg_param_t stack;
PHPDBG_G(flags) |= PHPDBG_IS_INTERACTIVE;
- input = phpdbg_read_input(NULL TSRMLS_CC);
+ while (ret == SUCCESS || ret == FAILURE) {
+ if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) {
+ zend_bailout();
+ }
- if (input) {
- do {
- phpdbg_init_param(&stack, STACK_PARAM);
+ if (!(input = phpdbg_read_input(NULL))) {
+ break;
+ }
- if (phpdbg_do_parse(&stack, input TSRMLS_CC) <= 0) {
- switch (ret = phpdbg_stack_execute(&stack, &why TSRMLS_CC)) {
- case FAILURE:
- if (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
- if (phpdbg_call_register(&stack TSRMLS_CC) == FAILURE) {
- if (why) {
- phpdbg_error("%s", why);
- }
- }
- }
- if (why) {
- free(why);
- why = NULL;
- }
- break;
+ phpdbg_init_param(&stack, STACK_PARAM);
- case PHPDBG_LEAVE:
- case PHPDBG_FINISH:
- case PHPDBG_UNTIL:
- case PHPDBG_NEXT: {
- if (!EG(in_execution) && !(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)) {
- phpdbg_error("Not running");
+ if (phpdbg_do_parse(&stack, input) <= 0) {
+ phpdbg_activate_err_buf(1);
+
+#ifdef PHP_WIN32
+#define PARA ((phpdbg_param_t *)stack.next)->type
+ if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE && (RUN_PARAM == PARA || EVAL_PARAM == PARA)) {
+ sigio_watcher_start();
+ }
+#endif
+ switch (ret = phpdbg_stack_execute(&stack, allow_async_unsafe)) {
+ case FAILURE:
+ if (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) {
+ if (!allow_async_unsafe || phpdbg_call_register(&stack) == FAILURE) {
+ phpdbg_output_err_buf(NULL, "%b", "%b");
}
- goto out;
}
+ break;
+
+ case PHPDBG_LEAVE:
+ case PHPDBG_FINISH:
+ case PHPDBG_UNTIL:
+ case PHPDBG_NEXT: {
+ phpdbg_activate_err_buf(0);
+ phpdbg_free_err_buf();
+ if (!PHPDBG_G(in_execution) && !(PHPDBG_G(flags) & PHPDBG_IS_STOPPING)) {
+ phpdbg_error("command", "type=\"noexec\"", "Not running");
+ }
+ break;
}
}
- if (why) {
- free(why);
- why = NULL;
+ phpdbg_activate_err_buf(0);
+ phpdbg_free_err_buf();
+#ifdef PHP_WIN32
+ if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE && (RUN_PARAM == PARA || EVAL_PARAM == PARA)) {
+ sigio_watcher_stop();
}
+#undef PARA
+#endif
+ }
- phpdbg_stack_free(&stack);
- phpdbg_destroy_input(&input TSRMLS_CC);
-
- } while ((input = phpdbg_read_input(NULL TSRMLS_CC)));
+ phpdbg_stack_free(&stack);
+ phpdbg_destroy_input(&input);
+ PHPDBG_G(req_id) = 0;
+ input = NULL;
}
-out:
if (input) {
phpdbg_stack_free(&stack);
- phpdbg_destroy_input(&input TSRMLS_CC);
+ phpdbg_destroy_input(&input);
+ PHPDBG_G(req_id) = 0;
}
- if (why) {
- free(why);
- }
-
- if (EG(in_execution)) {
- phpdbg_restore_frame(TSRMLS_C);
+ if (PHPDBG_G(in_execution)) {
+ phpdbg_restore_frame();
}
PHPDBG_G(flags) &= ~PHPDBG_IS_INTERACTIVE;
- phpdbg_print_changed_zvals(TSRMLS_C);
+ phpdbg_print_changed_zvals();
return ret;
} /* }}} */
-void phpdbg_clean(zend_bool full TSRMLS_DC) /* {{{ */
-{
- /* this is implicitly required */
- if (PHPDBG_G(ops)) {
- destroy_op_array(PHPDBG_G(ops) TSRMLS_CC);
- efree(PHPDBG_G(ops));
- PHPDBG_G(ops) = NULL;
- }
+/* code may behave weirdly if EG(exception) is set; thus backup it */
+#define DO_INTERACTIVE(allow_async_unsafe) do { \
+ const zend_op *backup_opline; \
+ const zend_op *before_ex; \
+ if (exception) { \
+ if (EG(current_execute_data) && EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type)) { \
+ backup_opline = EG(current_execute_data)->opline; \
+ } \
+ before_ex = EG(opline_before_exception); \
+ ++GC_REFCOUNT(exception); \
+ zend_clear_exception(); \
+ } \
+ if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { \
+ const char *file_char = zend_get_executed_filename(); \
+ zend_string *file = zend_string_init(file_char, strlen(file_char), 0); \
+ phpdbg_list_file(file, 3, zend_get_executed_lineno()-1, zend_get_executed_lineno()); \
+ efree(file); \
+ } \
+ \
+ switch (phpdbg_interactive(allow_async_unsafe)) { \
+ zval zv; \
+ case PHPDBG_LEAVE: \
+ case PHPDBG_FINISH: \
+ case PHPDBG_UNTIL: \
+ case PHPDBG_NEXT: \
+ if (exception) { \
+ if (EG(current_execute_data) && EG(current_execute_data)->func && ZEND_USER_CODE(EG(current_execute_data)->func->common.type) \
+ && (backup_opline->opcode == ZEND_HANDLE_EXCEPTION || backup_opline->opcode == ZEND_CATCH)) { \
+ EG(current_execute_data)->opline = backup_opline; \
+ EG(exception) = exception; \
+ } else { \
+ Z_OBJ(zv) = exception; \
+ zend_throw_exception_internal(&zv); \
+ } \
+ EG(opline_before_exception) = before_ex; \
+ } \
+ /* fallthrough */ \
+ default: \
+ goto next; \
+ } \
+} while (0)
- if (full) {
- PHPDBG_G(flags) |= PHPDBG_IS_CLEANING;
+void phpdbg_execute_ex(zend_execute_data *execute_data) /* {{{ */
+{
+ zend_bool original_in_execution = PHPDBG_G(in_execution);
+ if ((PHPDBG_G(flags) & PHPDBG_IS_STOPPING) && !(PHPDBG_G(flags) & PHPDBG_IS_RUNNING)) {
zend_bailout();
}
-} /* }}} */
-static inline zend_execute_data *phpdbg_create_execute_data(zend_op_array *op_array, zend_bool nested TSRMLS_DC) /* {{{ */
-{
-#if PHP_VERSION_ID >= 50500
- return zend_create_execute_data_from_op_array(op_array, nested TSRMLS_CC);
-#else
+ PHPDBG_G(in_execution) = 1;
-#undef EX
-#define EX(element) execute_data->element
-#undef EX_CV
-#define EX_CV(var) EX(CVs)[var]
-#undef EX_CVs
-#define EX_CVs() EX(CVs)
-#undef EX_T
-#define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset))
-#undef EX_Ts
-#define EX_Ts() EX(Ts)
-
- zend_execute_data *execute_data = (zend_execute_data *)zend_vm_stack_alloc(
- ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) +
- ZEND_MM_ALIGNED_SIZE(sizeof(zval**) * op_array->last_var * (EG(active_symbol_table) ? 1 : 2)) +
- ZEND_MM_ALIGNED_SIZE(sizeof(temp_variable)) * op_array->T TSRMLS_CC);
-
- EX(CVs) = (zval***)((char*)execute_data + ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)));
- memset(EX(CVs), 0, sizeof(zval**) * op_array->last_var);
- EX(Ts) = (temp_variable *)(((char*)EX(CVs)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval**) * op_array->last_var * (EG(active_symbol_table) ? 1 : 2)));
- EX(fbc) = NULL;
- EX(called_scope) = NULL;
- EX(object) = NULL;
- EX(old_error_reporting) = NULL;
- EX(op_array) = op_array;
- EX(symbol_table) = EG(active_symbol_table);
- EX(prev_execute_data) = EG(current_execute_data);
- EG(current_execute_data) = execute_data;
- EX(nested) = nested;
-
- if (!op_array->run_time_cache && op_array->last_cache_slot) {
- op_array->run_time_cache = ecalloc(op_array->last_cache_slot, sizeof(void*));
- }
+ while (1) {
+ zend_object *exception = EG(exception);
- if (op_array->this_var != -1 && EG(This)) {
- Z_ADDREF_P(EG(This)); /* For $this pointer */
- if (!EG(active_symbol_table)) {
- EX_CV(op_array->this_var) = (zval**)EX_CVs() + (op_array->last_var + op_array->this_var);
- *EX_CV(op_array->this_var) = EG(This);
- } else {
- if (zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), (void**)&EX_CV(op_array->this_var))==FAILURE) {
- Z_DELREF_P(EG(This));
- }
+ if ((PHPDBG_G(flags) & PHPDBG_BP_RESOLVE_MASK)) {
+ /* resolve nth opline breakpoints */
+ phpdbg_resolve_op_array_breaks(&execute_data->func->op_array);
}
- }
- EX(opline) = UNEXPECTED((op_array->fn_flags & ZEND_ACC_INTERACTIVE) != 0) && EG(start_op) ? EG(start_op) : op_array->opcodes;
- EG(opline_ptr) = &EX(opline);
+#ifdef ZEND_WIN32
+ if (EG(timed_out)) {
+ zend_timeout(0);
+ }
+#endif
- EX(function_state).function = (zend_function *) op_array;
- EX(function_state).arguments = NULL;
+ if (PHPDBG_G(flags) & PHPDBG_PREVENT_INTERACTIVE) {
+ phpdbg_print_opline_ex(execute_data, 0);
+ goto next;
+ }
- return execute_data;
-#endif
-} /* }}} */
+ /* check for uncaught exceptions */
+ if (exception && PHPDBG_G(handled_exception) != exception && !(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) {
+ zend_execute_data *prev_ex = execute_data;
+ zval zv, rv;
+ zend_string *file, *msg;
+ zend_long line;
+
+ do {
+ prev_ex = zend_generator_check_placeholder_frame(prev_ex);
+ /* assuming that no internal functions will silently swallow exceptions ... */
+ if (!prev_ex->func || !ZEND_USER_CODE(prev_ex->func->common.type)) {
+ continue;
+ }
-#if PHP_VERSION_ID >= 50500
-void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC) /* {{{ */
-{
-#else
-void phpdbg_execute_ex(zend_op_array *op_array TSRMLS_DC) /* {{{ */
-{
- long long flags = 0;
- zend_ulong address = 0L;
- zend_execute_data *execute_data;
- zend_bool nested = 0;
-#endif
- zend_bool original_in_execution = EG(in_execution);
- HashTable vars;
+ if (phpdbg_check_caught_ex(prev_ex, exception)) {
+ goto ex_is_caught;
+ }
+ } while ((prev_ex = prev_ex->prev_execute_data));
-#if PHP_VERSION_ID < 50500
- if (EG(exception)) {
- return;
- }
-#endif
+ PHPDBG_G(handled_exception) = exception;
- EG(in_execution) = 1;
+ ZVAL_OBJ(&zv, exception);
+ file = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("file"), 1, &rv));
+ line = zval_get_long(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("line"), 1, &rv));
+ msg = zval_get_string(zend_read_property(zend_get_exception_base(&zv), &zv, ZEND_STRL("message"), 1, &rv));
-#if PHP_VERSION_ID >= 50500
- if (0) {
-zend_vm_enter:
- execute_data = phpdbg_create_execute_data(EG(active_op_array), 1 TSRMLS_CC);
- }
- zend_hash_init(&vars, EG(active_op_array)->last, NULL, NULL, 0);
-#else
-zend_vm_enter:
- execute_data = phpdbg_create_execute_data(op_array, nested TSRMLS_CC);
- nested = 1;
- zend_hash_init(&vars, EG(active_op_array)->last, NULL, NULL, 0);
-#endif
+ phpdbg_error("exception", "name=\"%s\" file=\"%s\" line=\"" ZEND_LONG_FMT "\"", "Uncaught %s in %s on line " ZEND_LONG_FMT ": %.*s", ZSTR_VAL(exception->ce->name), ZSTR_VAL(file), line, ZSTR_LEN(msg) < 80 ? ZSTR_LEN(msg) : 80, ZSTR_VAL(msg));
+ zend_string_release(msg);
+ zend_string_release(file);
- while (1) {
-
- if ((PHPDBG_G(flags) & PHPDBG_BP_RESOLVE_MASK)) {
- /* resolve nth opline breakpoints */
- phpdbg_resolve_op_array_breaks(EG(active_op_array) TSRMLS_CC);
+ DO_INTERACTIVE(1);
}
-
-#ifdef ZEND_WIN32
- if (EG(timed_out)) {
- zend_timeout(0);
- }
-#endif
-
-#define DO_INTERACTIVE() do { \
- if (!(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) { \
- phpdbg_list_file( \
- zend_get_executed_filename(TSRMLS_C), \
- 3, \
- zend_get_executed_lineno(TSRMLS_C)-1, \
- zend_get_executed_lineno(TSRMLS_C) \
- TSRMLS_CC \
- ); \
- } \
- \
-/* do { */\
- switch (phpdbg_interactive(TSRMLS_C)) { \
- case PHPDBG_LEAVE: \
- case PHPDBG_FINISH: \
- case PHPDBG_UNTIL: \
- case PHPDBG_NEXT:{ \
- goto next; \
- } \
- } \
-/* } while (!(PHPDBG_G(flags) & PHPDBG_IS_QUITTING)); */\
-} while (0)
+ex_is_caught:
- /* allow conditional breakpoints and
- initialization to access the vm uninterrupted */
- if ((PHPDBG_G(flags) & PHPDBG_IN_COND_BP) ||
- (PHPDBG_G(flags) & PHPDBG_IS_INITIALIZING)) {
+ /* allow conditional breakpoints and initialization to access the vm uninterrupted */
+ if (PHPDBG_G(flags) & (PHPDBG_IN_COND_BP | PHPDBG_IS_INITIALIZING)) {
/* skip possible breakpoints */
goto next;
}
/* perform seek operation */
- if (PHPDBG_G(flags) & PHPDBG_SEEK_MASK) {
+ if ((PHPDBG_G(flags) & PHPDBG_SEEK_MASK) && !(PHPDBG_G(flags) & PHPDBG_IN_EVAL)) {
/* current address */
zend_ulong address = (zend_ulong) execute_data->opline;
+ if (PHPDBG_G(seek_ex) != execute_data) {
+ goto next;
+ }
+
+#define INDEX_EXISTS_CHECK (zend_hash_index_exists(&PHPDBG_G(seek), address) || (exception && phpdbg_check_caught_ex(execute_data, exception) == 0))
+
/* run to next line */
if (PHPDBG_G(flags) & PHPDBG_IN_UNTIL) {
- if (zend_hash_index_exists(&PHPDBG_G(seek), address)) {
+ if (INDEX_EXISTS_CHECK) {
PHPDBG_G(flags) &= ~PHPDBG_IN_UNTIL;
- zend_hash_clean(
- &PHPDBG_G(seek));
+ zend_hash_clean(&PHPDBG_G(seek));
} else {
/* skip possible breakpoints */
goto next;
@@ -1242,10 +1556,9 @@ zend_vm_enter:
/* run to finish */
if (PHPDBG_G(flags) & PHPDBG_IN_FINISH) {
- if (zend_hash_index_exists(&PHPDBG_G(seek), address)) {
+ if (INDEX_EXISTS_CHECK) {
PHPDBG_G(flags) &= ~PHPDBG_IN_FINISH;
- zend_hash_clean(
- &PHPDBG_G(seek));
+ zend_hash_clean(&PHPDBG_G(seek));
}
/* skip possible breakpoints */
goto next;
@@ -1253,16 +1566,14 @@ zend_vm_enter:
/* break for leave */
if (PHPDBG_G(flags) & PHPDBG_IN_LEAVE) {
- if (zend_hash_index_exists(&PHPDBG_G(seek), address)) {
+ if (INDEX_EXISTS_CHECK) {
PHPDBG_G(flags) &= ~PHPDBG_IN_LEAVE;
- zend_hash_clean(
- &PHPDBG_G(seek));
- phpdbg_notice(
- "Breaking for leave at %s:%u",
- zend_get_executed_filename(TSRMLS_C),
- zend_get_executed_lineno(TSRMLS_C)
+ zend_hash_clean(&PHPDBG_G(seek));
+ phpdbg_notice("breakpoint", "id=\"leave\" file=\"%s\" line=\"%u\"", "Breaking for leave at %s:%u",
+ zend_get_executed_filename(),
+ zend_get_executed_lineno()
);
- DO_INTERACTIVE();
+ DO_INTERACTIVE(1);
} else {
/* skip possible breakpoints */
goto next;
@@ -1271,18 +1582,17 @@ zend_vm_enter:
}
/* not while in conditionals */
- phpdbg_print_opline_ex(
- execute_data, &vars, 0 TSRMLS_CC);
+ phpdbg_print_opline_ex(execute_data, 0);
if (PHPDBG_G(flags) & PHPDBG_IS_STEPPING && (PHPDBG_G(flags) & PHPDBG_STEP_OPCODE || execute_data->opline->lineno != PHPDBG_G(last_line))) {
PHPDBG_G(flags) &= ~PHPDBG_IS_STEPPING;
- DO_INTERACTIVE();
+ DO_INTERACTIVE(1);
}
/* check if some watchpoint was hit */
{
- if (phpdbg_print_changed_zvals(TSRMLS_C) == SUCCESS) {
- DO_INTERACTIVE();
+ if (phpdbg_print_changed_zvals() == SUCCESS) {
+ DO_INTERACTIVE(1);
}
}
@@ -1291,45 +1601,94 @@ zend_vm_enter:
phpdbg_breakbase_t *brake;
if ((PHPDBG_G(flags) & PHPDBG_BP_MASK)
- && (brake = phpdbg_find_breakpoint(execute_data TSRMLS_CC))
+ && (brake = phpdbg_find_breakpoint(execute_data))
&& (brake->type != PHPDBG_BREAK_FILE || execute_data->opline->lineno != PHPDBG_G(last_line))) {
- phpdbg_hit_breakpoint(brake, 1 TSRMLS_CC);
- DO_INTERACTIVE();
+ phpdbg_hit_breakpoint(brake, 1);
+ DO_INTERACTIVE(1);
}
}
-next:
if (PHPDBG_G(flags) & PHPDBG_IS_SIGNALED) {
- phpdbg_writeln(EMPTY);
- phpdbg_notice("Program received signal SIGINT");
PHPDBG_G(flags) &= ~PHPDBG_IS_SIGNALED;
- DO_INTERACTIVE();
+
+ phpdbg_out("\n");
+ phpdbg_notice("signal", "type=\"SIGINT\"", "Program received signal SIGINT");
+ DO_INTERACTIVE(1);
}
+next:
+
PHPDBG_G(last_line) = execute_data->opline->lineno;
- PHPDBG_G(vmret) = execute_data->opline->handler(execute_data TSRMLS_CC);
+ /* stupid hack to make zend_do_fcall_common_helper return ZEND_VM_ENTER() instead of recursively calling zend_execute() and eventually segfaulting */
+ if ((execute_data->opline->opcode == ZEND_DO_FCALL ||
+ execute_data->opline->opcode == ZEND_DO_UCALL ||
+ execute_data->opline->opcode == ZEND_DO_FCALL_BY_NAME) &&
+ execute_data->call->func->type == ZEND_USER_FUNCTION) {
+ zend_execute_ex = execute_ex;
+ }
+ PHPDBG_G(vmret) = zend_vm_call_opcode_handler(execute_data);
+ zend_execute_ex = phpdbg_execute_ex;
- if (PHPDBG_G(vmret) > 0) {
- switch (PHPDBG_G(vmret)) {
- case 1:
- EG(in_execution) = original_in_execution;
- zend_hash_destroy(&vars);
- return;
- case 2:
-#if PHP_VERSION_ID < 50500
- op_array = EG(active_op_array);
-#endif
- zend_hash_destroy(&vars);
- goto zend_vm_enter;
- break;
- case 3:
- execute_data = EG(current_execute_data);
- break;
- default:
- break;
+ if (PHPDBG_G(vmret) != 0) {
+ if (PHPDBG_G(vmret) < 0) {
+ PHPDBG_G(in_execution) = original_in_execution;
+ return;
+ } else {
+ execute_data = EG(current_execute_data);
}
}
}
zend_error_noreturn(E_ERROR, "Arrived at end of main loop which shouldn't happen");
} /* }}} */
+
+/* only if *not* interactive and while executing */
+void phpdbg_force_interruption(void) /* {{{ */ {
+ zend_object *exception = EG(exception);
+ zend_execute_data *data = EG(current_execute_data); /* should be always readable if not NULL */
+
+ PHPDBG_G(flags) |= PHPDBG_IN_SIGNAL_HANDLER;
+
+ if (data) {
+ if (data->func) {
+ if (ZEND_USER_CODE(data->func->type)) {
+ phpdbg_notice("hardinterrupt", "opline=\"%p\" num=\"%lu\" file=\"%s\" line=\"%u\"", "Current opline: %p (op #%lu) in %s:%u", data->opline, (data->opline - data->func->op_array.opcodes) / sizeof(data->opline), data->func->op_array.filename->val, data->opline->lineno);
+ } else if (data->func->internal_function.function_name) {
+ phpdbg_notice("hardinterrupt", "func=\"%s\"", "Current opline: in internal function %s", data->func->internal_function.function_name->val);
+ } else {
+ phpdbg_notice("hardinterrupt", "", "Current opline: executing internal code");
+ }
+ } else {
+ phpdbg_notice("hardinterrupt", "opline=\"%p\"", "Current opline: %p (op_array information unavailable)", data->opline);
+ }
+ } else {
+ phpdbg_notice("hardinterrupt", "", "No information available about executing context");
+ }
+
+ DO_INTERACTIVE(0);
+
+next:
+ PHPDBG_G(flags) &= ~PHPDBG_IN_SIGNAL_HANDLER;
+
+ if (PHPDBG_G(flags) & PHPDBG_IS_STOPPING) {
+ zend_bailout();
+ }
+}
+/* }}} */
+
+PHPDBG_COMMAND(eol) /* {{{ */
+{
+ if (!param || param->type == EMPTY_PARAM) {
+ phpdbg_notice("eol", "argument required", "argument required");
+ } else switch (param->type) {
+ case STR_PARAM:
+ if (FAILURE == phpdbg_eol_global_update(param->str)) {
+ phpdbg_notice("eol", "unknown EOL name '%s', give crlf, lf, cr", "unknown EOL name '%s', give crlf, lf, cr", param->str);
+ }
+ break;
+
+ phpdbg_default_switch_case();
+ }
+
+ return SUCCESS;
+} /* }}} */
diff --git a/sapi/phpdbg/phpdbg_prompt.h b/sapi/phpdbg/phpdbg_prompt.h
index 5a0ea4bad3..4dd010035c 100644
--- a/sapi/phpdbg/phpdbg_prompt.h
+++ b/sapi/phpdbg/phpdbg_prompt.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -22,11 +22,13 @@
#define PHPDBG_PROMPT_H
/* {{{ */
-void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default TSRMLS_DC);
-void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init TSRMLS_DC);
-int phpdbg_interactive(TSRMLS_D);
-int phpdbg_compile(TSRMLS_D);
-void phpdbg_clean(zend_bool full TSRMLS_DC); /* }}} */
+void phpdbg_string_init(char *buffer);
+void phpdbg_init(char *init_file, size_t init_file_len, zend_bool use_default);
+void phpdbg_try_file_init(char *init_file, size_t init_file_len, zend_bool free_init);
+int phpdbg_interactive(zend_bool allow_async_unsafe);
+int phpdbg_compile(void);
+void phpdbg_force_interruption(void);
+/* }}} */
/* {{{ phpdbg command handlers */
PHPDBG_COMMAND(exec);
@@ -47,21 +49,20 @@ PHPDBG_COMMAND(clean);
PHPDBG_COMMAND(clear);
PHPDBG_COMMAND(help);
PHPDBG_COMMAND(sh);
+PHPDBG_COMMAND(dl);
PHPDBG_COMMAND(set);
PHPDBG_COMMAND(source);
PHPDBG_COMMAND(export);
PHPDBG_COMMAND(register);
PHPDBG_COMMAND(quit);
-PHPDBG_COMMAND(watch); /* }}} */
+PHPDBG_COMMAND(watch);
+PHPDBG_COMMAND(next);
+PHPDBG_COMMAND(eol);
+PHPDBG_COMMAND(wait); /* }}} */
/* {{{ prompt commands */
extern const phpdbg_command_t phpdbg_prompt_commands[]; /* }}} */
-/* {{{ */
-#if PHP_VERSION_ID >= 50500
-void phpdbg_execute_ex(zend_execute_data *execute_data TSRMLS_DC);
-#else
-void phpdbg_execute_ex(zend_op_array *op_array TSRMLS_DC);
-#endif /* }}} */
+void phpdbg_execute_ex(zend_execute_data *execute_data);
#endif /* PHPDBG_PROMPT_H */
diff --git a/sapi/phpdbg/phpdbg_rinit_hook.c b/sapi/phpdbg/phpdbg_rinit_hook.c
new file mode 100644
index 0000000000..248b8a323e
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_rinit_hook.c
@@ -0,0 +1,105 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Bob Weinand <bwoebi@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#include "phpdbg_rinit_hook.h"
+#include "php_ini.h"
+#include <errno.h>
+
+ZEND_DECLARE_MODULE_GLOBALS(phpdbg_webhelper);
+
+PHP_INI_BEGIN()
+ STD_PHP_INI_ENTRY("phpdbg.auth", "", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdateString, auth, zend_phpdbg_webhelper_globals, phpdbg_webhelper_globals)
+ STD_PHP_INI_ENTRY("phpdbg.path", "", PHP_INI_SYSTEM | PHP_INI_PERDIR, OnUpdateString, path, zend_phpdbg_webhelper_globals, phpdbg_webhelper_globals)
+PHP_INI_END()
+
+static inline void php_phpdbg_webhelper_globals_ctor(zend_phpdbg_webhelper_globals *pg) /* {{{ */
+{
+} /* }}} */
+
+static PHP_MINIT_FUNCTION(phpdbg_webhelper) /* {{{ */
+{
+ if (!strcmp(sapi_module.name, PHPDBG_NAME)) {
+ return SUCCESS;
+ }
+
+ ZEND_INIT_MODULE_GLOBALS(phpdbg_webhelper, php_phpdbg_webhelper_globals_ctor, NULL);
+ REGISTER_INI_ENTRIES();
+
+ return SUCCESS;
+} /* }}} */
+
+static PHP_RINIT_FUNCTION(phpdbg_webhelper) /* {{{ */
+{
+ zval cookies = PG(http_globals)[TRACK_VARS_COOKIE];
+ zval *auth;
+
+ if (Z_TYPE(cookies) == IS_ARRAY || (auth = zend_hash_str_find(Z_ARRVAL(cookies), PHPDBG_NAME "_AUTH_COOKIE", sizeof(PHPDBG_NAME "_AUTH_COOKIE"))) || Z_STRLEN_P(auth) != strlen(PHPDBG_WG(auth)) || strcmp(Z_STRVAL_P(auth), PHPDBG_WG(auth))) {
+ return SUCCESS;
+ }
+
+#ifndef _WIN32
+ {
+ struct sockaddr_un sock;
+ int s = socket(AF_UNIX, SOCK_STREAM, 0);
+ int len = strlen(PHPDBG_WG(path)) + sizeof(sock.sun_family);
+ char buf[(1 << 8) + 1];
+ int buflen;
+ sock.sun_family = AF_UNIX;
+ strcpy(sock.sun_path, PHPDBG_WG(path));
+
+ if (connect(s, (struct sockaddr *)&sock, len) == -1) {
+ zend_error(E_ERROR, "Unable to connect to UNIX domain socket at %s defined by phpdbg.path ini setting. Reason: %s", PHPDBG_WG(path), strerror(errno));
+ }
+
+ char *msg = NULL;
+ char msglen[5] = {0};
+ phpdbg_webdata_compress(&msg, (int *)msglen);
+
+ send(s, msglen, 4, 0);
+ send(s, msg, *(int *) msglen, 0);
+
+ while ((buflen = recv(s, buf, sizeof(buf) - 1, 0)) > 0) {
+ php_write(buf, buflen);
+ }
+
+ close(s);
+
+ php_output_flush_all();
+ zend_bailout();
+ }
+#endif
+
+ return SUCCESS;
+} /* }}} */
+
+zend_module_entry phpdbg_webhelper_module_entry = {
+ STANDARD_MODULE_HEADER,
+ "phpdbg_webhelper",
+ NULL,
+ PHP_MINIT(phpdbg_webhelper),
+ NULL,
+ PHP_RINIT(phpdbg_webhelper),
+ NULL,
+ NULL,
+ PHPDBG_VERSION,
+ STANDARD_MODULE_PROPERTIES
+};
+
+#ifdef COMPILE_DL_PHPDBG_WEBHELPER
+ZEND_GET_MODULE(phpdbg_webhelper)
+#endif
diff --git a/sapi/phpdbg/phpdbg_rinit_hook.h b/sapi/phpdbg/phpdbg_rinit_hook.h
new file mode 100644
index 0000000000..69d4f61285
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_rinit_hook.h
@@ -0,0 +1,41 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Felipe Pena <felipe@php.net> |
+ | Authors: Joe Watkins <joe.watkins@live.co.uk> |
+ | Authors: Bob Weinand <bwoebi@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#ifndef PHPDBG_WEBHELPER_H
+#define PHPDBG_WEBHELPER_H
+
+#include "phpdbg_webdata_transfer.h"
+
+extern zend_module_entry phpdbg_webhelper_module_entry;
+#define phpext_phpdbg_webhelper_ptr &phpdbg_webhelper_module_entry
+
+#ifdef ZTS
+# define PHPDBG_WG(v) TSRMG(phpdbg_webhelper_globals_id, zend_phpdbg_webhelper_globals *, v)
+#else
+# define PHPDBG_WG(v) (phpdbg_webhelper_globals.v)
+#endif
+
+/* {{{ structs */
+ZEND_BEGIN_MODULE_GLOBALS(phpdbg_webhelper)
+ char *auth;
+ char *path;
+ZEND_END_MODULE_GLOBALS(phpdbg_webhelper) /* }}} */
+
+#endif /* PHPDBG_WEBHELPER_H */
diff --git a/sapi/phpdbg/phpdbg_set.c b/sapi/phpdbg/phpdbg_set.c
index b9ff097751..5af2c593c8 100644
--- a/sapi/phpdbg/phpdbg_set.c
+++ b/sapi/phpdbg/phpdbg_set.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -27,29 +27,69 @@
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
-#define PHPDBG_SET_COMMAND_D(f, h, a, m, l, s) \
- PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[18])
+#define PHPDBG_SET_COMMAND_D(f, h, a, m, l, s, flags) \
+ PHPDBG_COMMAND_D_EXP(f, h, a, m, l, s, &phpdbg_prompt_commands[17], flags)
const phpdbg_command_t phpdbg_set_commands[] = {
- PHPDBG_SET_COMMAND_D(prompt, "usage: set prompt [<string>]", 'p', set_prompt, NULL, "|s"),
+ PHPDBG_SET_COMMAND_D(prompt, "usage: set prompt [<string>]", 'p', set_prompt, NULL, "|s", 0),
+ PHPDBG_SET_COMMAND_D(pagination, "usage: set pagination [<on|off>]", 'P', set_pagination, NULL, "|b", PHPDBG_ASYNC_SAFE),
#ifndef _WIN32
- PHPDBG_SET_COMMAND_D(color, "usage: set color <element> <color>", 'c', set_color, NULL, "ss"),
- PHPDBG_SET_COMMAND_D(colors, "usage: set colors [<on|off>]", 'C', set_colors, NULL, "|b"),
+ PHPDBG_SET_COMMAND_D(color, "usage: set color <element> <color>", 'c', set_color, NULL, "ss", PHPDBG_ASYNC_SAFE),
+ PHPDBG_SET_COMMAND_D(colors, "usage: set colors [<on|off>]", 'C', set_colors, NULL, "|b", PHPDBG_ASYNC_SAFE),
#endif
- PHPDBG_SET_COMMAND_D(oplog, "usage: set oplog [<output>]", 'O', set_oplog, NULL, "|s"),
- PHPDBG_SET_COMMAND_D(break, "usage: set break id [<on|off>]", 'b', set_break, NULL, "l|b"),
- PHPDBG_SET_COMMAND_D(breaks, "usage: set breaks [<on|off>]", 'B', set_breaks, NULL, "|b"),
- PHPDBG_SET_COMMAND_D(quiet, "usage: set quiet [<on|off>]", 'q', set_quiet, NULL, "|b"),
- PHPDBG_SET_COMMAND_D(stepping, "usage: set stepping [<line|op>]", 's', set_stepping, NULL, "|s"),
- PHPDBG_SET_COMMAND_D(refcount, "usage: set refcount [<on|off>]", 'r', set_refcount, NULL, "|b"),
+ PHPDBG_SET_COMMAND_D(oplog, "usage: set oplog [<output>]", 'O', set_oplog, NULL, "|s", 0),
+ PHPDBG_SET_COMMAND_D(break, "usage: set break id [<on|off>]", 'b', set_break, NULL, "l|b", PHPDBG_ASYNC_SAFE),
+ PHPDBG_SET_COMMAND_D(breaks, "usage: set breaks [<on|off>]", 'B', set_breaks, NULL, "|b", PHPDBG_ASYNC_SAFE),
+ PHPDBG_SET_COMMAND_D(quiet, "usage: set quiet [<on|off>]", 'q', set_quiet, NULL, "|b", PHPDBG_ASYNC_SAFE),
+ PHPDBG_SET_COMMAND_D(stepping, "usage: set stepping [<line|op>]", 's', set_stepping, NULL, "|s", PHPDBG_ASYNC_SAFE),
+ PHPDBG_SET_COMMAND_D(refcount, "usage: set refcount [<on|off>]", 'r', set_refcount, NULL, "|b", PHPDBG_ASYNC_SAFE),
+ PHPDBG_SET_COMMAND_D(lines, "usage: set lines [<number>]", 'l', set_lines, NULL, "|l", PHPDBG_ASYNC_SAFE),
PHPDBG_END_COMMAND
};
PHPDBG_SET(prompt) /* {{{ */
{
if (!param || param->type == EMPTY_PARAM) {
- phpdbg_writeln("%s", phpdbg_get_prompt(TSRMLS_C));
- } else phpdbg_set_prompt(param->str TSRMLS_CC);
+ phpdbg_writeln("setprompt", "str=\"%s\"", "Current prompt: %s", phpdbg_get_prompt());
+ } else {
+ phpdbg_set_prompt(param->str);
+ }
+
+ return SUCCESS;
+} /* }}} */
+
+PHPDBG_SET(pagination) /* {{{ */
+{
+ if (!param || param->type == EMPTY_PARAM) {
+ phpdbg_writeln("setpagination", "active=\"%s\"", "Pagination %s", PHPDBG_G(flags) & PHPDBG_HAS_PAGINATION ? "on" : "off");
+ } else switch (param->type) {
+ case NUMERIC_PARAM: {
+ if (param->num) {
+ PHPDBG_G(flags) |= PHPDBG_HAS_PAGINATION;
+ } else {
+ PHPDBG_G(flags) &= ~PHPDBG_HAS_PAGINATION;
+ }
+ } break;
+
+ default:
+ phpdbg_error("setpagination", "type=\"wrongargs\"", "set pagination used incorrectly: set pagination <on|off>");
+ }
+
+ return SUCCESS;
+} /* }}} */
+
+PHPDBG_SET(lines) /* {{{ */
+{
+ if (!param || param->type == EMPTY_PARAM) {
+ phpdbg_writeln("setlines", "active=\"%s\"", "Lines %ld", PHPDBG_G(lines));
+ } else switch (param->type) {
+ case NUMERIC_PARAM: {
+ PHPDBG_G(lines) = param->num;
+ } break;
+
+ default:
+ phpdbg_error("setlines", "type=\"wrongargs\"", "set lines used incorrectly: set lines <number>");
+ }
return SUCCESS;
} /* }}} */
@@ -60,22 +100,22 @@ PHPDBG_SET(break) /* {{{ */
case NUMERIC_PARAM: {
if (param->next) {
if (param->next->num) {
- phpdbg_enable_breakpoint(param->num TSRMLS_CC);
- } else phpdbg_disable_breakpoint(param->num TSRMLS_CC);
+ phpdbg_enable_breakpoint(param->num);
+ } else {
+ phpdbg_disable_breakpoint(param->num);
+ }
} else {
- phpdbg_breakbase_t *brake = phpdbg_find_breakbase(param->num TSRMLS_CC);
+ phpdbg_breakbase_t *brake = phpdbg_find_breakbase(param->num);
if (brake) {
- phpdbg_writeln(
- "%s", brake->disabled ? "off" : "on");
+ phpdbg_writeln("setbreak", "id=\"%ld\" active=\"%s\"", "Breakpoint #%ld %s", param->num, brake->disabled ? "off" : "on");
} else {
- phpdbg_error("Failed to find breakpoint #%ld", param->num);
+ phpdbg_error("setbreak", "type=\"nobreak\" id=\"%ld\"", "Failed to find breakpoint #%ld", param->num);
}
}
} break;
default:
- phpdbg_error(
- "set break used incorrectly: set break [id] <on|off>");
+ phpdbg_error("setbreak", "type=\"wrongargs\"", "set break used incorrectly: set break [id] <on|off>");
}
return SUCCESS;
@@ -84,18 +124,18 @@ PHPDBG_SET(break) /* {{{ */
PHPDBG_SET(breaks) /* {{{ */
{
if (!param || param->type == EMPTY_PARAM) {
- phpdbg_writeln("%s",
- PHPDBG_G(flags) & PHPDBG_IS_BP_ENABLED ? "on" : "off");
- } else switch (param->type) {
+ phpdbg_writeln("setbreaks", "active=\"%s\"", "Breakpoints %s",PHPDBG_G(flags) & PHPDBG_IS_BP_ENABLED ? "on" : "off");
+ } else switch (param->type) {
case NUMERIC_PARAM: {
if (param->num) {
- phpdbg_enable_breakpoints(TSRMLS_C);
- } else phpdbg_disable_breakpoints(TSRMLS_C);
+ phpdbg_enable_breakpoints();
+ } else {
+ phpdbg_disable_breakpoints();
+ }
} break;
default:
- phpdbg_error(
- "set break used incorrectly: set break [id] <on|off>");
+ phpdbg_error("setbreaks", "type=\"wrongargs\"", "set breaks used incorrectly: set breaks <on|off>");
}
return SUCCESS;
@@ -104,41 +144,35 @@ PHPDBG_SET(breaks) /* {{{ */
#ifndef _WIN32
PHPDBG_SET(color) /* {{{ */
{
- const phpdbg_color_t *color = phpdbg_get_color(
- param->next->str, param->next->len TSRMLS_CC);
-
+ const phpdbg_color_t *color = phpdbg_get_color(param->next->str, param->next->len);
+
if (!color) {
- phpdbg_error(
- "Failed to find the requested color (%s)", param->next->str);
+ phpdbg_error("setcolor", "type=\"nocolor\"", "Failed to find the requested color (%s)", param->next->str);
return SUCCESS;
}
-
- switch (phpdbg_get_element(param->str, param->len TSRMLS_CC)) {
+
+ switch (phpdbg_get_element(param->str, param->len)) {
case PHPDBG_COLOR_PROMPT:
- phpdbg_notice(
- "setting prompt color to %s (%s)", color->name, color->code);
+ phpdbg_notice("setcolor", "type=\"prompt\" color=\"%s\" code=\"%s\"", "setting prompt color to %s (%s)", color->name, color->code);
if (PHPDBG_G(prompt)[1]) {
free(PHPDBG_G(prompt)[1]);
PHPDBG_G(prompt)[1]=NULL;
}
- phpdbg_set_color(PHPDBG_COLOR_PROMPT, color TSRMLS_CC);
+ phpdbg_set_color(PHPDBG_COLOR_PROMPT, color);
break;
-
+
case PHPDBG_COLOR_ERROR:
- phpdbg_notice(
- "setting error color to %s (%s)", color->name, color->code);
- phpdbg_set_color(PHPDBG_COLOR_ERROR, color TSRMLS_CC);
+ phpdbg_notice("setcolor", "type=\"error\" color=\"%s\" code=\"%s\"", "setting error color to %s (%s)", color->name, color->code);
+ phpdbg_set_color(PHPDBG_COLOR_ERROR, color);
break;
-
+
case PHPDBG_COLOR_NOTICE:
- phpdbg_notice(
- "setting notice color to %s (%s)", color->name, color->code);
- phpdbg_set_color(PHPDBG_COLOR_NOTICE, color TSRMLS_CC);
+ phpdbg_notice("setcolor", "type=\"notice\" color=\"%s\" code=\"%s\"", "setting notice color to %s (%s)", color->name, color->code);
+ phpdbg_set_color(PHPDBG_COLOR_NOTICE, color);
break;
-
+
default:
- phpdbg_error(
- "Failed to find the requested element (%s)", param->str);
+ phpdbg_error("setcolor", "type=\"invalidtype\"", "Failed to find the requested element (%s)", param->str);
}
return SUCCESS;
@@ -147,7 +181,7 @@ PHPDBG_SET(color) /* {{{ */
PHPDBG_SET(colors) /* {{{ */
{
if (!param || param->type == EMPTY_PARAM) {
- phpdbg_writeln("%s", PHPDBG_G(flags) & PHPDBG_IS_COLOURED ? "on" : "off");
+ phpdbg_writeln("setcolors", "active=\"%s\"", "Colors %s", PHPDBG_G(flags) & PHPDBG_IS_COLOURED ? "on" : "off");
} else switch (param->type) {
case NUMERIC_PARAM: {
if (param->num) {
@@ -156,10 +190,9 @@ PHPDBG_SET(colors) /* {{{ */
PHPDBG_G(flags) &= ~PHPDBG_IS_COLOURED;
}
} break;
-
+
default:
- phpdbg_error(
- "set colors used incorrectly: set colors <on|off>");
+ phpdbg_error("setcolors", "type=\"wrongargs\"", "set colors used incorrectly: set colors <on|off>");
}
return SUCCESS;
@@ -169,7 +202,7 @@ PHPDBG_SET(colors) /* {{{ */
PHPDBG_SET(oplog) /* {{{ */
{
if (!param || param->type == EMPTY_PARAM) {
- phpdbg_notice("Oplog %s", PHPDBG_G(oplog) ? "enabled" : "disabled");
+ phpdbg_notice("setoplog", "active=\"%s\"", "Oplog %s", PHPDBG_G(oplog) ? "on" : "off");
} else switch (param->type) {
case STR_PARAM: {
/* open oplog */
@@ -177,14 +210,15 @@ PHPDBG_SET(oplog) /* {{{ */
PHPDBG_G(oplog) = fopen(param->str, "w+");
if (!PHPDBG_G(oplog)) {
- phpdbg_error("Failed to open %s for oplog", param->str);
+ phpdbg_error("setoplog", "type=\"openfailure\" file=\"%s\"", "Failed to open %s for oplog", param->str);
PHPDBG_G(oplog) = old;
} else {
if (old) {
- phpdbg_notice("Closing previously open oplog");
+ phpdbg_notice("setoplog", "type=\"closingold\"", "Closing previously open oplog");
fclose(old);
}
- phpdbg_notice("Successfully opened oplog %s", param->str);
+
+ phpdbg_notice("setoplog", "file=\"%s\"", "Successfully opened oplog %s", param->str);
}
} break;
@@ -197,8 +231,7 @@ PHPDBG_SET(oplog) /* {{{ */
PHPDBG_SET(quiet) /* {{{ */
{
if (!param || param->type == EMPTY_PARAM) {
- phpdbg_writeln("Quietness %s",
- PHPDBG_G(flags) & PHPDBG_IS_QUIET ? "on" : "off");
+ phpdbg_writeln("setquiet", "active=\"%s\"", "Quietness %s", PHPDBG_G(flags) & PHPDBG_IS_QUIET ? "on" : "off");
} else switch (param->type) {
case NUMERIC_PARAM: {
if (param->num) {
@@ -217,18 +250,15 @@ PHPDBG_SET(quiet) /* {{{ */
PHPDBG_SET(stepping) /* {{{ */
{
if (!param || param->type == EMPTY_PARAM) {
- phpdbg_writeln("Stepping %s",
- PHPDBG_G(flags) & PHPDBG_STEP_OPCODE ? "opcode" : "line");
+ phpdbg_writeln("setstepping", "type=\"%s\"", "Stepping %s", PHPDBG_G(flags) & PHPDBG_STEP_OPCODE ? "opcode" : "line");
} else switch (param->type) {
- case STR_PARAM: {
- if ((param->len == sizeof("opcode")-1) &&
- (memcmp(param->str, "opcode", sizeof("opcode")) == SUCCESS)) {
+ case STR_PARAM: {
+ if (param->len == sizeof("opcode") - 1 && !memcmp(param->str, "opcode", sizeof("opcode"))) {
PHPDBG_G(flags) |= PHPDBG_STEP_OPCODE;
- } else if ((param->len == sizeof("line")-1) &&
- (memcmp(param->str, "line", sizeof("line")) == SUCCESS)) {
+ } else if (param->len == sizeof("line") - 1 && !memcmp(param->str, "line", sizeof("line"))) {
PHPDBG_G(flags) &= ~PHPDBG_STEP_OPCODE;
} else {
- phpdbg_error("usage set stepping [<opcode|line>]");
+ phpdbg_error("setstepping", "type=\"wrongargs\"", "usage set stepping [<opcode|line>]");
}
} break;
@@ -241,7 +271,7 @@ PHPDBG_SET(stepping) /* {{{ */
PHPDBG_SET(refcount) /* {{{ */
{
if (!param || param->type == EMPTY_PARAM) {
- phpdbg_writeln("Refcount %s", PHPDBG_G(flags) & PHPDBG_IS_QUIET ? "on" : "off");
+ phpdbg_writeln("setrefcount", "active=\"%s\"", "Showing refcounts %s", PHPDBG_G(flags) & PHPDBG_IS_QUIET ? "on" : "off");
} else switch (param->type) {
case NUMERIC_PARAM: {
if (param->num) {
diff --git a/sapi/phpdbg/phpdbg_set.h b/sapi/phpdbg/phpdbg_set.h
index 64bf52fa99..b4102f50b2 100644
--- a/sapi/phpdbg/phpdbg_set.h
+++ b/sapi/phpdbg/phpdbg_set.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -36,6 +36,8 @@ PHPDBG_SET(breaks);
PHPDBG_SET(quiet);
PHPDBG_SET(stepping);
PHPDBG_SET(refcount);
+PHPDBG_SET(pagination);
+PHPDBG_SET(lines);
extern const phpdbg_command_t phpdbg_set_commands[];
diff --git a/sapi/phpdbg/phpdbg_sigio_win32.c b/sapi/phpdbg/phpdbg_sigio_win32.c
new file mode 100644
index 0000000000..8dde7c3cad
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_sigio_win32.c
@@ -0,0 +1,112 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2014-2015 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: |
+ | http://www.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: Anatol Belski <ab@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+
+#include <signal.h>
+
+#include "phpdbg.h"
+#include "phpdbg_sigio_win32.h"
+
+
+ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+
+
+VOID
+SigIoWatcherThread(VOID *p)
+{
+ zend_uchar sig;
+ struct win32_sigio_watcher_data *swd = (struct win32_sigio_watcher_data *)p;
+
+top:
+ (void)phpdbg_consume_bytes(swd->fd, &sig, 1, -1);
+
+
+ if (3 == sig) {
+ /* XXX completely not sure it is done right here */
+ if (*swd->flags & PHPDBG_IS_INTERACTIVE) {
+ if (raise(sig)) {
+ goto top;
+ }
+ }
+ if (*swd->flags & PHPDBG_IS_SIGNALED) {
+ phpdbg_set_sigsafe_mem(&sig);
+ zend_try {
+ phpdbg_force_interruption();
+ } zend_end_try();
+ phpdbg_clear_sigsafe_mem();
+ goto end;
+ }
+ if (!(*swd->flags & PHPDBG_IS_INTERACTIVE)) {
+ *swd->flags |= PHPDBG_IS_SIGNALED;
+ }
+end:
+ /* XXX set signaled flag to the caller thread, question is - whether it's needed */
+ ExitThread(sig);
+ } else {
+ goto top;
+ }
+}
+
+
+/* Start this only for the time of the run or eval command,
+for so long that the main thread is busy serving some debug
+session. */
+void
+sigio_watcher_start(void)
+{
+
+ PHPDBG_G(swd).fd = PHPDBG_G(io)[PHPDBG_STDIN].fd;
+#ifdef ZTS
+ PHPDBG_G(swd).flags = &PHPDBG_G(flags);
+#endif
+
+ PHPDBG_G(sigio_watcher_thread) = CreateThread(
+ NULL,
+ 0,
+ (LPTHREAD_START_ROUTINE)SigIoWatcherThread,
+ &PHPDBG_G(swd),
+ 0,
+ NULL);
+}
+
+void
+sigio_watcher_stop(void)
+{
+ DWORD waited;
+
+ if (INVALID_HANDLE_VALUE == PHPDBG_G(sigio_watcher_thread)) {
+ /* it probably did bail out already */
+ return;
+ }
+
+ waited = WaitForSingleObject(PHPDBG_G(sigio_watcher_thread), 300);
+
+ if (WAIT_OBJECT_0 != waited) {
+ if (!CancelSynchronousIo(PHPDBG_G(sigio_watcher_thread))) {
+ /* error out */
+ }
+
+ if (!TerminateThread(PHPDBG_G(sigio_watcher_thread), 0)) {
+ /* error out */
+ }
+ }
+
+ PHPDBG_G(swd).fd = -1;
+ PHPDBG_G(sigio_watcher_thread) = INVALID_HANDLE_VALUE;
+}
+
diff --git a/sapi/phpdbg/phpdbg_sigio_win32.h b/sapi/phpdbg/phpdbg_sigio_win32.h
new file mode 100644
index 0000000000..c0b190ba58
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_sigio_win32.h
@@ -0,0 +1,38 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2014-2015 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: |
+ | http://www.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: Anatol Belski <ab@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+
+#ifndef PHPDBG_SIGIO_WIN32_H
+#define PHPDBG_SIGIO_WIN32_H
+
+#include "phpdbg.h"
+#include "phpdbg_prompt.h"
+#include "phpdbg_io.h"
+
+struct win32_sigio_watcher_data {
+ uint64_t *flags;
+ int fd;
+};
+
+void
+sigio_watcher_start(void);
+
+void
+sigio_watcher_stop(void);
+
+#endif /* PHPDBG_SIGIO_WIN32_H */
diff --git a/sapi/phpdbg/phpdbg_sigsafe.c b/sapi/phpdbg/phpdbg_sigsafe.c
new file mode 100644
index 0000000000..54af08ec5b
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_sigsafe.c
@@ -0,0 +1,59 @@
+#include "phpdbg_sigsafe.h"
+#include "phpdbg.h"
+
+ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+
+#define STR(x) #x
+#define EXP_STR(x) STR(x)
+
+static void* zend_mm_mem_alloc(zend_mm_storage *storage, size_t size, size_t alignment) {
+
+ if (EXPECTED(size <= PHPDBG_SIGSAFE_MEM_SIZE && !PHPDBG_G(sigsafe_mem).allocated)) {
+ PHPDBG_G(sigsafe_mem).allocated = 1;
+ return (void *) (((size_t) PHPDBG_G(sigsafe_mem).mem & ~(alignment - 1)) + alignment);
+ }
+
+ quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, ZEND_STRL("Tried to allocate more than " EXP_STR(PHPDBG_SIGSAFE_MEM_SIZE) " bytes from stack memory in signal handler ... bailing out of signal handler\n"));
+
+ if (*EG(bailout)) {
+ LONGJMP(*EG(bailout), FAILURE);
+ }
+
+ quiet_write(PHPDBG_G(io)[PHPDBG_STDERR].fd, ZEND_STRL("Bailed out without a bailout address in signal handler!\n"));
+
+ return NULL;
+}
+
+static void zend_mm_mem_free(zend_mm_storage *storage, void *ptr, size_t size) {
+}
+
+void phpdbg_set_sigsafe_mem(char *buffer) {
+ phpdbg_signal_safe_mem *mem = &PHPDBG_G(sigsafe_mem);
+ const zend_mm_handlers phpdbg_handlers = {
+ zend_mm_mem_alloc,
+ zend_mm_mem_free,
+ NULL,
+ NULL,
+ };
+
+ mem->mem = buffer;
+ mem->allocated = 0;
+
+ mem->heap = zend_mm_startup_ex(&phpdbg_handlers, NULL, 0);
+
+ mem->old_heap = zend_mm_set_heap(mem->heap);
+}
+
+zend_mm_heap *phpdbg_original_heap_sigsafe_mem(void) {
+ return PHPDBG_G(sigsafe_mem).old_heap;
+}
+
+void phpdbg_clear_sigsafe_mem(void) {
+ zend_mm_set_heap(phpdbg_original_heap_sigsafe_mem());
+ PHPDBG_G(sigsafe_mem).mem = NULL;
+}
+
+zend_bool phpdbg_active_sigsafe_mem(void) {
+ return !!PHPDBG_G(sigsafe_mem).mem;
+}
+
diff --git a/sapi/phpdbg/phpdbg_sigsafe.h b/sapi/phpdbg/phpdbg_sigsafe.h
new file mode 100644
index 0000000000..ab689a38d8
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_sigsafe.h
@@ -0,0 +1,24 @@
+#ifndef PHPDBG_SIGSAFE_H
+#define PHPDBG_SIGSAFE_H
+
+#define PHPDBG_SIGSAFE_MEM_SIZE (ZEND_MM_CHUNK_SIZE * 2)
+
+#include "zend.h"
+
+typedef struct {
+ char *mem;
+ zend_bool allocated;
+ zend_mm_heap *heap;
+ zend_mm_heap *old_heap;
+} phpdbg_signal_safe_mem;
+
+#include "phpdbg.h"
+
+zend_bool phpdbg_active_sigsafe_mem(void);
+
+void phpdbg_set_sigsafe_mem(char *mem);
+void phpdbg_clear_sigsafe_mem(void);
+
+zend_mm_heap *phpdbg_original_heap_sigsafe_mem(void);
+
+#endif
diff --git a/sapi/phpdbg/phpdbg_utils.c b/sapi/phpdbg/phpdbg_utils.c
index 7c7307a58b..92beda3c4f 100644
--- a/sapi/phpdbg/phpdbg_utils.c
+++ b/sapi/phpdbg/phpdbg_utils.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -18,23 +18,24 @@
+----------------------------------------------------------------------+
*/
-#include <stdio.h>
-#include <ctype.h>
-#include <string.h>
#include "zend.h"
+
#include "php.h"
-#include "spprintf.h"
#include "phpdbg.h"
#include "phpdbg_opcode.h"
#include "phpdbg_utils.h"
+#include "ext/standard/php_string.h"
-#ifdef _WIN32
-# include "win32/time.h"
-#elif defined(HAVE_SYS_IOCTL_H)
-# include "sys/ioctl.h"
-# ifndef GWINSZ_IN_SYS_IOCTL
-# include <termios.h>
-# endif
+/* FASYNC under Solaris */
+#ifdef HAVE_SYS_FILE_H
+# include <sys/file.h>
+#endif
+
+#ifdef HAVE_SYS_IOCTL_H
+# include "sys/ioctl.h"
+# ifndef GWINSZ_IN_SYS_IOCTL
+# include <termios.h>
+# endif
#endif
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
@@ -128,12 +129,12 @@ PHPDBG_API int phpdbg_is_class_method(const char *str, size_t len, char **class,
}
if (class != NULL) {
-
+
if (str[0] == '\\') {
str++;
len--;
}
-
+
*class = estrndup(str, sep - str);
(*class)[sep - str] = 0;
}
@@ -145,20 +146,20 @@ PHPDBG_API int phpdbg_is_class_method(const char *str, size_t len, char **class,
return 1;
} /* }}} */
-PHPDBG_API char *phpdbg_resolve_path(const char *path TSRMLS_DC) /* {{{ */
+PHPDBG_API char *phpdbg_resolve_path(const char *path) /* {{{ */
{
char resolved_name[MAXPATHLEN];
- if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) {
+ if (expand_filepath(path, resolved_name) == NULL) {
return NULL;
}
return estrdup(resolved_name);
} /* }}} */
-PHPDBG_API const char *phpdbg_current_file(TSRMLS_D) /* {{{ */
+PHPDBG_API const char *phpdbg_current_file(void) /* {{{ */
{
- const char *file = zend_get_executed_filename(TSRMLS_C);
+ const char *file = zend_get_executed_filename();
if (memcmp(file, "[no active file]", sizeof("[no active file]")) == 0) {
return PHPDBG_G(exec);
@@ -167,30 +168,32 @@ PHPDBG_API const char *phpdbg_current_file(TSRMLS_D) /* {{{ */
return file;
} /* }}} */
-PHPDBG_API const zend_function *phpdbg_get_function(const char *fname, const char *cname TSRMLS_DC) /* {{{ */
+PHPDBG_API const zend_function *phpdbg_get_function(const char *fname, const char *cname) /* {{{ */
{
zend_function *func = NULL;
- size_t fname_len = strlen(fname);
- char *lcname = zend_str_tolower_dup(fname, fname_len);
+ zend_string *lfname = zend_string_init(fname, strlen(fname), 0);
+ zend_string *tmp = zend_string_tolower(lfname);
+ zend_string_release(lfname);
+ lfname = tmp;
if (cname) {
- zend_class_entry **ce;
- size_t cname_len = strlen(cname);
- char *lc_cname = zend_str_tolower_dup(cname, cname_len);
- int ret = zend_lookup_class(lc_cname, cname_len, &ce TSRMLS_CC);
+ zend_class_entry *ce;
+ zend_string *lcname = zend_string_init(cname, strlen(cname), 0);
+ tmp = zend_string_tolower(lcname);
+ zend_string_release(lcname);
+ lcname = tmp;
+ ce = zend_lookup_class(lcname);
- efree(lc_cname);
+ zend_string_release(lcname);
- if (ret == SUCCESS) {
- zend_hash_find(&(*ce)->function_table, lcname, fname_len+1,
- (void**)&func);
+ if (ce) {
+ func = zend_hash_find_ptr(&ce->function_table, lfname);
}
} else {
- zend_hash_find(EG(function_table), lcname, fname_len+1,
- (void**)&func);
+ func = zend_hash_find_ptr(EG(function_table), lfname);
}
- efree(lcname);
+ zend_string_release(lfname);
return func;
} /* }}} */
@@ -224,145 +227,46 @@ PHPDBG_API char *phpdbg_trim(const char *str, size_t len, size_t *new_len) /* {{
} /* }}} */
-PHPDBG_API int phpdbg_print(int type TSRMLS_DC, FILE *fp, const char *format, ...) /* {{{ */
-{
- int rc = 0;
- char *buffer = NULL;
- va_list args;
-
- if (format != NULL && strlen(format) > 0L) {
- va_start(args, format);
- vspprintf(&buffer, 0, format, args);
- va_end(args);
- }
-
- /* TODO(anyone) colours */
-
- switch (type) {
- case P_ERROR:
- if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) {
- rc = fprintf(fp,
- "\033[%sm[%s]\033[0m\n",
- PHPDBG_G(colors)[PHPDBG_COLOR_ERROR]->code, buffer);
- } else {
- rc = fprintf(fp, "[%s]\n", buffer);
- }
- break;
-
- case P_NOTICE:
- if (PHPDBG_G(flags) & PHPDBG_IS_COLOURED) {
- rc = fprintf(fp,
- "\033[%sm[%s]\033[0m\n",
- PHPDBG_G(colors)[PHPDBG_COLOR_NOTICE]->code, buffer);
- } else {
- rc = fprintf(fp, "[%s]\n", buffer);
- }
- break;
-
- case P_WRITELN: {
- if (buffer) {
- rc = fprintf(fp, "%s\n", buffer);
- } else {
- rc = fprintf(fp, "\n");
- }
- } break;
-
- case P_WRITE:
- if (buffer) {
- rc = fprintf(fp, "%s", buffer);
- }
- break;
-
- /* no formatting on logging output */
- case P_LOG:
- if (buffer) {
- struct timeval tp;
- if (gettimeofday(&tp, NULL) == SUCCESS) {
- rc = fprintf(fp, "[%ld %.8F]: %s\n", tp.tv_sec, tp.tv_usec / 1000000.00, buffer);
- } else {
- rc = FAILURE;
- }
- }
- break;
- }
-
- if (buffer) {
- efree(buffer);
- }
-
- return rc;
-} /* }}} */
-
-PHPDBG_API int phpdbg_rlog(FILE *fp, const char *fmt, ...) { /* {{{ */
- int rc = 0;
-
- va_list args;
- struct timeval tp;
-
- va_start(args, fmt);
- if (gettimeofday(&tp, NULL) == SUCCESS) {
- char friendly[100];
- char *format = NULL, *buffer = NULL;
- const time_t tt = tp.tv_sec;
-
- strftime(friendly, 100, "%a %b %d %T.%%04d %Y", localtime(&tt));
- asprintf(
- &buffer, friendly, tp.tv_usec/1000);
- asprintf(
- &format, "[%s]: %s\n", buffer, fmt);
- rc = vfprintf(
- fp, format, args);
-
- free(format);
- free(buffer);
- }
- va_end(args);
-
- return rc;
-} /* }}} */
-
-PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC) /* {{{ */
+PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length) /* {{{ */
{
const phpdbg_color_t *color = colors;
while (color && color->name) {
if (name_length == color->name_length &&
memcmp(name, color->name, name_length) == SUCCESS) {
- phpdbg_debug(
- "phpdbg_get_color(%s, %lu): %s", name, name_length, color->code);
+ phpdbg_debug("phpdbg_get_color(%s, %lu): %s", name, name_length, color->code);
return color;
}
++color;
}
- phpdbg_debug(
- "phpdbg_get_color(%s, %lu): failed", name, name_length);
+ phpdbg_debug("phpdbg_get_color(%s, %lu): failed", name, name_length);
return NULL;
} /* }}} */
-PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color) /* {{{ */
{
PHPDBG_G(colors)[element] = color;
} /* }}} */
-PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length) /* {{{ */
{
- const phpdbg_color_t *color = phpdbg_get_color(name, name_length TSRMLS_CC);
+ const phpdbg_color_t *color = phpdbg_get_color(name, name_length);
if (color) {
- phpdbg_set_color(element, color TSRMLS_CC);
+ phpdbg_set_color(element, color);
} else PHPDBG_G(colors)[element] = colors;
} /* }}} */
-PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(TSRMLS_D) /* {{{ */
+PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(void) /* {{{ */
{
return colors;
} /* }}} */
-PHPDBG_API int phpdbg_get_element(const char *name, size_t len TSRMLS_DC) {
+PHPDBG_API int phpdbg_get_element(const char *name, size_t len) {
const phpdbg_element_t *element = elements;
-
+
while (element && element->name) {
if (len == element->name_length) {
if (strncasecmp(name, element->name, len) == SUCCESS) {
@@ -371,11 +275,11 @@ PHPDBG_API int phpdbg_get_element(const char *name, size_t len TSRMLS_DC) {
}
element++;
}
-
+
return PHPDBG_COLOR_INVALID;
}
-PHPDBG_API void phpdbg_set_prompt(const char *prompt TSRMLS_DC) /* {{{ */
+PHPDBG_API void phpdbg_set_prompt(const char *prompt) /* {{{ */
{
/* free formatted prompt */
if (PHPDBG_G(prompt)[1]) {
@@ -392,7 +296,7 @@ PHPDBG_API void phpdbg_set_prompt(const char *prompt TSRMLS_DC) /* {{{ */
PHPDBG_G(prompt)[0] = strdup(prompt);
} /* }}} */
-PHPDBG_API const char *phpdbg_get_prompt(TSRMLS_D) /* {{{ */
+PHPDBG_API const char *phpdbg_get_prompt(void) /* {{{ */
{
/* find cached prompt */
if (PHPDBG_G(prompt)[1]) {
@@ -403,48 +307,41 @@ PHPDBG_API const char *phpdbg_get_prompt(TSRMLS_D) /* {{{ */
#ifndef HAVE_LIBEDIT
/* TODO: libedit doesn't seems to support coloured prompt */
if ((PHPDBG_G(flags) & PHPDBG_IS_COLOURED)) {
- asprintf(
- &PHPDBG_G(prompt)[1], "\033[%sm%s\033[0m ",
+ ZEND_IGNORE_VALUE(asprintf(&PHPDBG_G(prompt)[1], "\033[%sm%s\033[0m ",
PHPDBG_G(colors)[PHPDBG_COLOR_PROMPT]->code,
- PHPDBG_G(prompt)[0]);
+ PHPDBG_G(prompt)[0]));
} else
#endif
{
- asprintf(
- &PHPDBG_G(prompt)[1], "%s ",
- PHPDBG_G(prompt)[0]);
+ ZEND_IGNORE_VALUE(asprintf(&PHPDBG_G(prompt)[1], "%s ", PHPDBG_G(prompt)[0]));
}
return PHPDBG_G(prompt)[1];
} /* }}} */
-int phpdbg_rebuild_symtable(TSRMLS_D) {
- if (!EG(active_op_array)) {
- phpdbg_error("No active op array!");
+int phpdbg_rebuild_symtable(void) {
+ if (!EG(current_execute_data) || !EG(current_execute_data)->func) {
+ phpdbg_error("inactive", "type=\"op_array\"", "No active op array!");
return FAILURE;
}
- if (!EG(active_symbol_table)) {
- zend_rebuild_symbol_table(TSRMLS_C);
-
- if (!EG(active_symbol_table)) {
- phpdbg_error("No active symbol table!");
- return FAILURE;
- }
+ if (!zend_rebuild_symbol_table()) {
+ phpdbg_error("inactive", "type=\"symbol_table\"", "No active symbol table!");
+ return FAILURE;
}
return SUCCESS;
}
-PHPDBG_API int phpdbg_get_terminal_width(TSRMLS_D) /* {{{ */
+PHPDBG_API int phpdbg_get_terminal_width(void) /* {{{ */
{
- int columns;
+ int columns;
#ifdef _WIN32
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
columns = csbi.srWindow.Right - csbi.srWindow.Left + 1;
-#elif defined(HAVE_SYS_IOCTL_H) && defined (TIOCGWINSZ)
+#elif defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ)
struct winsize w;
columns = ioctl(fileno(stdout), TIOCGWINSZ, &w) == 0 ? w.ws_col : 80;
@@ -453,3 +350,497 @@ PHPDBG_API int phpdbg_get_terminal_width(TSRMLS_D) /* {{{ */
#endif
return columns;
} /* }}} */
+
+PHPDBG_API int phpdbg_get_terminal_height(void) /* {{{ */
+{
+ int lines;
+#ifdef _WIN32
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+
+ GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
+ lines = csbi.srWindow.Bottom - csbi.srWindow.Top + 1;
+#elif defined(HAVE_SYS_IOCTL_H) && defined(TIOCGWINSZ)
+ struct winsize w;
+
+ lines = ioctl(fileno(stdout), TIOCGWINSZ, &w) == 0 ? w.ws_row : 40;
+#else
+ lines = 40;
+#endif
+ return lines;
+} /* }}} */
+
+PHPDBG_API void phpdbg_set_async_io(int fd) {
+#if !defined(_WIN32) && defined(FASYNC)
+ int flags;
+ fcntl(STDIN_FILENO, F_SETOWN, getpid());
+ flags = fcntl(STDIN_FILENO, F_GETFL);
+ fcntl(STDIN_FILENO, F_SETFL, flags | FASYNC);
+#endif
+}
+
+int phpdbg_safe_class_lookup(const char *name, int name_length, zend_class_entry **ce) {
+ if (PHPDBG_G(flags) & PHPDBG_IN_SIGNAL_HANDLER) {
+ char *lc_name, *lc_free;
+ int lc_length;
+
+ if (name == NULL || !name_length) {
+ return FAILURE;
+ }
+
+ lc_free = lc_name = emalloc(name_length + 1);
+ zend_str_tolower_copy(lc_name, name, name_length);
+ lc_length = name_length + 1;
+
+ if (lc_name[0] == '\\') {
+ lc_name += 1;
+ lc_length -= 1;
+ }
+
+ phpdbg_try_access {
+ *ce = zend_hash_str_find_ptr(EG(class_table), lc_name, lc_length);
+ } phpdbg_catch_access {
+ phpdbg_error("signalsegv", "class=\"%.*s\"", "Could not fetch class %.*s, invalid data source", name_length, name);
+ } phpdbg_end_try_access();
+
+ efree(lc_free);
+ } else {
+ zend_string *str_name = zend_string_init(name, name_length, 0);
+ *ce = zend_lookup_class(str_name);
+ efree(str_name);
+ }
+
+ return *ce ? SUCCESS : FAILURE;
+}
+
+char *phpdbg_get_property_key(char *key) {
+ if (*key != 0) {
+ return key;
+ }
+ return strchr(key + 1, 0) + 1;
+}
+
+static int phpdbg_parse_variable_arg_wrapper(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv, phpdbg_parse_var_func callback) {
+ return callback(name, len, keyname, keylen, parent, zv);
+}
+
+PHPDBG_API int phpdbg_parse_variable(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_func callback, zend_bool silent) {
+ return phpdbg_parse_variable_with_arg(input, len, parent, i, (phpdbg_parse_var_with_arg_func) phpdbg_parse_variable_arg_wrapper, NULL, silent, callback);
+}
+
+PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, phpdbg_parse_var_with_arg_func step_cb, zend_bool silent, void *arg) {
+ int ret = FAILURE;
+ zend_bool new_index = 1;
+ char *last_index;
+ size_t index_len = 0;
+ zval *zv;
+
+ if (len < 2 || *input != '$') {
+ goto error;
+ }
+
+ while (i++ < len) {
+ if (i == len) {
+ new_index = 1;
+ } else {
+ switch (input[i]) {
+ case '[':
+ new_index = 1;
+ break;
+ case ']':
+ break;
+ case '>':
+ if (last_index[index_len - 1] == '-') {
+ new_index = 1;
+ index_len--;
+ }
+ break;
+
+ default:
+ if (new_index) {
+ last_index = input + i;
+ new_index = 0;
+ }
+ if (input[i - 1] == ']') {
+ goto error;
+ }
+ index_len++;
+ }
+ }
+
+ if (new_index && index_len == 0) {
+ zend_ulong numkey;
+ zend_string *strkey;
+ ZEND_HASH_FOREACH_KEY_PTR(parent, numkey, strkey, zv) {
+ while (Z_TYPE_P(zv) == IS_INDIRECT) {
+ zv = Z_INDIRECT_P(zv);
+ }
+
+ if (i == len || (i == len - 1 && input[len - 1] == ']')) {
+ char *key, *propkey;
+ size_t namelen, keylen;
+ char *name;
+ char *keyname = estrndup(last_index, index_len);
+ if (strkey) {
+ key = ZSTR_VAL(strkey);
+ keylen = ZSTR_LEN(strkey);
+ } else {
+ keylen = spprintf(&key, 0, "%llu", numkey);
+ }
+ propkey = phpdbg_get_property_key(key);
+ name = emalloc(i + keylen + 2);
+ namelen = sprintf(name, "%.*s%.*s%s", (int) i, input, keylen - (propkey - key), propkey, input[len - 1] == ']'?"]":"");
+ if (!strkey) {
+ efree(key);
+ }
+
+ ret = callback(name, namelen, keyname, index_len, parent, zv, arg) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE;
+ } else retry_ref: if (Z_TYPE_P(zv) == IS_OBJECT) {
+ if (step_cb) {
+ char *name = estrndup(input, i);
+ char *keyname = estrndup(last_index, index_len);
+
+ ret = step_cb(name, i, keyname, index_len, parent, zv, arg) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE;
+ }
+
+ phpdbg_parse_variable_with_arg(input, len, Z_OBJPROP_P(zv), i, callback, step_cb, silent, arg);
+ } else if (Z_TYPE_P(zv) == IS_ARRAY) {
+ if (step_cb) {
+ char *name = estrndup(input, i);
+ char *keyname = estrndup(last_index, index_len);
+
+ ret = step_cb(name, i, keyname, index_len, parent, zv, arg) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE;
+ }
+
+ phpdbg_parse_variable_with_arg(input, len, Z_ARRVAL_P(zv), i, callback, step_cb, silent, arg);
+ } else if (Z_ISREF_P(zv)) {
+ if (step_cb) {
+ char *name = estrndup(input, i);
+ char *keyname = estrndup(last_index, index_len);
+
+ ret = step_cb(name, i, keyname, index_len, parent, zv, arg) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE;
+ }
+
+ ZVAL_DEREF(zv);
+ goto retry_ref;
+ } else {
+ /* Ignore silently */
+ }
+ } ZEND_HASH_FOREACH_END();
+ return ret;
+ } else if (new_index) {
+ char last_chr = last_index[index_len];
+ last_index[index_len] = 0;
+ if (!(zv = zend_symtable_str_find(parent, last_index, index_len))) {
+ if (!silent) {
+ phpdbg_error("variable", "type=\"undefined\" variable=\"%.*s\"", "%.*s is undefined", (int) i, input);
+ }
+ return FAILURE;
+ }
+ while (Z_TYPE_P(zv) == IS_INDIRECT) {
+ zv = Z_INDIRECT_P(zv);
+ }
+
+ last_index[index_len] = last_chr;
+ if (i == len) {
+ char *name = estrndup(input, i);
+ char *keyname = estrndup(last_index, index_len);
+
+ ret = callback(name, i, keyname, index_len, parent, zv, arg) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE;
+ } else retry_ref_end: if (Z_TYPE_P(zv) == IS_OBJECT) {
+ if (step_cb) {
+ char *name = estrndup(input, i);
+ char *keyname = estrndup(last_index, index_len);
+
+ ret = step_cb(name, i, keyname, index_len, parent, zv, arg) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE;
+ }
+
+ parent = Z_OBJPROP_P(zv);
+ } else if (Z_TYPE_P(zv) == IS_ARRAY) {
+ if (step_cb) {
+ char *name = estrndup(input, i);
+ char *keyname = estrndup(last_index, index_len);
+
+ ret = step_cb(name, i, keyname, index_len, parent, zv, arg) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE;
+ }
+
+ parent = Z_ARRVAL_P(zv);
+ } else if (Z_ISREF_P(zv)) {
+ if (step_cb) {
+ char *name = estrndup(input, i);
+ char *keyname = estrndup(last_index, index_len);
+
+ ret = step_cb(name, i, keyname, index_len, parent, zv, arg) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE;
+ }
+
+ ZVAL_DEREF(zv);
+ goto retry_ref_end;
+ } else {
+ phpdbg_error("variable", "type=\"notiterable\" variable=\"%.*s\"", "%.*s is nor an array nor an object", (int) (input[i] == '>' ? i - 1 : i), input);
+ return FAILURE;
+ }
+ index_len = 0;
+ }
+ }
+
+ return ret;
+ error:
+ phpdbg_error("variable", "type=\"invalidinput\"", "Malformed input");
+ return FAILURE;
+}
+
+int phpdbg_is_auto_global(char *name, int len) {
+ return zend_is_auto_global_str(name, len);
+}
+
+static int phpdbg_xml_array_element_dump(zval *zv, zend_string *key, zend_ulong num) {
+ phpdbg_xml("<element");
+
+ phpdbg_try_access {
+ if (key) { /* string key */
+ phpdbg_xml(" name=\"%.*s\"", ZSTR_LEN(key), ZSTR_VAL(key));
+ } else { /* numeric key */
+ phpdbg_xml(" name=\"%ld\"", num);
+ }
+ } phpdbg_catch_access {
+ phpdbg_xml(" severity=\"error\" ></element>");
+ return 0;
+ } phpdbg_end_try_access();
+
+ phpdbg_xml(">");
+
+ phpdbg_xml_var_dump(zv);
+
+ phpdbg_xml("</element>");
+
+ return 0;
+}
+
+static int phpdbg_xml_object_property_dump(zval *zv, zend_string *key, zend_ulong num) {
+ phpdbg_xml("<property");
+
+ phpdbg_try_access {
+ if (key) { /* string key */
+ const char *prop_name, *class_name;
+ int unmangle = zend_unmangle_property_name(key, &class_name, &prop_name);
+
+ if (class_name && unmangle == SUCCESS) {
+ phpdbg_xml(" name=\"%s\"", prop_name);
+ if (class_name[0] == '*') {
+ phpdbg_xml(" protection=\"protected\"");
+ } else {
+ phpdbg_xml(" class=\"%s\" protection=\"private\"", class_name);
+ }
+ } else {
+ phpdbg_xml(" name=\"%.*s\" protection=\"public\"", ZSTR_LEN(key), ZSTR_VAL(key));
+ }
+ } else { /* numeric key */
+ phpdbg_xml(" name=\"%ld\" protection=\"public\"", num);
+ }
+ } phpdbg_catch_access {
+ phpdbg_xml(" severity=\"error\" ></property>");
+ return 0;
+ } phpdbg_end_try_access();
+
+ phpdbg_xml(">");
+
+ phpdbg_xml_var_dump(zv);
+
+ phpdbg_xml("</property>");
+
+ return 0;
+}
+
+#define COMMON (is_ref ? "&" : "")
+
+PHPDBG_API void phpdbg_xml_var_dump(zval *zv) {
+ HashTable *myht;
+ zend_string *class_name, *key;
+ zend_ulong num;
+ zval *val;
+ int (*element_dump_func)(zval *zv, zend_string *key, zend_ulong num);
+ zend_bool is_ref = 0;
+
+ int is_temp;
+
+ phpdbg_try_access {
+ is_ref = Z_ISREF_P(zv) && GC_REFCOUNT(Z_COUNTED_P(zv)) > 1;
+ ZVAL_DEREF(zv);
+
+ switch (Z_TYPE_P(zv)) {
+ case IS_TRUE:
+ phpdbg_xml("<bool refstatus=\"%s\" value=\"true\" />", COMMON);
+ break;
+ case IS_FALSE:
+ phpdbg_xml("<bool refstatus=\"%s\" value=\"false\" />", COMMON);
+ break;
+ case IS_NULL:
+ phpdbg_xml("<null refstatus=\"%s\" />", COMMON);
+ break;
+ case IS_LONG:
+ phpdbg_xml("<int refstatus=\"%s\" value=\"" ZEND_LONG_FMT "\" />", COMMON, Z_LVAL_P(zv));
+ break;
+ case IS_DOUBLE:
+ phpdbg_xml("<float refstatus=\"%s\" value=\"%.*G\" />", COMMON, (int) EG(precision), Z_DVAL_P(zv));
+ break;
+ case IS_STRING:
+ phpdbg_xml("<string refstatus=\"%s\" length=\"%d\" value=\"%.*s\" />", COMMON, Z_STRLEN_P(zv), Z_STRLEN_P(zv), Z_STRVAL_P(zv));
+ break;
+ case IS_ARRAY:
+ myht = Z_ARRVAL_P(zv);
+ if (ZEND_HASH_APPLY_PROTECTION(myht) && ++myht->u.v.nApplyCount > 1) {
+ phpdbg_xml("<recursion />");
+ --myht->u.v.nApplyCount;
+ break;
+ }
+ phpdbg_xml("<array refstatus=\"%s\" num=\"%d\">", COMMON, zend_hash_num_elements(myht));
+ element_dump_func = phpdbg_xml_array_element_dump;
+ is_temp = 0;
+ goto head_done;
+ case IS_OBJECT:
+ myht = Z_OBJDEBUG_P(zv, is_temp);
+ if (myht && ++myht->u.v.nApplyCount > 1) {
+ phpdbg_xml("<recursion />");
+ --myht->u.v.nApplyCount;
+ break;
+ }
+
+ class_name = Z_OBJ_HANDLER_P(zv, get_class_name)(Z_OBJ_P(zv));
+ phpdbg_xml("<object refstatus=\"%s\" class=\"%.*s\" id=\"%d\" num=\"%d\">", COMMON, ZSTR_LEN(class_name), ZSTR_VAL(class_name), Z_OBJ_HANDLE_P(zv), myht ? zend_hash_num_elements(myht) : 0);
+ zend_string_release(class_name);
+
+ element_dump_func = phpdbg_xml_object_property_dump;
+head_done:
+ if (myht) {
+ ZEND_HASH_FOREACH_KEY_VAL_IND(myht, num, key, val) {
+ element_dump_func(val, key, num);
+ } ZEND_HASH_FOREACH_END();
+ zend_hash_apply_with_arguments(myht, (apply_func_args_t) element_dump_func, 0);
+ --myht->u.v.nApplyCount;
+ if (is_temp) {
+ zend_hash_destroy(myht);
+ efree(myht);
+ }
+ }
+ if (Z_TYPE_P(zv) == IS_ARRAY) {
+ phpdbg_xml("</array>");
+ } else {
+ phpdbg_xml("</object>");
+ }
+ break;
+ case IS_RESOURCE: {
+ const char *type_name = zend_rsrc_list_get_rsrc_type(Z_RES_P(zv));
+ phpdbg_xml("<resource refstatus=\"%s\" id=\"%pd\" type=\"%ld\" />", COMMON, Z_RES_P(zv)->handle, type_name ? type_name : "unknown");
+ break;
+ }
+ default:
+ break;
+ }
+ } phpdbg_end_try_access();
+}
+
+PHPDBG_API zend_bool phpdbg_check_caught_ex(zend_execute_data *execute_data, zend_object *exception) {
+ const zend_op *op;
+ zend_op *cur;
+ uint32_t op_num, i;
+ zend_op_array *op_array = &execute_data->func->op_array;
+
+ if (execute_data->opline >= EG(exception_op) && execute_data->opline < EG(exception_op) + 3) {
+ op = EG(opline_before_exception);
+ } else {
+ op = execute_data->opline;
+ }
+
+ op_num = op - op_array->opcodes;
+
+ for (i = 0; i < op_array->last_try_catch && op_array->try_catch_array[i].try_op <= op_num; i++) {
+ uint32_t catch = op_array->try_catch_array[i].catch_op, finally = op_array->try_catch_array[i].finally_op;
+ if (op_num <= catch || op_num <= finally) {
+ if (finally) {
+ return 1;
+ }
+
+ do {
+ zend_class_entry *ce;
+ cur = &op_array->opcodes[catch];
+
+ if (!(ce = CACHED_PTR(Z_CACHE_SLOT_P(EX_CONSTANT(cur->op1))))) {
+ ce = zend_fetch_class_by_name(Z_STR_P(EX_CONSTANT(cur->op1)), EX_CONSTANT(cur->op1) + 1, ZEND_FETCH_CLASS_NO_AUTOLOAD);
+ CACHE_PTR(Z_CACHE_SLOT_P(EX_CONSTANT(cur->op1)), ce);
+ }
+
+ if (ce == exception->ce || (ce && instanceof_function(exception->ce, ce))) {
+ return 1;
+ }
+
+ catch = cur->extended_value;
+ } while (!cur->result.num);
+
+ return 0;
+ }
+ }
+
+ return op->opcode == ZEND_CATCH;
+}
+
+char *phpdbg_short_zval_print(zval *zv, int maxlen) /* {{{ */
+{
+ char *decode = NULL;
+
+ switch (Z_TYPE_P(zv)) {
+ case IS_UNDEF:
+ decode = estrdup("");
+ break;
+ case IS_NULL:
+ decode = estrdup("null");
+ break;
+ case IS_FALSE:
+ decode = estrdup("false");
+ break;
+ case IS_TRUE:
+ decode = estrdup("true");
+ break;
+ case IS_LONG:
+ spprintf(&decode, 0, ZEND_LONG_FMT, Z_LVAL_P(zv));
+ break;
+ case IS_DOUBLE:
+ spprintf(&decode, 0, "%.*G", 14, Z_DVAL_P(zv));
+ break;
+ case IS_STRING: {
+ int i;
+ zend_string *str = php_addcslashes(Z_STR_P(zv), 0, "\\\"", 2);
+ for (i = 0; i < ZSTR_LEN(str); i++) {
+ if (ZSTR_VAL(str)[i] < 32) {
+ ZSTR_VAL(str)[i] = ' ';
+ }
+ }
+ spprintf(&decode, 0, "\"%.*s\"%c",
+ ZSTR_LEN(str) <= maxlen - 2 ? (int) ZSTR_LEN(str) : (maxlen - 3),
+ ZSTR_VAL(str), ZSTR_LEN(str) <= maxlen - 2 ? 0 : '+');
+ zend_string_release(str);
+ } break;
+ case IS_RESOURCE:
+ spprintf(&decode, 0, "Rsrc #%d", Z_RES_HANDLE_P(zv));
+ break;
+ case IS_ARRAY:
+ spprintf(&decode, 0, "array(%d)", zend_hash_num_elements(Z_ARR_P(zv)));
+ break;
+ case IS_OBJECT: {
+ zend_string *str = Z_OBJCE_P(zv)->name;
+ spprintf(&decode, 0, "%.*s%c",
+ ZSTR_LEN(str) <= maxlen ? (int) ZSTR_LEN(str) : maxlen - 1,
+ ZSTR_VAL(str), ZSTR_LEN(str) <= maxlen ? 0 : '+');
+ break;
+ }
+ case IS_CONSTANT:
+ decode = estrdup("<constant>");
+ break;
+ case IS_CONSTANT_AST:
+ decode = estrdup("<ast>");
+ break;
+ default:
+ spprintf(&decode, 0, "unknown type: %d", Z_TYPE_P(zv));
+ break;
+ }
+
+ return decode;
+} /* }}} */
diff --git a/sapi/phpdbg/phpdbg_utils.h b/sapi/phpdbg/phpdbg_utils.h
index 8f974a9bbf..8cf7acc2ce 100644
--- a/sapi/phpdbg/phpdbg_utils.h
+++ b/sapi/phpdbg/phpdbg_utils.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -28,56 +28,10 @@ PHPDBG_API int phpdbg_is_numeric(const char*);
PHPDBG_API int phpdbg_is_empty(const char*);
PHPDBG_API int phpdbg_is_addr(const char*);
PHPDBG_API int phpdbg_is_class_method(const char*, size_t, char**, char**);
-PHPDBG_API const char *phpdbg_current_file(TSRMLS_D);
-PHPDBG_API char *phpdbg_resolve_path(const char* TSRMLS_DC);
+PHPDBG_API const char *phpdbg_current_file(void);
+PHPDBG_API char *phpdbg_resolve_path(const char*);
PHPDBG_API char *phpdbg_trim(const char*, size_t, size_t*);
-PHPDBG_API const zend_function *phpdbg_get_function(const char*, const char* TSRMLS_DC);
-
-/**
- * Error/notice/formatting helpers
- */
-enum {
- P_ERROR = 1,
- P_NOTICE,
- P_WRITELN,
- P_WRITE,
- P_LOG
-};
-
-#ifdef ZTS
-PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 4, 5);
-#else
-PHPDBG_API int phpdbg_print(int TSRMLS_DC, FILE*, const char*, ...) PHP_ATTRIBUTE_FORMAT(printf, 3, 4);
-#endif
-
-PHPDBG_API int phpdbg_rlog(FILE *stream, const char *fmt, ...);
-
-#define phpdbg_error(fmt, ...) phpdbg_print(P_ERROR TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
-#define phpdbg_notice(fmt, ...) phpdbg_print(P_NOTICE TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
-#define phpdbg_writeln(fmt, ...) phpdbg_print(P_WRITELN TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
-#define phpdbg_write(fmt, ...) phpdbg_print(P_WRITE TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
-#define phpdbg_log(fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDOUT], fmt, ##__VA_ARGS__)
-
-#define phpdbg_error_ex(out, fmt, ...) phpdbg_print(P_ERROR TSRMLS_CC, out, fmt, ##__VA_ARGS__)
-#define phpdbg_notice_ex(out, fmt, ...) phpdbg_print(P_NOTICE TSRMLS_CC, out, fmt, ##__VA_ARGS__)
-#define phpdbg_writeln_ex(out, fmt, ...) phpdbg_print(P_WRITELN TSRMLS_CC, out, fmt, ##__VA_ARGS__)
-#define phpdbg_write_ex(out, fmt, ...) phpdbg_print(P_WRITE TSRMLS_CC, out, fmt, ##__VA_ARGS__)
-#define phpdbg_log_ex(out, fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, out, fmt, ##__VA_ARGS__)
-
-#if PHPDBG_DEBUG
-# define phpdbg_debug(fmt, ...) phpdbg_print(P_LOG TSRMLS_CC, PHPDBG_G(io)[PHPDBG_STDERR], fmt, ##__VA_ARGS__)
-#else
-# define phpdbg_debug(fmt, ...)
-#endif
-
-/* {{{ For writing blank lines */
-#define EMPTY NULL /* }}} */
-
-/* {{{ For prompt lines */
-#define PROMPT "phpdbg>" /* }}} */
-
-/* {{{ For separation */
-#define SEPARATE "------------------------------------------------" /* }}} */
+PHPDBG_API const zend_function *phpdbg_get_function(const char*, const char*);
/* {{{ Color Management */
#define PHPDBG_COLOR_LEN 12
@@ -109,39 +63,65 @@ typedef struct _phpdbg_element_t {
int id;
} phpdbg_element_t;
-PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length TSRMLS_DC);
-PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color TSRMLS_DC);
-PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length TSRMLS_DC);
-PHPDBG_API const phpdbg_color_t* phpdbg_get_colors(TSRMLS_D);
-PHPDBG_API int phpdbg_get_element(const char *name, size_t len TSRMLS_DC); /* }}} */
+PHPDBG_API const phpdbg_color_t *phpdbg_get_color(const char *name, size_t name_length);
+PHPDBG_API void phpdbg_set_color(int element, const phpdbg_color_t *color);
+PHPDBG_API void phpdbg_set_color_ex(int element, const char *name, size_t name_length);
+PHPDBG_API const phpdbg_color_t *phpdbg_get_colors(void);
+PHPDBG_API int phpdbg_get_element(const char *name, size_t len); /* }}} */
/* {{{ Prompt Management */
-PHPDBG_API void phpdbg_set_prompt(const char* TSRMLS_DC);
-PHPDBG_API const char *phpdbg_get_prompt(TSRMLS_D); /* }}} */
-
-/* {{{ Console Width */
-PHPDBG_API int phpdbg_get_terminal_width(TSRMLS_D); /* }}} */
-
-int phpdbg_rebuild_symtable(TSRMLS_D);
-
-#if PHP_VERSION_ID < 50500
-/* copy from zend_hash.c PHP 5.5 for 5.4 compatibility */
-static void zend_hash_get_current_key_zval_ex(const HashTable *ht, zval *key, HashPosition *pos) {
- Bucket *p;
-
- p = pos ? (*pos) : ht->pInternalPointer;
-
- if (!p) {
- Z_TYPE_P(key) = IS_NULL;
- } else if (p->nKeyLength) {
- Z_TYPE_P(key) = IS_STRING;
- Z_STRVAL_P(key) = IS_INTERNED(p->arKey) ? (char*)p->arKey : estrndup(p->arKey, p->nKeyLength - 1);
- Z_STRLEN_P(key) = p->nKeyLength - 1;
- } else {
- Z_TYPE_P(key) = IS_LONG;
- Z_LVAL_P(key) = p->h;
- }
-}
+PHPDBG_API void phpdbg_set_prompt(const char*);
+PHPDBG_API const char *phpdbg_get_prompt(void); /* }}} */
+
+/* {{{ Console size */
+PHPDBG_API int phpdbg_get_terminal_width(void);
+PHPDBG_API int phpdbg_get_terminal_height(void); /* }}} */
+
+PHPDBG_API void phpdbg_set_async_io(int fd);
+
+int phpdbg_rebuild_symtable(void);
+
+int phpdbg_safe_class_lookup(const char *name, int name_length, zend_class_entry **ce);
+
+char *phpdbg_get_property_key(char *key);
+
+typedef int (*phpdbg_parse_var_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv);
+typedef int (*phpdbg_parse_var_with_arg_func)(char *name, size_t len, char *keyname, size_t keylen, HashTable *parent, zval *zv, void *arg);
+
+PHPDBG_API int phpdbg_parse_variable(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_func callback, zend_bool silent);
+PHPDBG_API int phpdbg_parse_variable_with_arg(char *input, size_t len, HashTable *parent, size_t i, phpdbg_parse_var_with_arg_func callback, phpdbg_parse_var_with_arg_func step_cb, zend_bool silent, void *arg);
+
+int phpdbg_is_auto_global(char *name, int len);
+
+PHPDBG_API void phpdbg_xml_var_dump(zval *zv);
+
+char *phpdbg_short_zval_print(zval *zv, int maxlen);
+
+PHPDBG_API zend_bool phpdbg_check_caught_ex(zend_execute_data *ex, zend_object *exception);
+
+#ifdef ZTS
+#define PHPDBG_OUTPUT_BACKUP_DEFINES() \
+ zend_output_globals *output_globals_ptr; \
+ zend_output_globals original_output_globals; \
+ output_globals_ptr = (zend_output_globals *) (*((void ***) tsrm_get_ls_cache()))[TSRM_UNSHUFFLE_RSRC_ID(output_globals_id)];
+#else
+#define PHPDBG_OUTPUT_BACKUP_DEFINES() \
+ zend_output_globals *output_globals_ptr; \
+ zend_output_globals original_output_globals; \
+ output_globals_ptr = &output_globals;
#endif
+#define PHPDBG_OUTPUT_BACKUP_SWAP() \
+ original_output_globals = *output_globals_ptr; \
+ memset(output_globals_ptr, 0, sizeof(zend_output_globals)); \
+ php_output_activate();
+
+#define PHPDBG_OUTPUT_BACKUP() \
+ PHPDBG_OUTPUT_BACKUP_DEFINES() \
+ PHPDBG_OUTPUT_BACKUP_SWAP()
+
+#define PHPDBG_OUTPUT_BACKUP_RESTORE() \
+ php_output_deactivate(); \
+ *output_globals_ptr = original_output_globals;
+
#endif /* PHPDBG_UTILS_H */
diff --git a/sapi/phpdbg/phpdbg_wait.c b/sapi/phpdbg/phpdbg_wait.c
new file mode 100644
index 0000000000..cee926f579
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_wait.c
@@ -0,0 +1,398 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Bob Weinand <bwoebi@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#include "phpdbg_wait.h"
+#include "phpdbg_prompt.h"
+#include "ext/standard/php_var.h"
+#include "ext/standard/basic_functions.h"
+
+ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+
+static void phpdbg_rebuild_http_globals_array(int type, const char *name) {
+ zval *zvp;
+ if (Z_TYPE(PG(http_globals)[type]) != IS_UNDEF) {
+ zval_dtor(&PG(http_globals)[type]);
+ }
+ if ((zvp = zend_hash_str_find(&EG(symbol_table), name, strlen(name)))) {
+ Z_ADDREF_P(zvp);
+ PG(http_globals)[type] = *zvp;
+ }
+}
+
+
+static int phpdbg_dearm_autoglobals(zend_auto_global *auto_global) {
+ if (ZSTR_LEN(auto_global->name) != sizeof("GLOBALS") - 1 || memcmp(ZSTR_VAL(auto_global->name), "GLOBALS", sizeof("GLOBALS") - 1)) {
+ auto_global->armed = 0;
+ }
+
+ return ZEND_HASH_APPLY_KEEP;
+}
+
+typedef struct {
+ HashTable *ht[2];
+ HashPosition pos[2];
+} phpdbg_intersect_ptr;
+
+static int phpdbg_array_data_compare(const void *a, const void *b) {
+ Bucket *f, *s;
+ int result;
+ zval *first, *second;
+
+ f = *((Bucket **) a);
+ s = *((Bucket **) b);
+
+ first = &f->val;
+ second = &s->val;
+
+ result = string_compare_function(first, second);
+
+ if (result < 0) {
+ return -1;
+ } else if (result > 0) {
+ return 1;
+ }
+
+ return 0;
+}
+
+static void phpdbg_array_intersect_init(phpdbg_intersect_ptr *info, HashTable *ht1, HashTable *ht2) {
+ info->ht[0] = ht1;
+ info->ht[1] = ht2;
+
+ zend_hash_sort(info->ht[0], (compare_func_t) phpdbg_array_data_compare, 0);
+ zend_hash_sort(info->ht[1], (compare_func_t) phpdbg_array_data_compare, 0);
+
+ zend_hash_internal_pointer_reset_ex(info->ht[0], &info->pos[0]);
+ zend_hash_internal_pointer_reset_ex(info->ht[1], &info->pos[1]);
+}
+
+/* -1 => first array, 0 => both arrays equal, 1 => second array */
+static int phpdbg_array_intersect(phpdbg_intersect_ptr *info, zval **ptr) {
+ int ret;
+ zval *zvp[2];
+ int invalid = !info->ht[0] + !info->ht[1];
+
+ if (invalid > 0) {
+ invalid = !info->ht[0];
+
+ if (!(*ptr = zend_hash_get_current_data_ex(info->ht[invalid], &info->pos[invalid]))) {
+ return 0;
+ }
+
+ zend_hash_move_forward_ex(info->ht[invalid], &info->pos[invalid]);
+
+ return invalid ? 1 : -1;
+ }
+
+ if (!(zvp[0] = zend_hash_get_current_data_ex(info->ht[0], &info->pos[0]))) {
+ info->ht[0] = NULL;
+ return phpdbg_array_intersect(info, ptr);
+ }
+ if (!(zvp[1] = zend_hash_get_current_data_ex(info->ht[1], &info->pos[1]))) {
+ info->ht[1] = NULL;
+ return phpdbg_array_intersect(info, ptr);
+ }
+
+ ret = zend_binary_zval_strcmp(zvp[0], zvp[1]);
+
+ if (ret <= 0) {
+ *ptr = zvp[0];
+ zend_hash_move_forward_ex(info->ht[0], &info->pos[0]);
+ }
+ if (ret >= 0) {
+ *ptr = zvp[1];
+ zend_hash_move_forward_ex(info->ht[1], &info->pos[1]);
+ }
+
+ return ret;
+}
+
+void phpdbg_webdata_decompress(char *msg, int len) {
+ zval *free_zv = NULL;
+ zval zv, *zvp;
+ HashTable *ht;
+ php_unserialize_data_t var_hash;
+
+ PHP_VAR_UNSERIALIZE_INIT(var_hash);
+ if (!php_var_unserialize(&zv, (const unsigned char **) &msg, (unsigned char *) msg + len, &var_hash)) {
+ PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
+ phpdbg_error("wait", "type=\"invaliddata\" import=\"fail\"", "Malformed serialized was sent to this socket, arborting");
+ return;
+ }
+ PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
+
+ ht = Z_ARRVAL(zv);
+
+ /* Reapply symbol table */
+ if ((zvp = zend_hash_str_find(ht, ZEND_STRL("GLOBALS"))) && Z_TYPE_P(zvp) == IS_ARRAY) {
+ {
+ zval *srv;
+ if ((srv = zend_hash_str_find(Z_ARRVAL_P(zvp), ZEND_STRL("_SERVER"))) && Z_TYPE_P(srv) == IS_ARRAY) {
+ zval *script;
+ if ((script = zend_hash_str_find(Z_ARRVAL_P(srv), ZEND_STRL("SCRIPT_FILENAME"))) && Z_TYPE_P(script) == IS_STRING) {
+ phpdbg_param_t param;
+ param.str = Z_STRVAL_P(script);
+ PHPDBG_COMMAND_HANDLER(exec)(&param);
+ }
+ }
+ }
+
+ PG(auto_globals_jit) = 0;
+ zend_hash_apply(CG(auto_globals), (apply_func_t) phpdbg_dearm_autoglobals);
+
+ zend_hash_clean(&EG(symbol_table));
+ EG(symbol_table) = *Z_ARR_P(zvp);
+
+ /* Rebuild cookies, env vars etc. from GLOBALS (PG(http_globals)) */
+ phpdbg_rebuild_http_globals_array(TRACK_VARS_POST, "_POST");
+ phpdbg_rebuild_http_globals_array(TRACK_VARS_GET, "_GET");
+ phpdbg_rebuild_http_globals_array(TRACK_VARS_COOKIE, "_COOKIE");
+ phpdbg_rebuild_http_globals_array(TRACK_VARS_SERVER, "_SERVER");
+ phpdbg_rebuild_http_globals_array(TRACK_VARS_ENV, "_ENV");
+ phpdbg_rebuild_http_globals_array(TRACK_VARS_FILES, "_FILES");
+
+ Z_ADDREF_P(zvp);
+ free_zv = zvp;
+ }
+
+ if ((zvp = zend_hash_str_find(ht, ZEND_STRL("input"))) && Z_TYPE_P(zvp) == IS_STRING) {
+ if (SG(request_info).request_body) {
+ php_stream_close(SG(request_info).request_body);
+ }
+ SG(request_info).request_body = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE, PG(upload_tmp_dir));
+ php_stream_truncate_set_size(SG(request_info).request_body, 0);
+ php_stream_write(SG(request_info).request_body, Z_STRVAL_P(zvp), Z_STRLEN_P(zvp));
+ }
+
+ if ((zvp = zend_hash_str_find(ht, ZEND_STRL("cwd"))) && Z_TYPE_P(zvp) == IS_STRING) {
+ if (VCWD_CHDIR(Z_STRVAL_P(zvp)) == SUCCESS) {
+ if (BG(CurrentStatFile) && !IS_ABSOLUTE_PATH(BG(CurrentStatFile), strlen(BG(CurrentStatFile)))) {
+ efree(BG(CurrentStatFile));
+ BG(CurrentStatFile) = NULL;
+ }
+ if (BG(CurrentLStatFile) && !IS_ABSOLUTE_PATH(BG(CurrentLStatFile), strlen(BG(CurrentLStatFile)))) {
+ efree(BG(CurrentLStatFile));
+ BG(CurrentLStatFile) = NULL;
+ }
+ }
+ }
+
+ if ((zvp = zend_hash_str_find(ht, ZEND_STRL("sapi_name"))) && (Z_TYPE_P(zvp) == IS_STRING || Z_TYPE_P(zvp) == IS_NULL)) {
+ if (PHPDBG_G(sapi_name_ptr)) {
+ free(PHPDBG_G(sapi_name_ptr));
+ }
+ if (Z_TYPE_P(zvp) == IS_STRING) {
+ PHPDBG_G(sapi_name_ptr) = sapi_module.name = strdup(Z_STRVAL_P(zvp));
+ } else {
+ PHPDBG_G(sapi_name_ptr) = sapi_module.name = NULL;
+ }
+ }
+
+ if ((zvp = zend_hash_str_find(ht, ZEND_STRL("modules"))) && Z_TYPE_P(zvp) == IS_ARRAY) {
+ phpdbg_intersect_ptr pos;
+ zval *module;
+ zend_module_entry *mod;
+ HashTable zv_registry;
+
+ /* intersect modules, unregister modules loaded "too much", announce not yet registered modules (phpdbg_notice) */
+
+ zend_hash_init(&zv_registry, zend_hash_num_elements(&module_registry), 0, ZVAL_PTR_DTOR, 0);
+ ZEND_HASH_FOREACH_PTR(&module_registry, mod) {
+ if (mod->name) {
+ zval value;
+ ZVAL_NEW_STR(&value, zend_string_init(mod->name, strlen(mod->name), 0));
+ zend_hash_next_index_insert(&zv_registry, &value);
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ phpdbg_array_intersect_init(&pos, &zv_registry, Z_ARRVAL_P(zvp));
+ do {
+ int mode = phpdbg_array_intersect(&pos, &module);
+ if (mode < 0) {
+ // loaded module, but not needed
+ if (strcmp(PHPDBG_NAME, Z_STRVAL_P(module))) {
+ zend_hash_del(&module_registry, Z_STR_P(module));
+ }
+ } else if (mode > 0) {
+ // not loaded module
+ if (!sapi_module.name || strcmp(sapi_module.name, Z_STRVAL_P(module))) {
+ phpdbg_notice("wait", "missingmodule=\"%.*s\"", "The module %.*s isn't present in " PHPDBG_NAME ", you still can load via dl /path/to/module/%.*s.so", Z_STRLEN_P(module), Z_STRVAL_P(module), Z_STRLEN_P(module), Z_STRVAL_P(module));
+ }
+ }
+ } while (module);
+
+ zend_hash_clean(&zv_registry);
+ }
+
+ if ((zvp = zend_hash_str_find(ht, ZEND_STRL("extensions"))) && Z_TYPE_P(zvp) == IS_ARRAY) {
+ zend_extension *extension;
+ zend_llist_position pos;
+ zval *name = NULL;
+ zend_string *strkey;
+
+ extension = (zend_extension *) zend_llist_get_first_ex(&zend_extensions, &pos);
+ while (extension) {
+ extension = (zend_extension *) zend_llist_get_next_ex(&zend_extensions, &pos);
+
+ /* php_serach_array() body should be in some ZEND_API function... */
+ ZEND_HASH_FOREACH_STR_KEY_PTR(Z_ARRVAL_P(zvp), strkey, name) {
+ if (Z_TYPE_P(name) == IS_STRING && !zend_binary_strcmp(extension->name, strlen(extension->name), Z_STRVAL_P(name), Z_STRLEN_P(name))) {
+ break;
+ }
+ name = NULL;
+ } ZEND_HASH_FOREACH_END();
+
+ if (name) {
+ /* sigh, breaking the encapsulation, there aren't any functions manipulating the llist at the place of the zend_llist_position */
+ zend_llist_element *elm = pos;
+ if (elm->prev) {
+ elm->prev->next = elm->next;
+ } else {
+ zend_extensions.head = elm->next;
+ }
+ if (elm->next) {
+ elm->next->prev = elm->prev;
+ } else {
+ zend_extensions.tail = elm->prev;
+ }
+#if ZEND_EXTENSIONS_SUPPORT
+ if (extension->shutdown) {
+ extension->shutdown(extension);
+ }
+#endif
+ if (zend_extensions.dtor) {
+ zend_extensions.dtor(elm->data);
+ }
+ pefree(elm, zend_extensions.persistent);
+ zend_extensions.count--;
+ } else {
+/* zend_hash_get_current_key_zval_ex(Z_ARRVAL_PP(zvpp), &key, &hpos);
+ if (Z_TYPE(key) == IS_LONG) {
+ zend_hash_index_del(Z_ARRVAL_PP(zvpp), Z_LVAL(key));
+ }
+*/
+ zend_hash_del(Z_ARRVAL_P(zvp), strkey);
+ }
+ }
+
+ ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zvp), name) {
+ if (Z_TYPE_P(name) == IS_STRING) {
+ phpdbg_notice("wait", "missingextension=\"%.*s\"", "The Zend extension %.*s isn't present in " PHPDBG_NAME ", you still can load via dl /path/to/extension.so", Z_STRLEN_P(name), Z_STRVAL_P(name));
+ }
+ } ZEND_HASH_FOREACH_END();
+ }
+
+ zend_ini_deactivate();
+
+ if ((zvp = zend_hash_str_find(ht, ZEND_STRL("systemini"))) && Z_TYPE_P(zvp) == IS_ARRAY) {
+ zval *ini_entry;
+ zend_ini_entry *original_ini;
+ zend_string *key;
+
+ ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zvp), key, ini_entry) {
+ if (key && Z_TYPE_P(ini_entry) == IS_STRING) {
+ if ((original_ini = zend_hash_find_ptr(EG(ini_directives), key))) {
+ if (!original_ini->on_modify || original_ini->on_modify(original_ini, Z_STR_P(ini_entry), original_ini->mh_arg1, original_ini->mh_arg2, original_ini->mh_arg3, ZEND_INI_STAGE_ACTIVATE) == SUCCESS) {
+ if (original_ini->modified && original_ini->orig_value != original_ini->value) {
+ efree(original_ini->value);
+ }
+ original_ini->value = Z_STR_P(ini_entry);
+ Z_ADDREF_P(ini_entry); /* don't free the string */
+ }
+ }
+ }
+ } ZEND_HASH_FOREACH_END();
+ }
+
+ if ((zvp = zend_hash_str_find(ht, ZEND_STRL("userini"))) && Z_TYPE_P(zvp) == IS_ARRAY) {
+ zval *ini_entry;
+ zend_string *key;
+
+ ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(zvp), key, ini_entry) {
+ if (key && Z_TYPE_P(ini_entry) == IS_STRING) {
+ zend_alter_ini_entry_ex(key, Z_STR_P(ini_entry), ZEND_INI_PERDIR, ZEND_INI_STAGE_HTACCESS, 1);
+ }
+ } ZEND_HASH_FOREACH_END();
+ }
+
+ zval_dtor(&zv);
+ if (free_zv) {
+ /* separate freeing to not dtor the symtable too, just the container zval... */
+ efree(free_zv);
+ }
+
+ /* Reapply raw input */
+ /* ??? */
+}
+
+PHPDBG_COMMAND(wait) /* {{{ */
+{
+#ifndef PHP_WIN32
+ struct sockaddr_un local, remote;
+ int rlen, sr, sl;
+ unlink(PHPDBG_G(socket_path));
+ if (PHPDBG_G(socket_server_fd) == -1) {
+ int len;
+ PHPDBG_G(socket_server_fd) = sl = socket(AF_UNIX, SOCK_STREAM, 0);
+
+ local.sun_family = AF_UNIX;
+ strcpy(local.sun_path, PHPDBG_G(socket_path));
+ len = strlen(local.sun_path) + sizeof(local.sun_family);
+ if (bind(sl, (struct sockaddr *)&local, len) == -1) {
+ phpdbg_error("wait", "type=\"nosocket\" import=\"fail\"", "Unable to connect to UNIX domain socket at %s defined by phpdbg.path ini setting", PHPDBG_G(socket_path));
+ return FAILURE;
+ }
+
+ chmod(PHPDBG_G(socket_path), 0666);
+
+ listen(sl, 2);
+ } else {
+ sl = PHPDBG_G(socket_server_fd);
+ }
+
+ rlen = sizeof(remote);
+ sr = accept(sl, (struct sockaddr *) &remote, (socklen_t *) &rlen);
+
+ char msglen[5];
+ int recvd = 4;
+
+ do {
+ recvd -= recv(sr, &(msglen[4 - recvd]), recvd, 0);
+ } while (recvd > 0);
+
+ recvd = *(size_t *) msglen;
+ char *data = emalloc(recvd);
+
+ do {
+ recvd -= recv(sr, &(data[(*(int *) msglen) - recvd]), recvd, 0);
+ } while (recvd > 0);
+
+ phpdbg_webdata_decompress(data, *(int *) msglen);
+
+ if (PHPDBG_G(socket_fd) != -1) {
+ close(PHPDBG_G(socket_fd));
+ }
+ PHPDBG_G(socket_fd) = sr;
+
+ efree(data);
+
+ phpdbg_notice("wait", "import=\"success\"", "Successfully imported request data, stopped before executing");
+#endif
+
+ return SUCCESS;
+} /* }}} */
diff --git a/sapi/phpdbg/phpdbg_wait.h b/sapi/phpdbg/phpdbg_wait.h
new file mode 100644
index 0000000000..569e54b5a7
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_wait.h
@@ -0,0 +1,29 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Bob Weinand <bwoebi@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#ifndef PHPDBG_WAIT_H
+#define PHPDBG_WAIT_H
+
+#include "zend.h"
+#include "phpdbg.h"
+
+PHPDBG_COMMAND(wait);
+
+void phpdbg_webdata_decompress(char *msg, int len);
+
+#endif /* PHPDBG_WAIT_H */
diff --git a/sapi/phpdbg/phpdbg_watch.c b/sapi/phpdbg/phpdbg_watch.c
index 422cf92b72..4cf3acbb6c 100644
--- a/sapi/phpdbg/phpdbg_watch.c
+++ b/sapi/phpdbg/phpdbg_watch.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -18,11 +18,63 @@
+----------------------------------------------------------------------+
*/
+/* Some information for the reader...
+ *
+ * Watchpoints are either simple, recursive or implicit (PHPDBG_WATCH_* flags)
+ * Simple means that a particular watchpoint was explicitely defined
+ * Recursive watchpoints are created recursively and substitute simple watchpoints
+ * Implicit watchpoints are implicitely created on all ancestors of simple or recursive watchpoints
+ * Recursive and (simple or implicit) watchpoints are mutually exclusive
+ *
+ * PHPDBG_G(watchpoint_tree) contains all watchpoints identified by the watch target address
+ * PHPDBG_G(watch_HashTables) contains the dtors of the HashTables to call in our custom dtor (we substitute the dtor of HashTables containing watched zvals by our own dtor)
+ * PHPDBG_G(watchpoints) contains all watchpoints (except the ones managed by watch collision)
+ * PHPDBG_G(watch_collisions) is indexed by a zend_reference * pointer. It stores information about collisions (everything which contains a zend_reference * may be referenced by multiple watches)
+ *
+ * Creating a watchpoint:
+ * * Create watchpoints with PHPDBG_WATCH_IMPLICIT set on each zval and HashTable in hierarchy except the last zval or HashTable fetch. (if already existing PHPDBG_WATCH_IMPLICIT flag is added)
+ * * Create a PHPDBG_WATCH_SIMPLE watch for simple watches or a PHPDBG_WATCH_RECURSIVE watch for recursive watches
+ * * When the target zval is an IS_REFERENCE, create a watchpoint on it too
+ * * Each time a watchpoints parent is a zval and it is Z_REFCOUNTED(), put a watchpoint (WATCH_ON_REFCOUNTED) on it and add a watchpoint collision
+ * * When in recursive mode and encountering a not-refcounted PHPDBG_WATCH_SIMPLE, remove it and recreate it with a PHPDBG_WATCH_RECURSIVE (handled via watch collision)
+ * * Make attention to not add something twice or iterate over it twice
+ *
+ * Deleting a watchpoint:
+ * * Only allow deletion of recursive watches at their root and simple watches
+ * * Go to referenced variable. And remove watch collision on *parent* (if there is a parent)
+ * * If it is Z_REFCOUNTED(), remove that watch collision
+ *
+ * Watch collisions:
+ * * hold a counter for recursive, if it is incremented from 0 to 1, create recursive watchpoint
+ * * holds a HashTable for normal (not implicit) watchpoints ... it is used to get the fetch type of the HashTable (depending on whether it is empty or not)
+ * * holds a HashTable for implicit watchpoints ... (some sort of a refcounter, but ensure that there are no duplicates)
+ * * if normal and implicit watchpoints are empty, drop that watch collision and remove WATCH_ON_REFCOUNT alongside with watchpoint on an eventual reference
+ *
+ * Watching on addresses:
+ * * Address and size are transformed into memory page aligned address and size
+ * * mprotect() enables or disables them (depending on flags) - Windows has a transparent compatibility layer in phpdbg_win.c
+ * * segfault handler dumps watched memory segment and deactivates watchpoint
+ * * later watches inside these memory segments are compared against their current value and eventually reactivated (or deleted)
+ *
+ * A watched zval was removed:
+ * * trigger a memory copy (in segv handler) and an automatic deactivation
+ * * change a type flag _zval_struct.u1.v.type_flags (add PHPDBG_DESTRUCTED_ZVAL flag) in memory dump
+ *
+ * A watched zval was changed:
+ * * check if parent container has a different reference for referenced zval - recursively update all watches and drop them if necessary
+ * * if _zval_struct.u1.v.type_flags & PHPDBG_DESTRUCTED_ZVAL, add it to a list of zvals to be handled at the end (if location was not changed, remove it finally)
+ * * display changes if watch->flags & PHPDBG_WATCH_NORMAL (means: not implicit)
+ * * handle case where Z_RECOUNTED() or Z_PTR() changed (remove/add collison(s))
+ * * if necessary ... on zvals: handle references, if recursive also objects and arrays ... on arrays: if recursive, add new elements
+ * * drop destructed zval watchpoints which were not updated
+ */
+
#include "zend.h"
#include "phpdbg.h"
#include "phpdbg_btree.h"
#include "phpdbg_watch.h"
#include "phpdbg_utils.h"
+#include "phpdbg_prompt.h"
#ifndef _WIN32
# include <unistd.h>
# include <sys/mman.h>
@@ -30,6 +82,19 @@
ZEND_EXTERN_MODULE_GLOBALS(phpdbg);
+const phpdbg_command_t phpdbg_watch_commands[] = {
+ PHPDBG_COMMAND_D_EX(array, "create watchpoint on an array", 'a', watch_array, &phpdbg_prompt_commands[24], "s", 0),
+ PHPDBG_COMMAND_D_EX(delete, "delete watchpoint", 'd', watch_delete, &phpdbg_prompt_commands[24], "s", 0),
+ PHPDBG_COMMAND_D_EX(recursive, "create recursive watchpoints", 'r', watch_recursive, &phpdbg_prompt_commands[24], "s", 0),
+ PHPDBG_END_COMMAND
+};
+
+//#define HT_FROM_WATCH(watch) (watch->type == WATCH_ON_OBJECT ? watch->addr.obj->handlers->get_properties(watch->parent_container.zv) : watch->type == WATCH_ON_ARRAY ? &watch->addr.arr->ht : NULL)
+#define HT_FROM_ZVP(zvp) (Z_TYPE_P(zvp) == IS_OBJECT ? Z_OBJPROP_P(zvp) : Z_TYPE_P(zvp) == IS_ARRAY ? Z_ARRVAL_P(zvp) : NULL)
+
+#define HT_WATCH_OFFSET (sizeof(zend_refcounted *) + sizeof(uint32_t)) /* we are not interested in gc and flags */
+#define HT_PTR_HT(ptr) ((HashTable *) (((char *) (ptr)) - HT_WATCH_OFFSET))
+#define HT_WATCH_HT(watch) HT_PTR_HT((watch)->addr.ptr)
typedef struct {
void *page;
@@ -42,7 +107,7 @@ typedef struct {
#define MEMDUMP_SIZE(size) (sizeof(phpdbg_watch_memdump) - sizeof(void *) + (size))
-static phpdbg_watchpoint_t *phpdbg_check_for_watchpoint(void *addr TSRMLS_DC) {
+static phpdbg_watchpoint_t *phpdbg_check_for_watchpoint(void *addr) {
phpdbg_watchpoint_t *watch;
phpdbg_btree_result *result = phpdbg_btree_find_closest(&PHPDBG_G(watchpoint_tree), (zend_ulong)phpdbg_get_page_boundary(addr) + phpdbg_pagesize - 1);
@@ -53,7 +118,7 @@ static phpdbg_watchpoint_t *phpdbg_check_for_watchpoint(void *addr TSRMLS_DC) {
watch = result->ptr;
/* check if that addr is in a mprotect()'ed memory area */
- if ((char *)phpdbg_get_page_boundary(watch->addr.ptr) > (char *)addr || (char *)phpdbg_get_page_boundary(watch->addr.ptr) + phpdbg_get_total_page_size(watch->addr.ptr, watch->size) < (char *)addr) {
+ if ((char *) phpdbg_get_page_boundary(watch->addr.ptr) > (char *) addr || (char *) phpdbg_get_page_boundary(watch->addr.ptr) + phpdbg_get_total_page_size(watch->addr.ptr, watch->size) < (char *) addr) {
/* failure */
return NULL;
}
@@ -61,27 +126,25 @@ static phpdbg_watchpoint_t *phpdbg_check_for_watchpoint(void *addr TSRMLS_DC) {
return watch;
}
-static void phpdbg_change_watchpoint_access(phpdbg_watchpoint_t *watch, int access TSRMLS_DC) {
- int m;
-
+static void phpdbg_change_watchpoint_access(phpdbg_watchpoint_t *watch, int access) {
/* pagesize is assumed to be in the range of 2^x */
- m = mprotect(phpdbg_get_page_boundary(watch->addr.ptr), phpdbg_get_total_page_size(watch->addr.ptr, watch->size), access);
+ mprotect(phpdbg_get_page_boundary(watch->addr.ptr), phpdbg_get_total_page_size(watch->addr.ptr, watch->size), access);
}
-static inline void phpdbg_activate_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) {
- phpdbg_change_watchpoint_access(watch, PROT_READ TSRMLS_CC);
+static inline void phpdbg_activate_watchpoint(phpdbg_watchpoint_t *watch) {
+ phpdbg_change_watchpoint_access(watch, PROT_READ);
}
-static inline void phpdbg_deactivate_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) {
- phpdbg_change_watchpoint_access(watch, PROT_READ | PROT_WRITE TSRMLS_CC);
+static inline void phpdbg_deactivate_watchpoint(phpdbg_watchpoint_t *watch) {
+ phpdbg_change_watchpoint_access(watch, PROT_READ | PROT_WRITE);
}
-static inline void phpdbg_store_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) {
- phpdbg_btree_insert(&PHPDBG_G(watchpoint_tree), (zend_ulong)watch->addr.ptr, watch);
+static inline void phpdbg_store_watchpoint(phpdbg_watchpoint_t *watch) {
+ phpdbg_btree_insert(&PHPDBG_G(watchpoint_tree), (zend_ulong) watch->addr.ptr, watch);
}
-static inline void phpdbg_remove_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) {
- phpdbg_btree_delete(&PHPDBG_G(watchpoint_tree), (zend_ulong)watch->addr.ptr);
+static inline void phpdbg_remove_watchpoint(phpdbg_watchpoint_t *watch) {
+ phpdbg_btree_delete(&PHPDBG_G(watchpoint_tree), (zend_ulong) watch->addr.ptr);
}
void phpdbg_create_addr_watchpoint(void *addr, size_t size, phpdbg_watchpoint_t *watch) {
@@ -95,326 +158,547 @@ void phpdbg_create_zval_watchpoint(zval *zv, phpdbg_watchpoint_t *watch) {
}
void phpdbg_create_ht_watchpoint(HashTable *ht, phpdbg_watchpoint_t *watch) {
- phpdbg_create_addr_watchpoint(ht, sizeof(HashTable), watch);
+ phpdbg_create_addr_watchpoint(((char *) ht) + HT_WATCH_OFFSET, sizeof(HashTable) - HT_WATCH_OFFSET, watch);
watch->type = WATCH_ON_HASHTABLE;
+ watch->implicit_ht_count = 0;
}
-void phpdbg_watch_HashTable_dtor(zval **ptr);
+static int phpdbg_create_recursive_ht_watch(phpdbg_watchpoint_t *watch);
+static int phpdbg_create_recursive_zval_watch(phpdbg_watchpoint_t *watch);
-static int phpdbg_create_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) {
- watch->flags |= PHPDBG_WATCH_SIMPLE;
+void phpdbg_watch_HashTable_dtor(zval *ptr);
- phpdbg_store_watchpoint(watch TSRMLS_CC);
- zend_hash_add(&PHPDBG_G(watchpoints), watch->str, watch->str_len, &watch, sizeof(phpdbg_watchpoint_t *), NULL);
+static void phpdbg_free_watch(phpdbg_watchpoint_t *watch) {
+ zend_string_release(watch->str);
+ zend_string_release(watch->name_in_parent);
+}
- if (watch->type == WATCH_ON_ZVAL) {
- phpdbg_btree_insert(&PHPDBG_G(watch_HashTables), (zend_ulong)watch->parent_container, watch->parent_container->pDestructor);
- watch->parent_container->pDestructor = (dtor_func_t)phpdbg_watch_HashTable_dtor;
+static int phpdbg_delete_watchpoint(phpdbg_watchpoint_t *tmp_watch);
+static void phpdbg_delete_ht_watchpoints_recursive(phpdbg_watchpoint_t *watch);
+static void phpdbg_delete_zval_watchpoints_recursive(phpdbg_watchpoint_t *watch);
+static void phpdbg_delete_watchpoints_recursive(phpdbg_watchpoint_t *watch);
+
+/* Store all the possible watches the refcounted may refer to (for displaying & deleting by identifier) [collision] */
+static phpdbg_watchpoint_t *phpdbg_create_refcounted_watchpoint(phpdbg_watchpoint_t *parent, zend_refcounted *ref) {
+ phpdbg_watchpoint_t *watch = emalloc(sizeof(phpdbg_watchpoint_t));
+ watch->flags = parent->flags;
+ watch->parent = parent;
+ watch->str = parent->str;
+ ++GC_REFCOUNT(parent->str);
+ phpdbg_create_addr_watchpoint(&GC_REFCOUNT(ref), sizeof(uint32_t), watch);
+ watch->type = WATCH_ON_REFCOUNTED;
+
+ return watch;
+}
+
+/* Must prevent duplicates ... if there are duplicates, replace new by old! */
+static void phpdbg_add_watch_collision(phpdbg_watchpoint_t *watch) {
+ phpdbg_watch_collision *cur;
+
+ /* Check for either recursive or (simple and/or implicit) */
+ ZEND_ASSERT(((watch->flags & PHPDBG_WATCH_RECURSIVE) == 0) ^ ((watch->flags & (PHPDBG_WATCH_IMPLICIT | PHPDBG_WATCH_SIMPLE)) == 0));
+
+ if ((cur = zend_hash_index_find_ptr(&PHPDBG_G(watch_collisions), (zend_ulong) watch->addr.ref))) {
+ phpdbg_watchpoint_t *old;
+ int flags = 0;
+ if ((old = zend_hash_find_ptr(&cur->watches, watch->str)) || (old = zend_hash_find_ptr(&cur->implicit_watches, watch->str))) {
+ if (((old->flags ^ watch->flags) & (PHPDBG_WATCH_NORMAL|PHPDBG_WATCH_IMPLICIT)) == 0) {
+ return; /* there was no change ... */
+ }
+
+ flags = old->flags;
+
+ if (flags & PHPDBG_WATCH_RECURSIVE) {
+ if (!(watch->flags & PHPDBG_WATCH_RECURSIVE) && !--cur->refs) {
+ phpdbg_delete_watchpoints_recursive(watch);
+ }
+ }
+ if (flags & PHPDBG_WATCH_NORMAL) {
+ zend_hash_del(&cur->watches, watch->str);
+ if (zend_hash_num_elements(&cur->watches) > 0) {
+ cur->watch = Z_PTR_P(zend_hash_get_current_data_ex(&cur->watches, NULL));
+ } else {
+ cur->watch = Z_PTR_P(zend_hash_get_current_data_ex(&cur->implicit_watches, NULL));
+ }
+ }
+ if (flags & PHPDBG_WATCH_IMPLICIT) {
+ zend_hash_del(&cur->implicit_watches, watch->str);
+ }
+
+ old->flags = watch->flags;
+ phpdbg_free_watch(watch);
+ efree(watch);
+ watch = old;
+ }
+ if (watch->flags & PHPDBG_WATCH_RECURSIVE) {
+ if (!(flags & PHPDBG_WATCH_RECURSIVE) && !cur->refs++) {
+ phpdbg_create_recursive_zval_watch(watch->parent);
+ }
+ }
+ } else {
+ phpdbg_watch_collision coll;
+ coll.refs = (watch->flags & PHPDBG_WATCH_RECURSIVE) != 0;
+ coll.watch = watch;
+ zend_hash_init(&coll.watches, 8, arghs, NULL, 0);
+ zend_hash_init(&coll.implicit_watches, 8, ..., NULL, 0);
+ cur = zend_hash_index_add_mem(&PHPDBG_G(watch_collisions), (zend_ulong) watch->addr.ref, &coll, sizeof(phpdbg_watch_collision));
+ phpdbg_store_watchpoint(cur->watch);
+ phpdbg_activate_watchpoint(cur->watch);
+ if (coll.refs) {
+ phpdbg_create_recursive_zval_watch(watch->parent);
+ }
}
- phpdbg_activate_watchpoint(watch TSRMLS_CC);
+ if (watch->flags & PHPDBG_WATCH_NORMAL) {
+ cur->watch = watch;
+ zend_hash_add_ptr(&cur->watches, watch->str, watch->parent);
+ }
+ if (watch->flags & PHPDBG_WATCH_IMPLICIT) {
+ zend_hash_add_ptr(&cur->implicit_watches, watch->str, watch->parent);
+ }
+}
- return SUCCESS;
+static void phpdbg_remove_watch_collision(phpdbg_watchpoint_t *watch) {
+ phpdbg_watch_collision *cur;
+ if ((cur = zend_hash_index_find_ptr(&PHPDBG_G(watch_collisions), (zend_ulong) Z_COUNTED_P(watch->addr.zv)))) {
+ if (cur->refs && !--cur->refs) {
+ phpdbg_delete_watchpoints_recursive(watch);
+ }
+
+ zend_hash_del(&cur->watches, watch->str);
+ zend_hash_del(&cur->implicit_watches, watch->str);
+
+ if (zend_hash_num_elements(&cur->watches) > 0) {
+ cur->watch = Z_PTR_P(zend_hash_get_current_data_ex(&cur->watches, NULL));
+ } else if (zend_hash_num_elements(&cur->implicit_watches) > 0) {
+ cur->watch = Z_PTR_P(zend_hash_get_current_data_ex(&cur->implicit_watches, NULL));
+ } else {
+ phpdbg_deactivate_watchpoint(cur->watch);
+ phpdbg_remove_watchpoint(cur->watch);
+
+ zend_hash_index_del(&PHPDBG_G(watch_collisions), (zend_ulong) Z_COUNTED_P(watch->addr.zv));
+ }
+ }
}
-static int phpdbg_create_array_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) {
- HashTable *ht;
+static phpdbg_watchpoint_t *phpdbg_create_watchpoint(phpdbg_watchpoint_t *watch);
- switch (Z_TYPE_P(watch->addr.zv)) {
- case IS_ARRAY:
- ht = Z_ARRVAL_P(watch->addr.zv);
- break;
- case IS_OBJECT:
- ht = Z_OBJPROP_P(watch->addr.zv);
- break;
- default:
- return FAILURE;
+static phpdbg_watchpoint_t *phpdbg_create_reference_watch(phpdbg_watchpoint_t *watch) {
+ phpdbg_watchpoint_t *ref = emalloc(sizeof(phpdbg_watchpoint_t));
+ watch->reference = ref;
+ ref->flags = watch->flags;
+ ref->str = watch->str;
+ ++GC_REFCOUNT(ref->str);
+ ref->parent = watch;
+ ref->parent_container = NULL;
+ phpdbg_create_zval_watchpoint(Z_REFVAL_P(watch->addr.zv), ref);
+
+ phpdbg_create_watchpoint(ref);
+
+ return ref;
+}
+
+static phpdbg_watchpoint_t *phpdbg_get_refcount_watch(phpdbg_watchpoint_t *parent) {
+ zend_refcounted *ref;
+ phpdbg_btree_result *res;
+
+ if (parent->type == WATCH_ON_HASHTABLE) {
+ parent = parent->parent;
+ if (!parent) {
+ return NULL;
+ }
}
- phpdbg_create_ht_watchpoint(ht, watch);
+ ZEND_ASSERT(parent->type == WATCH_ON_ZVAL);
+ ref = Z_COUNTED_P(parent->addr.zv);
- phpdbg_create_watchpoint(watch TSRMLS_CC);
+ res = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong) ref);
+ if (res) {
+ return res->ptr;
+ }
+ return NULL;
+}
- return SUCCESS;
+static phpdbg_watchpoint_t *phpdbg_create_watchpoint(phpdbg_watchpoint_t *watch) {
+ phpdbg_watchpoint_t *ret = watch;
+
+ if (watch->type == WATCH_ON_ZVAL) {
+ switch (Z_TYPE_P(watch->addr.zv)) {
+ case IS_NULL:
+ case IS_UNDEF:
+ case IS_TRUE:
+ case IS_FALSE:
+ memset(watch->addr.zv, 0, sizeof(zend_value));
+ }
+ }
+
+ /* exclude references & refcounted */
+ if (!watch->parent || watch->parent->type != WATCH_ON_ZVAL || watch->type == WATCH_ON_HASHTABLE) {
+ phpdbg_watchpoint_t *old_watch = zend_hash_find_ptr(&PHPDBG_G(watchpoints), watch->str);
+
+ if (old_watch) {
+#define return_and_free_watch(x) { \
+ phpdbg_watchpoint_t *ref = phpdbg_get_refcount_watch(old_watch); \
+ if (ref) { \
+ phpdbg_add_watch_collision(ref); \
+ } \
+ if (watch != old_watch) { \
+ phpdbg_free_watch(watch); \
+ efree(watch); \
+ } \
+ return (x); \
}
+ if (watch->flags & PHPDBG_WATCH_RECURSIVE) {
+ if (old_watch->flags & PHPDBG_WATCH_RECURSIVE) {
+ return_and_free_watch(NULL);
+ } else {
+ old_watch->flags &= ~(PHPDBG_WATCH_SIMPLE | PHPDBG_WATCH_IMPLICIT);
+ old_watch->flags |= PHPDBG_WATCH_RECURSIVE;
+ return_and_free_watch(old_watch);
+ }
+ } else {
+ if (!(old_watch->flags & PHPDBG_WATCH_RECURSIVE)) {
+ old_watch->flags |= watch->flags & (PHPDBG_WATCH_IMPLICIT | PHPDBG_WATCH_SIMPLE);
+ }
+ return_and_free_watch(NULL);
+ }
+ } else {
+ if (watch->parent && watch->parent->type == WATCH_ON_HASHTABLE) {
+ watch->parent->implicit_ht_count++;
+ }
+ zend_hash_add_ptr(&PHPDBG_G(watchpoints), watch->str, watch);
+ }
+ }
+
+ phpdbg_store_watchpoint(watch);
+
+ if (watch->parent && watch->parent->type == WATCH_ON_ZVAL && Z_REFCOUNTED_P(watch->parent->addr.zv)) {
+ phpdbg_add_watch_collision(phpdbg_create_refcounted_watchpoint(watch, Z_COUNTED_P(watch->parent->addr.zv)));
+ }
+
+ if (watch->type == WATCH_ON_ZVAL) {
+ if (watch->parent_container) {
+ HashTable *ht_watches;
+ phpdbg_btree_result *find;
+ if (!(find = phpdbg_btree_find(&PHPDBG_G(watch_HashTables), (zend_ulong) watch->parent_container))) {
+ phpdbg_watch_ht_info *hti = emalloc(sizeof(*hti));
+ hti->dtor = watch->parent_container->pDestructor;
+ ht_watches = &hti->watches;
+ zend_hash_init(ht_watches, 0, grrrrr, ZVAL_PTR_DTOR, 0);
+ phpdbg_btree_insert(&PHPDBG_G(watch_HashTables), (zend_ulong) watch->parent_container, hti);
+ watch->parent_container->pDestructor = (dtor_func_t) phpdbg_watch_HashTable_dtor;
+ } else {
+ ht_watches = &((phpdbg_watch_ht_info *) find->ptr)->watches;
+ }
+ zend_hash_add_ptr(ht_watches, watch->name_in_parent, watch);
+ }
-static char *phpdbg_get_property_key(char *key) {
- if (*key != 0) {
- return key;
+ if (Z_ISREF_P(watch->addr.zv)) {
+ ret = phpdbg_create_reference_watch(watch);
+ }
}
- return strchr(key + 1, 0) + 1;
+
+ phpdbg_activate_watchpoint(watch);
+
+ return ret;
}
-static int phpdbg_create_recursive_watchpoint(phpdbg_watchpoint_t *watch TSRMLS_DC) {
- HashTable *ht;
+static int phpdbg_create_simple_watchpoint(phpdbg_watchpoint_t *watch) {
+ watch->flags |= PHPDBG_WATCH_SIMPLE;
+
+ phpdbg_create_watchpoint(watch);
+
+ return SUCCESS;
+}
+
+static int phpdbg_create_array_watchpoint(phpdbg_watchpoint_t *zv_watch) {
+ zval *zv = zv_watch->addr.zv;
+ phpdbg_watchpoint_t *watch = emalloc(sizeof(phpdbg_watchpoint_t));
+ HashTable *ht = HT_FROM_ZVP(zv);
+
+ watch->parent = zv_watch;
+
+ if (!ht) {
+ return FAILURE;
+ }
+
+ phpdbg_create_ht_watchpoint(ht, watch);
+
+ if (phpdbg_create_watchpoint(watch) == NULL) {
+ return SUCCESS;
+ }
+
+ if (Z_TYPE_P(zv) == IS_ARRAY) {
+ watch->flags |= PHPDBG_WATCH_ARRAY;
+ } else {
+ watch->flags |= PHPDBG_WATCH_OBJECT;
+ }
+ phpdbg_add_watch_collision(phpdbg_create_refcounted_watchpoint(watch, Z_COUNTED_P(zv)));
+
+ return SUCCESS;
+}
+
+static int phpdbg_create_recursive_watchpoint(phpdbg_watchpoint_t *watch) {
if (watch->type != WATCH_ON_ZVAL) {
return FAILURE;
}
watch->flags |= PHPDBG_WATCH_RECURSIVE;
- phpdbg_create_watchpoint(watch TSRMLS_CC);
+ watch = phpdbg_create_watchpoint(watch);
- switch (Z_TYPE_P(watch->addr.zv)) {
- case IS_ARRAY:
- ht = Z_ARRVAL_P(watch->addr.zv);
- break;
- case IS_OBJECT:
- ht = Z_OBJPROP_P(watch->addr.zv);
- break;
- default:
- return SUCCESS;
- }
+ return SUCCESS;
+}
- {
- HashPosition position;
- zval **zv;
- zval key;
+static int phpdbg_create_recursive_ht_watch(phpdbg_watchpoint_t *watch) {
+ zval *zv;
+ zend_string *key;
+ zend_long h;
- for (zend_hash_internal_pointer_reset_ex(ht, &position);
- zend_hash_get_current_data_ex(ht, (void **)&zv, &position) == SUCCESS;
- zend_hash_move_forward_ex(ht, &position)) {
- phpdbg_watchpoint_t *new_watch = emalloc(sizeof(phpdbg_watchpoint_t));
+ ZEND_ASSERT(watch->type == WATCH_ON_HASHTABLE);
- new_watch->flags = PHPDBG_WATCH_RECURSIVE;
- new_watch->parent = watch;
- new_watch->parent_container = ht;
+ ZEND_HASH_FOREACH_KEY_VAL(HT_WATCH_HT(watch), h, key, zv) {
+ phpdbg_watchpoint_t *new_watch = emalloc(sizeof(phpdbg_watchpoint_t));
- zend_hash_get_current_key_zval_ex(ht, &key, &position);
- if (Z_TYPE(key) == IS_STRING) {
- new_watch->name_in_parent = zend_strndup(Z_STRVAL(key), Z_STRLEN(key));
- new_watch->name_in_parent_len = Z_STRLEN(key);
- } else {
- new_watch->name_in_parent = NULL;
- new_watch->name_in_parent_len = asprintf(&new_watch->name_in_parent, "%ld", Z_LVAL(key));
- }
+ new_watch->flags = PHPDBG_WATCH_RECURSIVE;
+ new_watch->parent = watch;
+ new_watch->parent_container = HT_WATCH_HT(watch);
- new_watch->str = NULL;
- new_watch->str_len = asprintf(&new_watch->str, "%.*s%s%s%s", (int)watch->str_len, watch->str, Z_TYPE_P(watch->addr.zv) == IS_ARRAY?"[":"->", phpdbg_get_property_key(new_watch->name_in_parent), Z_TYPE_P(watch->addr.zv) == IS_ARRAY?"]":"");
+ if (key) {
+ new_watch->name_in_parent = key;
+ ++GC_REFCOUNT(key);
+ } else {
+ new_watch->name_in_parent = strpprintf(0, ZEND_LONG_FMT, h);
+ }
- phpdbg_create_zval_watchpoint(*zv, new_watch);
- phpdbg_create_recursive_watchpoint(new_watch TSRMLS_CC);
+ new_watch->str = strpprintf(0, "%.*s%s%s%s", (int) ZSTR_LEN(watch->str) - 2, ZSTR_VAL(watch->str), (watch->flags & PHPDBG_WATCH_ARRAY) ? "[" : "->", phpdbg_get_property_key(ZSTR_VAL(new_watch->name_in_parent)), (watch->flags & PHPDBG_WATCH_ARRAY) ? "]" : "");
+
+ while (Z_TYPE_P(zv) == IS_INDIRECT) {
+ zv = Z_INDIRECT_P(zv);
}
- }
- {
+ phpdbg_create_zval_watchpoint(zv, new_watch);
+ new_watch = phpdbg_create_watchpoint(new_watch);
+ phpdbg_create_recursive_zval_watch(new_watch);
+ } ZEND_HASH_FOREACH_END();
+
+ return SUCCESS;
+}
+
+static int phpdbg_create_recursive_zval_watch(phpdbg_watchpoint_t *watch) {
+ HashTable *ht;
+ zval *zvp;
+
+ ZEND_ASSERT(watch->type == WATCH_ON_ZVAL);
+
+ zvp = watch->addr.zv;
+ ZVAL_DEREF(zvp);
+
+ if ((ht = HT_FROM_ZVP(zvp))) {
phpdbg_watchpoint_t *new_watch = emalloc(sizeof(phpdbg_watchpoint_t));
+ new_watch->flags = PHPDBG_WATCH_RECURSIVE;
new_watch->parent = watch;
new_watch->parent_container = watch->parent_container;
- new_watch->name_in_parent = zend_strndup(watch->name_in_parent, watch->name_in_parent_len);
- new_watch->name_in_parent_len = watch->name_in_parent_len;
- new_watch->str = NULL;
- new_watch->str_len = asprintf(&new_watch->str, "%.*s[]", (int)watch->str_len, watch->str);
- new_watch->flags = PHPDBG_WATCH_RECURSIVE;
+ new_watch->name_in_parent = watch->name_in_parent;
+ ++GC_REFCOUNT(new_watch->name_in_parent);
+ new_watch->str = strpprintf(0, "%.*s[]", (int) ZSTR_LEN(watch->str), ZSTR_VAL(watch->str));
+
+ if (Z_TYPE_P(zvp) == IS_ARRAY) {
+ new_watch->flags |= PHPDBG_WATCH_ARRAY;
+ } else {
+ new_watch->flags |= PHPDBG_WATCH_OBJECT;
+ }
phpdbg_create_ht_watchpoint(ht, new_watch);
- phpdbg_create_watchpoint(new_watch TSRMLS_CC);
+
+ phpdbg_create_recursive_ht_watch(new_watch);
+
+ phpdbg_create_watchpoint(new_watch);
}
return SUCCESS;
}
-static int phpdbg_delete_watchpoint_recursive(phpdbg_watchpoint_t *watch, zend_bool user_request TSRMLS_DC) {
- if (watch->type == WATCH_ON_HASHTABLE || (watch->type == WATCH_ON_ZVAL && (Z_TYPE_P(watch->addr.zv) == IS_ARRAY || Z_TYPE_P(watch->addr.zv) == IS_OBJECT))) {
- HashTable *ht;
- phpdbg_btree_result *result;
-
- if (watch->type == WATCH_ON_HASHTABLE && user_request) {
- HashPosition position;
- zval **zv;
- zval key;
- char *str;
- int str_len;
- phpdbg_watchpoint_t **watchpoint;
-
- ht = watch->addr.ht;
-
- for (zend_hash_internal_pointer_reset_ex(ht, &position);
- zend_hash_get_current_data_ex(ht, (void **)&zv, &position) == SUCCESS;
- zend_hash_move_forward_ex(ht, &position)) {
- zend_hash_get_current_key_zval_ex(ht, &key, &position);
- str = NULL;
- if (Z_TYPE(key) == IS_STRING) {
- str_len = asprintf(&str, "%.*s%s%s%s", (int)watch->parent->str_len, watch->parent->str, Z_TYPE_P(watch->parent->addr.zv) == IS_ARRAY?"[":"->", phpdbg_get_property_key(Z_STRVAL(key)), Z_TYPE_P(watch->parent->addr.zv) == IS_ARRAY?"]":"");
- } else {
- str_len = asprintf(&str, "%.*s%s%li%s", (int)watch->parent->str_len, watch->parent->str, Z_TYPE_P(watch->parent->addr.zv) == IS_ARRAY?"[":"->", Z_LVAL(key), Z_TYPE_P(watch->parent->addr.zv) == IS_ARRAY?"]":"");
- }
+static void phpdbg_delete_implicit_parents(phpdbg_watchpoint_t *watch) {
+ phpdbg_watchpoint_t *parent = watch->parent;
+ if (!parent) {
+ return;
+ }
- if (zend_hash_find(&PHPDBG_G(watchpoints), str, str_len, (void **) &watchpoint) == SUCCESS) {
- phpdbg_delete_watchpoint_recursive(*watchpoint, 1 TSRMLS_CC);
- }
- }
+ ZEND_ASSERT(!(parent->flags & PHPDBG_WATCH_RECURSIVE));
+ ZEND_ASSERT(parent->flags & PHPDBG_WATCH_IMPLICIT);
+
+ if (parent->type == WATCH_ON_HASHTABLE && --parent->implicit_ht_count) {
+ return;
+ }
+
+ parent->flags &= ~PHPDBG_WATCH_IMPLICIT;
+ if (!(parent->flags & PHPDBG_WATCH_SIMPLE)) {
+ if (parent->type == WATCH_ON_ZVAL && Z_REFCOUNTED_P(watch->addr.zv)) {
+ phpdbg_remove_watch_collision(parent);
+ }
+ zend_hash_del(&PHPDBG_G(watchpoints), parent->str);
+ }
+}
+
+/* delete watchpoint, recursively (and inclusively) */
+static int phpdbg_delete_watchpoint_recursive(phpdbg_watchpoint_t *watch, zend_bool user_request) {
+ if (watch->type == WATCH_ON_HASHTABLE) {
+ if (user_request) {
+ phpdbg_delete_ht_watchpoints_recursive(watch);
} else {
- switch (Z_TYPE_P(watch->addr.zv)) {
- case IS_ARRAY:
- ht = Z_ARRVAL_P(watch->addr.zv);
- break;
- case IS_OBJECT:
- ht = Z_OBJPROP_P(watch->addr.zv);
- break;
- }
+ HashTable *ht;
+ phpdbg_btree_result *result;
+
+ ht = HT_FROM_ZVP(watch->addr.zv);
if ((result = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong) ht))) {
- phpdbg_delete_watchpoint_recursive((phpdbg_watchpoint_t *) result->ptr, user_request TSRMLS_CC);
+ phpdbg_delete_watchpoint_recursive((phpdbg_watchpoint_t *) result->ptr, user_request);
}
}
+ } else if (watch->type == WATCH_ON_ZVAL) {
+ phpdbg_delete_zval_watchpoints_recursive(watch);
+ }
+
+ return zend_hash_del(&PHPDBG_G(watchpoints), watch->str);
+}
+
+static void phpdbg_delete_ht_watchpoints_recursive(phpdbg_watchpoint_t *watch) {
+ zend_string *str, *strkey;
+ zend_long numkey;
+ phpdbg_watchpoint_t *watchpoint;
+
+ ZEND_HASH_FOREACH_KEY(HT_WATCH_HT(watch), numkey, strkey) {
+ if (strkey) {
+ str = strpprintf(0, "%.*s%s%s%s", (int) ZSTR_LEN(watch->str), ZSTR_VAL(watch->str), (watch->flags & PHPDBG_WATCH_ARRAY) ? "[" : "->", phpdbg_get_property_key(ZSTR_VAL(strkey)), (watch->flags & PHPDBG_WATCH_ARRAY) ? "]" : "");
+ } else {
+ str = strpprintf(0, "%.*s%s" ZEND_LONG_FMT "%s", (int) ZSTR_LEN(watch->str), ZSTR_VAL(watch->str), (watch->flags & PHPDBG_WATCH_ARRAY) ? "[" : "->", numkey, (watch->flags & PHPDBG_WATCH_ARRAY) ? "]" : "");
+ }
+
+ if ((watchpoint = zend_hash_find_ptr(&PHPDBG_G(watchpoints), str))) {
+ phpdbg_delete_watchpoint_recursive(watchpoint, 1);
+ }
+
+ zend_string_release(str);
+ } ZEND_HASH_FOREACH_END();
+}
+
+static void phpdbg_delete_zval_watchpoints_recursive(phpdbg_watchpoint_t *watch) {
+ if (Z_REFCOUNTED_P(watch->addr.zv)) {
+ phpdbg_remove_watch_collision(watch);
}
+}
- return zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len);
+/* delete watchpoints recusively (exclusively!) */
+static void phpdbg_delete_watchpoints_recursive(phpdbg_watchpoint_t *watch) {
+ if (watch->type == WATCH_ON_ZVAL) {
+ phpdbg_delete_zval_watchpoints_recursive(watch);
+ } else if (watch->type == WATCH_ON_HASHTABLE) {
+ phpdbg_delete_ht_watchpoints_recursive(watch);
+ }
}
-static int phpdbg_delete_watchpoint(phpdbg_watchpoint_t *tmp_watch TSRMLS_DC) {
+static int phpdbg_delete_watchpoint(phpdbg_watchpoint_t *tmp_watch) {
int ret;
phpdbg_watchpoint_t *watch;
phpdbg_btree_result *result;
- if ((result = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong)tmp_watch->addr.ptr)) == NULL) {
+ if ((result = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong) tmp_watch->addr.ptr)) == NULL) {
return FAILURE;
}
watch = result->ptr;
+ if (!(watch->flags & PHPDBG_WATCH_NORMAL) || (watch->parent && (watch->parent->flags & PHPDBG_WATCH_RECURSIVE))) {
+ return FAILURE; /* TODO: better error message for recursive (??) */
+ }
+
if (watch->flags & PHPDBG_WATCH_RECURSIVE) {
- ret = phpdbg_delete_watchpoint_recursive(watch, 1 TSRMLS_CC);
+ ret = phpdbg_delete_watchpoint_recursive(watch, 1);
} else {
- ret = zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len);
+ ret = zend_hash_del(&PHPDBG_G(watchpoints), watch->str);
}
- free(tmp_watch->str);
+ phpdbg_free_watch(tmp_watch);
efree(tmp_watch);
return ret;
}
-static int phpdbg_watchpoint_parse_input(char *input, size_t len, HashTable *parent, size_t i, int (*callback)(phpdbg_watchpoint_t * TSRMLS_DC), zend_bool silent TSRMLS_DC) {
- int ret = FAILURE;
- zend_bool new_index = 1;
- char *last_index;
- int index_len = 0;
- zval **zv;
+static int phpdbg_watchpoint_parse_wrapper(char *name, size_t namelen, char *key, size_t keylen, HashTable *parent, zval *zv, int (*callback)(phpdbg_watchpoint_t *)) {
+ int ret;
+ phpdbg_watchpoint_t *watch = ecalloc(1, sizeof(phpdbg_watchpoint_t));
+ watch->str = zend_string_init(name, namelen, 0);
+ watch->name_in_parent = zend_string_init(key, keylen, 0);
+ watch->parent_container = parent;
+ phpdbg_create_zval_watchpoint(zv, watch);
- if (len < 2 || *input != '$') {
- goto error;
+ ret = callback(watch);
+
+ efree(name);
+ efree(key);
+
+ if (ret != SUCCESS) {
+ phpdbg_free_watch(watch);
+ efree(watch);
}
- while (i++ < len) {
- if (i == len) {
- new_index = 1;
- } else {
- switch (input[i]) {
- case '[':
- new_index = 1;
- break;
- case ']':
- break;
- case '>':
- if (last_index[index_len - 1] == '-') {
- new_index = 1;
- index_len--;
- }
- break;
+ PHPDBG_G(watch_tmp) = NULL;
- default:
- if (new_index) {
- last_index = input + i;
- new_index = 0;
- }
- if (input[i - 1] == ']') {
- goto error;
- }
- index_len++;
- }
- }
+ return ret;
+}
- if (new_index && index_len == 0) {
- HashPosition position;
- for (zend_hash_internal_pointer_reset_ex(parent, &position);
- zend_hash_get_current_data_ex(parent, (void **)&zv, &position) == SUCCESS;
- zend_hash_move_forward_ex(parent, &position)) {
- if (i == len || (i == len - 1 && input[len - 1] == ']')) {
- zval *key = emalloc(sizeof(zval));
- phpdbg_watchpoint_t *watch = emalloc(sizeof(phpdbg_watchpoint_t));
- watch->flags = 0;
- zend_hash_get_current_key_zval_ex(parent, key, &position);
- convert_to_string(key);
- watch->str = malloc(i + Z_STRLEN_P(key) + 2);
- watch->str_len = sprintf(watch->str, "%.*s%s%s", (int)i, input, phpdbg_get_property_key(Z_STRVAL_P(key)), input[len - 1] == ']'?"]":"");
- efree(key);
- watch->name_in_parent = zend_strndup(last_index, index_len);
- watch->name_in_parent_len = index_len;
- watch->parent_container = parent;
- phpdbg_create_zval_watchpoint(*zv, watch);
-
- ret = callback(watch TSRMLS_CC) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE;
- } else if (Z_TYPE_PP(zv) == IS_OBJECT) {
- phpdbg_watchpoint_parse_input(input, len, Z_OBJPROP_PP(zv), i, callback, silent TSRMLS_CC);
- } else if (Z_TYPE_PP(zv) == IS_ARRAY) {
- phpdbg_watchpoint_parse_input(input, len, Z_ARRVAL_PP(zv), i, callback, silent TSRMLS_CC);
- } else {
- /* Ignore silently */
- }
- }
- return ret;
- } else if (new_index) {
- char last_chr = last_index[index_len];
- last_index[index_len] = 0;
- if (zend_symtable_find(parent, last_index, index_len + 1, (void **)&zv) == FAILURE) {
- if (!silent) {
- phpdbg_error("%.*s is undefined", (int)i, input);
- }
- return FAILURE;
- }
- last_index[index_len] = last_chr;
- if (i == len) {
- phpdbg_watchpoint_t *watch = emalloc(sizeof(phpdbg_watchpoint_t));
- watch->flags = 0;
- watch->str = zend_strndup(input, len);
- watch->str_len = len;
- watch->name_in_parent = zend_strndup(last_index, index_len);
- watch->name_in_parent_len = index_len;
- watch->parent_container = parent;
- phpdbg_create_zval_watchpoint(*zv, watch);
-
- ret = callback(watch TSRMLS_CC) == SUCCESS || ret == SUCCESS?SUCCESS:FAILURE;
- } else if (Z_TYPE_PP(zv) == IS_OBJECT) {
- parent = Z_OBJPROP_PP(zv);
- } else if (Z_TYPE_PP(zv) == IS_ARRAY) {
- parent = Z_ARRVAL_PP(zv);
- } else {
- phpdbg_error("%.*s is nor an array nor an object", (int)i, input);
- return FAILURE;
- }
- index_len = 0;
- }
+PHPDBG_API int phpdbg_watchpoint_parse_input(char *input, size_t len, HashTable *parent, size_t i, int (*callback)(phpdbg_watchpoint_t *), zend_bool silent) {
+ return phpdbg_parse_variable_with_arg(input, len, parent, i, (phpdbg_parse_var_with_arg_func) phpdbg_watchpoint_parse_wrapper, NULL, 0, callback);
+}
+
+static int phpdbg_watchpoint_parse_step(char *name, size_t namelen, char *key, size_t keylen, HashTable *parent, zval *zv, int (*callback)(phpdbg_watchpoint_t *)) {
+ phpdbg_watchpoint_t *watch;
+
+ if ((watch = zend_hash_str_find_ptr(&PHPDBG_G(watchpoints), name, namelen))) {
+ watch->flags |= PHPDBG_WATCH_IMPLICIT;
+ PHPDBG_G(watch_tmp) = watch;
+ return SUCCESS;
}
- return ret;
- error:
- phpdbg_error("Malformed input");
- return FAILURE;
+ watch = ecalloc(1, sizeof(phpdbg_watchpoint_t));
+ watch->flags = PHPDBG_WATCH_IMPLICIT;
+ watch->str = zend_string_init(name, namelen, 0);
+ watch->name_in_parent = zend_string_init(key, keylen, 0);
+ watch->parent_container = parent;
+ watch->parent = PHPDBG_G(watch_tmp);
+ phpdbg_create_zval_watchpoint(zv, watch);
+
+ phpdbg_create_watchpoint(watch);
+
+ efree(name);
+ efree(key);
+
+ PHPDBG_G(watch_tmp) = watch;
+ return SUCCESS;
}
-static int phpdbg_watchpoint_parse_symtables(char *input, size_t len, int (*callback)(phpdbg_watchpoint_t * TSRMLS_DC) TSRMLS_DC) {
- if (EG(This) && len >= 5 && !memcmp("$this", input, 5)) {
- zend_hash_add(EG(active_symbol_table), "this", sizeof("this"), &EG(This), sizeof(zval *), NULL);
+static int phpdbg_watchpoint_parse_symtables(char *input, size_t len, int (*callback)(phpdbg_watchpoint_t *)) {
+ if (EG(scope) && len >= 5 && !memcmp("$this", input, 5)) {
+ zend_hash_str_add(EG(current_execute_data)->symbol_table, ZEND_STRL("this"), &EG(current_execute_data)->This);
}
- if (zend_is_auto_global(input, len TSRMLS_CC) && phpdbg_watchpoint_parse_input(input, len, &EG(symbol_table), 0, callback, 1 TSRMLS_CC) != FAILURE) {
+ if (phpdbg_is_auto_global(input, len) && phpdbg_watchpoint_parse_input(input, len, &EG(symbol_table), 0, callback, 1) != FAILURE) {
return SUCCESS;
}
- return phpdbg_watchpoint_parse_input(input, len, EG(active_symbol_table), 0, callback, 0 TSRMLS_CC);
+ return phpdbg_parse_variable_with_arg(input, len, EG(current_execute_data)->symbol_table, 0, (phpdbg_parse_var_with_arg_func) phpdbg_watchpoint_parse_wrapper, (phpdbg_parse_var_with_arg_func) phpdbg_watchpoint_parse_step, 0, callback);
}
PHPDBG_WATCH(delete) /* {{{ */
{
switch (param->type) {
case STR_PARAM:
- if (phpdbg_delete_var_watchpoint(param->str, param->len TSRMLS_CC) == FAILURE) {
- phpdbg_error("Nothing was deleted, no corresponding watchpoint found");
+ if (phpdbg_delete_var_watchpoint(param->str, param->len) == FAILURE) {
+ phpdbg_error("watchdelete", "type=\"nowatch\"", "Nothing was deleted, no corresponding watchpoint found");
} else {
- phpdbg_notice("Removed watchpoint %.*s", (int)param->len, param->str);
+ phpdbg_notice("watchdelete", "variable=\"%.*s\"", "Removed watchpoint %.*s", (int) param->len, param->str);
}
break;
@@ -426,14 +710,14 @@ PHPDBG_WATCH(delete) /* {{{ */
PHPDBG_WATCH(recursive) /* {{{ */
{
- if (phpdbg_rebuild_symtable(TSRMLS_C) == FAILURE) {
+ if (phpdbg_rebuild_symtable() == FAILURE) {
return SUCCESS;
}
switch (param->type) {
case STR_PARAM:
- if (phpdbg_watchpoint_parse_symtables(param->str, param->len, phpdbg_create_recursive_watchpoint TSRMLS_CC) != FAILURE) {
- phpdbg_notice("Set recursive watchpoint on %.*s", (int)param->len, param->str);
+ if (phpdbg_watchpoint_parse_symtables(param->str, param->len, phpdbg_create_recursive_watchpoint) != FAILURE) {
+ phpdbg_notice("watchrecursive", "variable=\"%.*s\"", "Set recursive watchpoint on %.*s", (int)param->len, param->str);
}
break;
@@ -445,14 +729,14 @@ PHPDBG_WATCH(recursive) /* {{{ */
PHPDBG_WATCH(array) /* {{{ */
{
- if (phpdbg_rebuild_symtable(TSRMLS_C) == FAILURE) {
+ if (phpdbg_rebuild_symtable() == FAILURE) {
return SUCCESS;
}
switch (param->type) {
case STR_PARAM:
- if (phpdbg_watchpoint_parse_symtables(param->str, param->len, phpdbg_create_array_watchpoint TSRMLS_CC) != FAILURE) {
- phpdbg_notice("Set array watchpoint on %.*s", (int)param->len, param->str);
+ if (phpdbg_watchpoint_parse_symtables(param->str, param->len, phpdbg_create_array_watchpoint) != FAILURE) {
+ phpdbg_notice("watcharray", "variable=\"%.*s\"", "Set array watchpoint on %.*s", (int)param->len, param->str);
}
break;
@@ -462,48 +746,65 @@ PHPDBG_WATCH(array) /* {{{ */
return SUCCESS;
} /* }}} */
-void phpdbg_watch_HashTable_dtor(zval **zv) {
+void phpdbg_watch_HashTable_dtor(zval *zv) {
phpdbg_btree_result *result;
- TSRMLS_FETCH();
+ zval *orig_zv = zv;
- zval_ptr_dtor_wrapper(zv);
+ while (Z_TYPE_P(zv) == IS_INDIRECT) {
+ zv = Z_INDIRECT_P(zv);
+ }
- if ((result = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong)*zv))) {
+ if ((result = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong) zv))) {
phpdbg_watchpoint_t *watch = result->ptr;
- PHPDBG_G(watchpoint_hit) = 1;
+ if (watch->flags & PHPDBG_WATCH_NORMAL) {
+ PHPDBG_G(watchpoint_hit) = 1;
- phpdbg_notice("%.*s was removed, removing watchpoint%s", (int)watch->str_len, watch->str, (watch->flags & PHPDBG_WATCH_RECURSIVE)?" recursively":"");
+ phpdbg_notice("watchdelete", "variable=\"%.*s\" recursive=\"%s\"", "%.*s was removed, removing watchpoint%s", (int) ZSTR_LEN(watch->str), ZSTR_VAL(watch->str), (watch->flags & PHPDBG_WATCH_RECURSIVE) ? " recursively" : "");
+ }
+
+ if ((result = phpdbg_btree_find(&PHPDBG_G(watch_HashTables), (zend_ulong) watch->parent_container))) {
+ phpdbg_watch_ht_info *hti = result->ptr;
+ hti->dtor(orig_zv);
+ zend_hash_del(&hti->watches, watch->name_in_parent);
+ if (zend_hash_num_elements(&hti->watches) == 0) {
+ watch->parent_container->pDestructor = hti->dtor;
+ zend_hash_destroy(&hti->watches);
+ phpdbg_btree_delete(&PHPDBG_G(watch_HashTables), (zend_ulong) watch->parent_container);
+ efree(hti);
+ }
+ } else {
+ zval_ptr_dtor_wrapper(orig_zv);
+ }
if (watch->flags & PHPDBG_WATCH_RECURSIVE) {
- phpdbg_delete_watchpoint_recursive(watch, 0 TSRMLS_CC);
+ phpdbg_delete_watchpoint_recursive(watch, 0);
} else {
- zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len);
+ zend_hash_del(&PHPDBG_G(watchpoints), watch->str);
}
}
}
-
-int phpdbg_create_var_watchpoint(char *input, size_t len TSRMLS_DC) {
- if (phpdbg_rebuild_symtable(TSRMLS_C) == FAILURE) {
+int phpdbg_create_var_watchpoint(char *input, size_t len) {
+ if (phpdbg_rebuild_symtable() == FAILURE) {
return FAILURE;
}
- return phpdbg_watchpoint_parse_symtables(input, len, phpdbg_create_watchpoint TSRMLS_CC);
+ return phpdbg_watchpoint_parse_symtables(input, len, phpdbg_create_simple_watchpoint);
}
-int phpdbg_delete_var_watchpoint(char *input, size_t len TSRMLS_DC) {
- if (phpdbg_rebuild_symtable(TSRMLS_C) == FAILURE) {
+int phpdbg_delete_var_watchpoint(char *input, size_t len) {
+ if (phpdbg_rebuild_symtable() == FAILURE) {
return FAILURE;
}
- return phpdbg_watchpoint_parse_symtables(input, len, phpdbg_delete_watchpoint TSRMLS_CC);
+ return phpdbg_watchpoint_parse_input(input, len, EG(current_execute_data)->symbol_table, 0, phpdbg_delete_watchpoint, 0);
}
#ifdef _WIN32
-int phpdbg_watchpoint_segfault_handler(void *addr TSRMLS_DC) {
+int phpdbg_watchpoint_segfault_handler(void *addr) {
#else
-int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC) {
+int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context) {
#endif
void *page;
phpdbg_watch_memdump *dump;
@@ -516,7 +817,7 @@ int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC)
#else
info->si_addr
#endif
- TSRMLS_CC);
+ );
if (watch == NULL) {
return FAILURE;
@@ -531,6 +832,7 @@ int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC)
dump = malloc(MEMDUMP_SIZE(size));
dump->page = page;
dump->size = size;
+ dump->reenable_writing = 0;
memcpy(&dump->data, page, size);
@@ -539,34 +841,55 @@ int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC)
return SUCCESS;
}
-void phpdbg_watchpoints_clean(TSRMLS_D) {
+void phpdbg_watchpoints_clean(void) {
zend_hash_clean(&PHPDBG_G(watchpoints));
}
-static void phpdbg_watch_dtor(void *pDest) {
- phpdbg_watchpoint_t *watch = *(phpdbg_watchpoint_t **)pDest;
- TSRMLS_FETCH();
+/* due to implicit delete... MUST BE DESTROYED MANUALLY */
+static void phpdbg_watch_dtor(zval *pDest) {
+ phpdbg_watchpoint_t *watch = (phpdbg_watchpoint_t *) Z_PTR_P(pDest);
- phpdbg_deactivate_watchpoint(watch TSRMLS_CC);
- phpdbg_remove_watchpoint(watch TSRMLS_CC);
+ if (watch->flags & PHPDBG_WATCH_IMPLICIT) {
+ watch->flags = PHPDBG_WATCH_SIMPLE; // tiny hack for delete_implicit_parents
- free(watch->str);
- free(watch->name_in_parent);
+ if (watch->type == WATCH_ON_ZVAL) {
+ phpdbg_delete_zval_watchpoints_recursive(watch);
+ } else if (watch->type == WATCH_ON_HASHTABLE) {
+ phpdbg_watchpoint_t *watchpoint;
+
+ watch->implicit_ht_count++;
+
+ ZEND_HASH_FOREACH_PTR(&((phpdbg_watch_ht_info *) phpdbg_btree_find(&PHPDBG_G(watch_HashTables), (zend_ulong) HT_WATCH_HT(watch))->ptr)->watches, watchpoint) {
+ phpdbg_delete_watchpoint_recursive(watchpoint, 1);
+ } ZEND_HASH_FOREACH_END();
+ }
+ }
+
+ phpdbg_delete_implicit_parents(watch);
+
+ phpdbg_deactivate_watchpoint(watch);
+ phpdbg_remove_watchpoint(watch);
+
+ phpdbg_free_watch(watch);
efree(watch);
}
static void phpdbg_watch_mem_dtor(void *llist_data) {
- phpdbg_watch_memdump *dump = *(phpdbg_watch_memdump **)llist_data;
+ phpdbg_watch_memdump *dump = *(phpdbg_watch_memdump **) llist_data;
/* Disble writing again */
if (dump->reenable_writing) {
mprotect(dump->page, dump->size, PROT_READ);
}
- free(*(void **)llist_data);
+ free(dump);
}
-void phpdbg_setup_watchpoints(TSRMLS_D) {
+static void phpdbg_watch_free_ptr_dtor(zval *ptr) {
+ efree(Z_PTR_P(ptr));
+}
+
+void phpdbg_setup_watchpoints(void) {
#if _SC_PAGE_SIZE
phpdbg_pagesize = sysconf(_SC_PAGE_SIZE);
#elif _SC_PAGESIZE
@@ -580,164 +903,199 @@ void phpdbg_setup_watchpoints(TSRMLS_D) {
zend_llist_init(&PHPDBG_G(watchlist_mem), sizeof(void *), phpdbg_watch_mem_dtor, 1);
phpdbg_btree_init(&PHPDBG_G(watchpoint_tree), sizeof(void *) * 8);
phpdbg_btree_init(&PHPDBG_G(watch_HashTables), sizeof(void *) * 8);
- zend_hash_init(&PHPDBG_G(watchpoints), 8, NULL, phpdbg_watch_dtor, 0 ZEND_FILE_LINE_CC);
+ zend_hash_init(&PHPDBG_G(watchpoints), 8, NULL, phpdbg_watch_dtor, 0);
+ zend_hash_init(&PHPDBG_G(watch_collisions), 8, NULL, phpdbg_watch_free_ptr_dtor, 0);
}
-static void phpdbg_print_changed_zval(phpdbg_watch_memdump *dump TSRMLS_DC) {
+static void phpdbg_print_changed_zval(phpdbg_watch_memdump *dump) {
/* fetch all changes between dump->page and dump->page + dump->size */
- phpdbg_btree_position pos = phpdbg_btree_find_between(&PHPDBG_G(watchpoint_tree), (zend_ulong)dump->page, (zend_ulong)dump->page + dump->size);
- phpdbg_btree_result *result, *htresult;
+ phpdbg_btree_position pos = phpdbg_btree_find_between(&PHPDBG_G(watchpoint_tree), (zend_ulong) dump->page, (zend_ulong) dump->page + dump->size);
+ phpdbg_btree_result *result;
int elementDiff;
void *curTest;
dump->reenable_writing = 0;
while ((result = phpdbg_btree_next(&pos))) {
- phpdbg_watchpoint_t *watch = result->ptr, *htwatch;
- void *oldPtr = (char *)&dump->data + ((size_t)watch->addr.ptr - (size_t)dump->page);
+ phpdbg_watchpoint_t *watch = result->ptr;
+ void *oldPtr = (char *) &dump->data + ((size_t) watch->addr.ptr - (size_t) dump->page);
char reenable = 1;
+ int removed = 0;
- if ((size_t)watch->addr.ptr < (size_t)dump->page || (size_t)watch->addr.ptr + watch->size > (size_t)dump->page + dump->size) {
+ if ((size_t) watch->addr.ptr < (size_t) dump->page || (size_t) watch->addr.ptr + watch->size > (size_t) dump->page + dump->size) {
continue;
}
- /* Test if the zval was separated and if necessary move the watchpoint */
- if (zend_hash_find(watch->parent_container, watch->name_in_parent, watch->name_in_parent_len + 1, &curTest) == SUCCESS) {
- if (watch->type == WATCH_ON_HASHTABLE) {
- switch (Z_TYPE_PP((zval **)curTest)) {
- case IS_ARRAY:
- curTest = (void *)Z_ARRVAL_PP((zval **)curTest);
- break;
- case IS_OBJECT:
- curTest = (void *)Z_OBJPROP_PP((zval **)curTest);
- break;
+ /* Test if the zval was separated or replaced and if necessary move the watchpoint */
+ if ((watch->type == WATCH_ON_HASHTABLE || watch->type == WATCH_ON_ZVAL) && watch->parent_container) {
+ if ((curTest = zend_symtable_find(watch->parent_container, watch->name_in_parent))) {
+ while (Z_TYPE_P((zval *) curTest) == IS_INDIRECT) {
+ curTest = Z_INDIRECT_P((zval *) curTest);
+ }
+
+ if (watch->type == WATCH_ON_HASHTABLE) {
+ switch (Z_TYPE_P((zval *) curTest)) {
+ case IS_ARRAY:
+ curTest = (void *) Z_ARRVAL_P((zval *) curTest);
+ break;
+ case IS_OBJECT:
+ curTest = (void *) Z_OBJPROP_P((zval *) curTest);
+ break;
+ }
}
- } else {
- curTest = *(void **)curTest;
- }
- if (curTest != watch->addr.ptr) {
- phpdbg_deactivate_watchpoint(watch TSRMLS_CC);
- phpdbg_remove_watchpoint(watch TSRMLS_CC);
- watch->addr.ptr = curTest;
- phpdbg_store_watchpoint(watch TSRMLS_CC);
- phpdbg_activate_watchpoint(watch TSRMLS_CC);
+ if (curTest != watch->addr.ptr) {
+ phpdbg_deactivate_watchpoint(watch);
+ phpdbg_remove_watchpoint(watch);
+ watch->addr.ptr = curTest;
+ phpdbg_store_watchpoint(watch);
+ phpdbg_activate_watchpoint(watch);
- reenable = 0;
+ reenable = 0;
+ }
+ } else {
+ removed = 1;
}
}
/* Show to the user what changed and delete watchpoint upon removal */
- if (memcmp(oldPtr, watch->addr.ptr, watch->size) != SUCCESS) {
- if (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS || (watch->type == WATCH_ON_ZVAL && memcmp(oldPtr, watch->addr.zv, sizeof(zvalue_value))) || (watch->type == WATCH_ON_HASHTABLE
-#if ZEND_DEBUG
- && !watch->addr.ht->inconsistent
-#endif
- && zend_hash_num_elements((HashTable *)oldPtr) != zend_hash_num_elements(watch->addr.ht))) {
+ {
+ zend_bool do_break = 0;
+
+ switch (watch->type) {
+ case WATCH_ON_ZVAL:
+ do_break = memcmp(oldPtr, watch->addr.zv, sizeof(zend_value) + sizeof(uint32_t) /* value + typeinfo */) != 0;
+ if (!do_break) {
+ goto end;
+ }
+ break;
+ case WATCH_ON_HASHTABLE:
+ do_break = zend_hash_num_elements(HT_PTR_HT(oldPtr)) != zend_hash_num_elements(HT_WATCH_HT(watch));
+ if (!do_break) {
+ goto end;
+ }
+ break;
+ case WATCH_ON_REFCOUNTED:
+ do_break = memcmp(oldPtr, watch->addr.ref, sizeof(uint32_t) /* no zend_refcounted metadata info */) != 0;
+ if (!do_break) {
+ goto end;
+ }
+ if (!(PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS)) {
+ do_break = 0;
+ }
+ break;
+ }
+
+ if (!(watch->flags & PHPDBG_WATCH_NORMAL)) {
+ do_break = 0;
+ }
+
+ if (do_break) {
PHPDBG_G(watchpoint_hit) = 1;
- phpdbg_notice("Breaking on watchpoint %s", watch->str);
+ phpdbg_notice("watchhit", "variable=\"%s\"", "Breaking on watchpoint %.*s", (int) ZSTR_LEN(watch->str), ZSTR_VAL(watch->str));
+ phpdbg_xml("<watchdata %r>");
}
switch (watch->type) {
case WATCH_ON_ZVAL: {
- int removed = ((zval *)oldPtr)->refcount__gc != watch->addr.zv->refcount__gc && !zend_symtable_exists(watch->parent_container, watch->name_in_parent, watch->name_in_parent_len + 1);
- int show_value = memcmp(oldPtr, watch->addr.zv, sizeof(zvalue_value));
- int show_ref = ((zval *)oldPtr)->refcount__gc != watch->addr.zv->refcount__gc || ((zval *)oldPtr)->is_ref__gc != watch->addr.zv->is_ref__gc;
-
- if (removed || show_value) {
- phpdbg_write("Old value: ");
- if ((Z_TYPE_P((zval *)oldPtr) == IS_ARRAY || Z_TYPE_P((zval *)oldPtr) == IS_OBJECT) && removed) {
- phpdbg_writeln("Value inaccessible, HashTable already destroyed");
+ zend_bool show_value = memcmp(oldPtr, watch->addr.zv, sizeof(zend_value) + sizeof(uint32_t) /* no metadata info */) != 0;
+
+ if ((watch->flags & PHPDBG_WATCH_NORMAL) && (removed || show_value)) {
+/* TODO: Merge with refcounting watches, store if watched ref value is to be dropped etc. [for example: manually increment refcount transparently for displaying and drop it if it decrements to 1] */
+ if (Z_REFCOUNTED_P((zval *) oldPtr)) {
+ phpdbg_writeln("watchvalue", "type=\"old\" inaccessible=\"inaccessible\"", "Old value inaccessible or destroyed");
} else {
- zend_print_flat_zval_r((zval *)oldPtr TSRMLS_CC);
- phpdbg_writeln("");
+ phpdbg_out("Old value: ");
+ phpdbg_xml("<watchvalue %r type=\"old\">");
+ zend_print_flat_zval_r((zval *) oldPtr);
+ phpdbg_xml("</watchvalue>");
+ phpdbg_out("\n");
}
}
- if (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS && (removed || show_ref)) {
- phpdbg_writeln("Old refcount: %d; Old is_ref: %d", ((zval *)oldPtr)->refcount__gc, ((zval *)oldPtr)->is_ref__gc);
- }
/* check if zval was removed */
if (removed) {
- phpdbg_notice("Watchpoint %s was unset, removing watchpoint", watch->str);
- zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len);
+ if (watch->flags & PHPDBG_WATCH_NORMAL) {
+ phpdbg_notice("watchdelete", "variable=\"%.*s\"", "Watchpoint %.*s was unset, removing watchpoint", (int) ZSTR_LEN(watch->str), ZSTR_VAL(watch->str));
+ }
+ zend_hash_del(&PHPDBG_G(watchpoints), watch->str);
reenable = 0;
- if (Z_TYPE_P((zval *)oldPtr) == IS_ARRAY || Z_TYPE_P((zval *)oldPtr) == IS_OBJECT) {
- goto remove_ht_watch;
+ if (Z_REFCOUNTED_P((zval *) oldPtr)) {
+ phpdbg_remove_watch_collision(watch);
}
-
break;
}
- if (show_value) {
- phpdbg_write("New value: ");
- zend_print_flat_zval_r(watch->addr.zv TSRMLS_CC);
- phpdbg_writeln("");
- }
- if (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS && show_ref) {
- phpdbg_writeln("New refcount: %d; New is_ref: %d", watch->addr.zv->refcount__gc, watch->addr.zv->is_ref__gc);
+ if ((watch->flags & PHPDBG_WATCH_NORMAL) && show_value) {
+ phpdbg_out("New value%s: ", Z_ISREF_P(watch->addr.zv) ? " (reference)" : "");
+ phpdbg_xml("<watchvalue %r%s type=\"new\">", Z_ISREF_P(watch->addr.zv) ? " reference=\"reference\"" : "");
+ zend_print_flat_zval_r(watch->addr.zv);
+ phpdbg_xml("</watchvalue>");
+ phpdbg_out("\n");
}
- if ((Z_TYPE_P(watch->addr.zv) == IS_ARRAY && Z_ARRVAL_P(watch->addr.zv) != Z_ARRVAL_P((zval *)oldPtr)) || (Z_TYPE_P(watch->addr.zv) != IS_OBJECT && Z_OBJ_HANDLE_P(watch->addr.zv) == Z_OBJ_HANDLE_P((zval *)oldPtr))) {
- /* add new watchpoints if necessary */
- if (watch->flags & PHPDBG_WATCH_RECURSIVE) {
- phpdbg_create_recursive_watchpoint(watch TSRMLS_CC);
+ /* add new watchpoints if necessary */
+ if (Z_PTR_P(watch->addr.zv) != Z_PTR_P((zval *) oldPtr) || Z_TYPE_P(watch->addr.zv) != Z_TYPE_P((zval *) oldPtr)) {
+ if (Z_REFCOUNTED_P((zval *) oldPtr)) {
+ zval *new_zv = watch->addr.zv;
+ watch->addr.ptr = oldPtr;
+ phpdbg_remove_watch_collision(watch);
+ watch->addr.zv = new_zv;
+ }
+ if (Z_REFCOUNTED_P(watch->addr.zv)) {
+ if ((watch->flags & PHPDBG_WATCH_NORMAL) && (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS)) {
+ phpdbg_writeln("watchrefcount", "type=\"new\" refcount=\"%d\"", "New refcount: %d", Z_REFCOUNT_P(watch->addr.zv));
+ }
+ if (watch->flags & PHPDBG_WATCH_RECURSIVE) {
+ phpdbg_create_recursive_watchpoint(watch);
+ } else if (Z_ISREF_P(watch->addr.zv)) {
+ phpdbg_create_reference_watch(watch);
+ }
}
- }
-
- if ((Z_TYPE_P((zval *)oldPtr) != IS_ARRAY || Z_ARRVAL_P(watch->addr.zv) == Z_ARRVAL_P((zval *)oldPtr)) && (Z_TYPE_P((zval *)oldPtr) != IS_OBJECT || Z_OBJ_HANDLE_P(watch->addr.zv) == Z_OBJ_HANDLE_P((zval *)oldPtr))) {
- break;
- }
-
-remove_ht_watch:
- if ((htresult = phpdbg_btree_find(&PHPDBG_G(watchpoint_tree), (zend_ulong)Z_ARRVAL_P((zval *)oldPtr)))) {
- htwatch = htresult->ptr;
- zend_hash_del(&PHPDBG_G(watchpoints), htwatch->str, htwatch->str_len);
}
break;
}
case WATCH_ON_HASHTABLE:
-
-#if ZEND_DEBUG
- if (watch->addr.ht->inconsistent) {
- phpdbg_notice("Watchpoint %s was unset, removing watchpoint", watch->str);
- zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len);
-
- reenable = 0;
-
- break;
- }
-#endif
-
- elementDiff = zend_hash_num_elements((HashTable *)oldPtr) - zend_hash_num_elements(watch->addr.ht);
- if (elementDiff) {
+ /* We should be safely able to assume the HashTable to be consistent (inconsistent HashTables should have been caught by phpdbg_watch_efree() */
+ elementDiff = zend_hash_num_elements(HT_PTR_HT(oldPtr)) - zend_hash_num_elements(HT_WATCH_HT(watch));
+ if ((watch->flags & PHPDBG_WATCH_NORMAL) && elementDiff) {
if (elementDiff > 0) {
- phpdbg_writeln("%d elements were removed from the array", elementDiff);
+ phpdbg_writeln("watchsize", "removed=\"%d\"", "%d elements were removed from the array", elementDiff);
} else {
- phpdbg_writeln("%d elements were added to the array", -elementDiff);
-
- /* add new watchpoints if necessary */
- if (watch->flags & PHPDBG_WATCH_RECURSIVE) {
- phpdbg_create_recursive_watchpoint(watch TSRMLS_CC);
- }
+ phpdbg_writeln("watchsize", "added=\"%d\"", "%d elements were added to the array", -elementDiff);
}
}
- if (((HashTable *)oldPtr)->pInternalPointer != watch->addr.ht->pInternalPointer) {
- phpdbg_writeln("Internal pointer of array was changed");
+ /* add new watchpoints if necessary */
+ if (watch->flags & PHPDBG_WATCH_RECURSIVE) {
+ phpdbg_create_recursive_ht_watch(watch);
+ }
+ if ((watch->flags & PHPDBG_WATCH_NORMAL) && HT_WATCH_HT(watch)->nInternalPointer != HT_PTR_HT(oldPtr)->nInternalPointer) {
+ phpdbg_writeln("watcharrayptr", "", "Internal pointer of array was changed");
}
break;
+ case WATCH_ON_REFCOUNTED: {
+ if ((watch->flags & PHPDBG_WATCH_NORMAL) && (PHPDBG_G(flags) & PHPDBG_SHOW_REFCOUNTS)) {
+ phpdbg_writeln("watchrefcount", "type=\"old\" refcount=\"%d\"", "Old refcount: %d", GC_REFCOUNT((zend_refcounted *) oldPtr));
+ phpdbg_writeln("watchrefcount", "type=\"new\" refcount=\"%d\"", "New refcount: %d", GC_REFCOUNT(watch->addr.ref));
+ }
+ break;
+ }
}
- }
+
+ if (do_break) {
+ phpdbg_xml("</watchdata>");
+ }
+ } end:
dump->reenable_writing = dump->reenable_writing | reenable;
}
}
-int phpdbg_print_changed_zvals(TSRMLS_D) {
+int phpdbg_print_changed_zvals(void) {
zend_llist_position pos;
phpdbg_watch_memdump **dump;
int ret;
@@ -746,44 +1104,63 @@ int phpdbg_print_changed_zvals(TSRMLS_D) {
return FAILURE;
}
- dump = (phpdbg_watch_memdump **)zend_llist_get_last_ex(&PHPDBG_G(watchlist_mem), &pos);
+ dump = (phpdbg_watch_memdump **) zend_llist_get_last_ex(&PHPDBG_G(watchlist_mem), &pos);
do {
- phpdbg_print_changed_zval(*dump TSRMLS_CC);
- } while ((dump = (phpdbg_watch_memdump **)zend_llist_get_prev_ex(&PHPDBG_G(watchlist_mem), &pos)));
+ phpdbg_print_changed_zval(*dump);
+ } while ((dump = (phpdbg_watch_memdump **) zend_llist_get_prev_ex(&PHPDBG_G(watchlist_mem), &pos)));
zend_llist_clean(&PHPDBG_G(watchlist_mem));
- ret = PHPDBG_G(watchpoint_hit)?SUCCESS:FAILURE;
+ ret = PHPDBG_G(watchpoint_hit) ? SUCCESS : FAILURE;
PHPDBG_G(watchpoint_hit) = 0;
return ret;
}
-void phpdbg_list_watchpoints(TSRMLS_D) {
- HashPosition position;
- phpdbg_watchpoint_t **watch;
+void phpdbg_list_watchpoints(void) {
+ phpdbg_watchpoint_t *watch;
+
+ phpdbg_xml("<watchlist %r>");
- for (zend_hash_internal_pointer_reset_ex(&PHPDBG_G(watchpoints), &position);
- zend_hash_get_current_data_ex(&PHPDBG_G(watchpoints), (void**) &watch, &position) == SUCCESS;
- zend_hash_move_forward_ex(&PHPDBG_G(watchpoints), &position)) {
- phpdbg_writeln("%.*s", (int)(*watch)->str_len, (*watch)->str);
- }
+ ZEND_HASH_FOREACH_PTR(&PHPDBG_G(watchpoints), watch) {
+ if (watch->flags & PHPDBG_WATCH_NORMAL) {
+ phpdbg_writeln("watchvariable", "variable=\"%.*s\" on=\"%s\" type=\"%s\"", "%.*s (%s, %s)", (int) ZSTR_LEN(watch->str), ZSTR_VAL(watch->str), watch->type == WATCH_ON_HASHTABLE ? "array" : watch->type == WATCH_ON_REFCOUNTED ? "refcount" : "variable", watch->flags == PHPDBG_WATCH_RECURSIVE ? "recursive" : "simple");
+ }
+ } ZEND_HASH_FOREACH_END();
+
+ phpdbg_xml("</watchlist>");
}
void phpdbg_watch_efree(void *ptr) {
phpdbg_btree_result *result;
- TSRMLS_FETCH();
- result = phpdbg_btree_find_closest(&PHPDBG_G(watchpoint_tree), (zend_ulong)ptr);
+ result = phpdbg_btree_find_closest(&PHPDBG_G(watchpoint_tree), (zend_ulong) ptr);
if (result) {
phpdbg_watchpoint_t *watch = result->ptr;
- if ((size_t)watch->addr.ptr + watch->size > (size_t)ptr) {
- zend_hash_del(&PHPDBG_G(watchpoints), watch->str, watch->str_len);
+ if ((size_t) watch->addr.ptr + watch->size > (size_t) ptr) {
+ if (watch->type == WATCH_ON_REFCOUNTED) {
+ /* remove watchpoint here from btree, zval watchpoint will remove it via remove_watch_collison */
+ phpdbg_deactivate_watchpoint(watch);
+ phpdbg_remove_watchpoint(watch);
+ } else {
+ if (watch->type == WATCH_ON_ZVAL) {
+ phpdbg_remove_watch_collision(watch);
+ }
+ if (watch->type == WATCH_ON_HASHTABLE && (watch->flags & PHPDBG_WATCH_SIMPLE)) {
+ /* when a HashTable is freed, we can safely assume the other zvals all were dtor'ed */
+ phpdbg_notice("watchdelete", "variable=\"%.*s\" recursive=\"%s\"", "Array %.*s was removed, removing watchpoint%s", (int) ZSTR_LEN(watch->str), ZSTR_VAL(watch->str), (watch->flags & PHPDBG_WATCH_RECURSIVE) ? " recursively" : "");
+ }
+ if (watch->type == WATCH_ON_HASHTABLE || watch->parent == NULL || watch->parent->type != WATCH_ON_ZVAL) { /* no references */
+ zend_hash_del(&PHPDBG_G(watchpoints), watch->str);
+ }
+ }
}
}
- PHPDBG_G(original_free_function)(ptr);
+ if (PHPDBG_G(original_free_function)) {
+ PHPDBG_G(original_free_function)(ptr);
+ }
}
diff --git a/sapi/phpdbg/phpdbg_watch.h b/sapi/phpdbg/phpdbg_watch.h
index 0240a47265..ca56af8c3e 100644
--- a/sapi/phpdbg/phpdbg_watch.h
+++ b/sapi/phpdbg/phpdbg_watch.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -21,11 +21,10 @@
#ifndef PHPDBG_WATCH_H
#define PHPDBG_WATCH_H
-#include "TSRM.h"
#include "phpdbg_cmd.h"
#ifdef _WIN32
-# include "phpdbg_win.h"
+# include "phpdbg_win.h"
#endif
#define PHPDBG_WATCH(name) PHPDBG_COMMAND(watch_##name)
@@ -37,64 +36,75 @@ PHPDBG_WATCH(array);
PHPDBG_WATCH(delete);
PHPDBG_WATCH(recursive);
-/**
- * Commands
- */
-
-static const phpdbg_command_t phpdbg_watch_commands[] = {
- PHPDBG_COMMAND_D_EX(array, "create watchpoint on an array", 'a', watch_array, NULL, "s"),
- PHPDBG_COMMAND_D_EX(delete, "delete watchpoint", 'd', watch_delete, NULL, "s"),
- PHPDBG_COMMAND_D_EX(recursive, "create recursive watchpoints", 'r', watch_recursive, NULL, "s"),
- PHPDBG_END_COMMAND
-};
+extern const phpdbg_command_t phpdbg_watch_commands[];
/* Watchpoint functions/typedefs */
+/* References are managed through their parent zval *, being a simple WATCH_ON_ZVAL and eventually WATCH_ON_REFCOUNTED */
typedef enum {
WATCH_ON_ZVAL,
WATCH_ON_HASHTABLE,
+ WATCH_ON_REFCOUNTED,
} phpdbg_watchtype;
-#define PHPDBG_WATCH_SIMPLE 0x0
-#define PHPDBG_WATCH_RECURSIVE 0x1
+#define PHPDBG_WATCH_SIMPLE 0x01
+#define PHPDBG_WATCH_RECURSIVE 0x02
+#define PHPDBG_WATCH_ARRAY 0x04
+#define PHPDBG_WATCH_OBJECT 0x08
+#define PHPDBG_WATCH_NORMAL (PHPDBG_WATCH_SIMPLE | PHPDBG_WATCH_RECURSIVE)
+#define PHPDBG_WATCH_IMPLICIT 0x10
+
+#define PHPDBG_DESTRUCTED_ZVAL 0x80
typedef struct _phpdbg_watchpoint_t phpdbg_watchpoint_t;
struct _phpdbg_watchpoint_t {
- phpdbg_watchpoint_t *parent;
- HashTable *parent_container;
- char *name_in_parent;
- size_t name_in_parent_len;
- char *str;
- size_t str_len;
union {
zval *zv;
- HashTable *ht;
+ zend_refcounted *ref;
void *ptr;
} addr;
size_t size;
phpdbg_watchtype type;
char flags;
+ unsigned int implicit_ht_count;
+ phpdbg_watchpoint_t *parent;
+ phpdbg_watchpoint_t *reference;
+ HashTable *parent_container;
+ zend_string *name_in_parent;
+ zend_string *str;
};
-void phpdbg_setup_watchpoints(TSRMLS_D);
+typedef struct {
+ phpdbg_watchpoint_t *watch;
+ unsigned int refs;
+ HashTable watches;
+ HashTable implicit_watches;
+} phpdbg_watch_collision;
+
+typedef struct {
+ dtor_func_t dtor;
+ HashTable watches;
+} phpdbg_watch_ht_info;
+
+void phpdbg_setup_watchpoints(void);
#ifndef _WIN32
-int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context TSRMLS_DC);
+int phpdbg_watchpoint_segfault_handler(siginfo_t *info, void *context);
#else
-int phpdbg_watchpoint_segfault_handler(void *addr TSRMLS_DC);
+int phpdbg_watchpoint_segfault_handler(void *addr);
#endif
void phpdbg_create_addr_watchpoint(void *addr, size_t size, phpdbg_watchpoint_t *watch);
void phpdbg_create_zval_watchpoint(zval *zv, phpdbg_watchpoint_t *watch);
-int phpdbg_delete_var_watchpoint(char *input, size_t len TSRMLS_DC);
-int phpdbg_create_var_watchpoint(char *input, size_t len TSRMLS_DC);
+int phpdbg_delete_var_watchpoint(char *input, size_t len);
+int phpdbg_create_var_watchpoint(char *input, size_t len);
-int phpdbg_print_changed_zvals(TSRMLS_D);
+int phpdbg_print_changed_zvals(void);
-void phpdbg_list_watchpoints(TSRMLS_D);
+void phpdbg_list_watchpoints(void);
void phpdbg_watch_efree(void *ptr);
@@ -102,11 +112,11 @@ void phpdbg_watch_efree(void *ptr);
static long phpdbg_pagesize;
static zend_always_inline void *phpdbg_get_page_boundary(void *addr) {
- return (void *)((size_t)addr & ~(phpdbg_pagesize - 1));
+ return (void *) ((size_t) addr & ~(phpdbg_pagesize - 1));
}
static zend_always_inline size_t phpdbg_get_total_page_size(void *addr, size_t size) {
- return (size_t)phpdbg_get_page_boundary((void *)((size_t)addr + size - 1)) - (size_t)phpdbg_get_page_boundary(addr) + phpdbg_pagesize;
+ return (size_t) phpdbg_get_page_boundary((void *) ((size_t) addr + size - 1)) - (size_t) phpdbg_get_page_boundary(addr) + phpdbg_pagesize;
}
#endif
diff --git a/sapi/phpdbg/phpdbg_webdata_transfer.c b/sapi/phpdbg/phpdbg_webdata_transfer.c
new file mode 100644
index 0000000000..ddcf2deec2
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_webdata_transfer.c
@@ -0,0 +1,175 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Bob Weinand <bwoebi@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#include "phpdbg_webdata_transfer.h"
+#include "ext/standard/php_var.h"
+
+static int phpdbg_is_auto_global(char *name, int len) {
+ int ret;
+ zend_string *str = zend_string_init(name, len, 0);
+ ret = zend_is_auto_global(str);
+ efree(str);
+ return ret;
+}
+
+PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len) {
+ zval array;
+ HashTable *ht;
+ zval zv[9] = {{{0}}};
+
+ array_init(&array);
+ ht = Z_ARRVAL(array);
+
+ /* fetch superglobals */
+ {
+ phpdbg_is_auto_global(ZEND_STRL("GLOBALS"));
+ /* might be JIT */
+ phpdbg_is_auto_global(ZEND_STRL("_ENV"));
+ phpdbg_is_auto_global(ZEND_STRL("_SERVER"));
+ phpdbg_is_auto_global(ZEND_STRL("_REQUEST"));
+ array_init(&zv[1]);
+ zend_hash_copy(Z_ARRVAL(zv[1]), &EG(symbol_table), NULL);
+ Z_ARRVAL(zv[1])->pDestructor = NULL; /* we're operating on a copy! Don't double free zvals */
+ zend_hash_str_del(Z_ARRVAL(zv[1]), ZEND_STRL("GLOBALS")); /* do not use the reference to itself in json */
+ zend_hash_str_add(ht, ZEND_STRL("GLOBALS"), &zv[1]);
+ }
+
+ /* save php://input */
+ {
+ php_stream *stream;
+ zend_string *str;
+
+ stream = php_stream_temp_create_ex(TEMP_STREAM_DEFAULT, SAPI_POST_BLOCK_SIZE, PG(upload_tmp_dir));
+ if ((str = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0))) {
+ ZVAL_STR(&zv[2], str);
+ } else {
+ ZVAL_EMPTY_STRING(&zv[2]);
+ }
+ Z_SET_REFCOUNT(zv[2], 1);
+ zend_hash_str_add(ht, ZEND_STRL("input"), &zv[2]);
+ }
+
+ /* change sapi name */
+ {
+ if (sapi_module.name) {
+ ZVAL_STRING(&zv[6], sapi_module.name);
+ } else {
+ Z_TYPE_INFO(zv[6]) = IS_NULL;
+ }
+ zend_hash_str_add(ht, ZEND_STRL("sapi_name"), &zv[6]);
+ Z_SET_REFCOUNT(zv[6], 1);
+ }
+
+ /* handle modules / extensions */
+ {
+ zend_module_entry *module;
+ zend_extension *extension;
+ zend_llist_position pos;
+
+ array_init(&zv[7]);
+ ZEND_HASH_FOREACH_PTR(&module_registry, module) {
+ zval *value = ecalloc(sizeof(zval), 1);
+ ZVAL_STRING(value, module->name);
+ zend_hash_next_index_insert(Z_ARRVAL(zv[7]), value);
+ } ZEND_HASH_FOREACH_END();
+ zend_hash_str_add(ht, ZEND_STRL("modules"), &zv[7]);
+
+ array_init(&zv[8]);
+ extension = (zend_extension *) zend_llist_get_first_ex(&zend_extensions, &pos);
+ while (extension) {
+ zval *value = ecalloc(sizeof(zval), 1);
+ ZVAL_STRING(value, extension->name);
+ zend_hash_next_index_insert(Z_ARRVAL(zv[8]), value);
+ extension = (zend_extension *) zend_llist_get_next_ex(&zend_extensions, &pos);
+ }
+ zend_hash_str_add(ht, ZEND_STRL("extensions"), &zv[8]);
+ }
+
+ /* switch cwd */
+ if (SG(options) & SAPI_OPTION_NO_CHDIR) {
+ char *ret = NULL;
+ char path[MAXPATHLEN];
+
+#if HAVE_GETCWD
+ ret = VCWD_GETCWD(path, MAXPATHLEN);
+#elif HAVE_GETWD
+ ret = VCWD_GETWD(path);
+#endif
+ if (ret) {
+ ZVAL_STRING(&zv[5], path);
+ Z_SET_REFCOUNT(zv[5], 1);
+ zend_hash_str_add(ht, ZEND_STRL("cwd"), &zv[5]);
+ }
+ }
+
+ /* get system ini entries */
+ {
+ zend_ini_entry *ini_entry;
+
+ array_init(&zv[3]);
+ ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) {
+ zval *value = ecalloc(sizeof(zval), 1);
+ if (ini_entry->modified) {
+ if (!ini_entry->orig_value) {
+ efree(value);
+ continue;
+ }
+ ZVAL_STR(value, ini_entry->orig_value);
+ } else {
+ if (!ini_entry->value) {
+ efree(value);
+ continue;
+ }
+ ZVAL_STR(value, ini_entry->value);
+ }
+ zend_hash_add(Z_ARRVAL(zv[3]), ini_entry->name, value);
+ } ZEND_HASH_FOREACH_END();
+ zend_hash_str_add(ht, ZEND_STRL("systemini"), &zv[3]);
+ }
+
+ /* get perdir ini entries */
+ if (EG(modified_ini_directives)) {
+ zend_ini_entry *ini_entry;
+
+ array_init(&zv[4]);
+ ZEND_HASH_FOREACH_PTR(EG(ini_directives), ini_entry) {
+ zval *value = ecalloc(sizeof(zval), 1);
+ if (!ini_entry->value) {
+ efree(value);
+ continue;
+ }
+ ZVAL_STR(value, ini_entry->value);
+ zend_hash_add(Z_ARRVAL(zv[4]), ini_entry->name, value);
+ } ZEND_HASH_FOREACH_END();
+ zend_hash_str_add(ht, ZEND_STRL("userini"), &zv[4]);
+ }
+
+ /* encode data */
+ {
+ php_serialize_data_t var_hash;
+ smart_str buf = {0};
+
+ PHP_VAR_SERIALIZE_INIT(var_hash);
+ php_var_serialize(&buf, &array, &var_hash);
+ PHP_VAR_SERIALIZE_DESTROY(var_hash);
+ *msg = ZSTR_VAL(buf.s);
+ *len = ZSTR_LEN(buf.s);
+ }
+
+ zval_dtor(&array);
+}
diff --git a/sapi/phpdbg/phpdbg_webdata_transfer.h b/sapi/phpdbg/phpdbg_webdata_transfer.h
new file mode 100644
index 0000000000..28810a2741
--- /dev/null
+++ b/sapi/phpdbg/phpdbg_webdata_transfer.h
@@ -0,0 +1,27 @@
+/*
+ +----------------------------------------------------------------------+
+ | PHP Version 7 |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 1997-2015 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: |
+ | http://www.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: Bob Weinand <bwoebi@php.net> |
+ +----------------------------------------------------------------------+
+*/
+
+#ifndef PHPDBG_WEBDATA_TRANSFER_H
+#define PHPDBG_WEBDATA_TRANSFER_H
+
+#include "zend.h"
+#include "phpdbg.h"
+
+PHPDBG_API void phpdbg_webdata_compress(char **msg, int *len);
+
+#endif /* PHPDBG_WEBDATA_TRANSFER_H */
diff --git a/sapi/phpdbg/phpdbg_win.c b/sapi/phpdbg/phpdbg_win.c
index a10baba800..132eb05b1e 100644
--- a/sapi/phpdbg/phpdbg_win.c
+++ b/sapi/phpdbg/phpdbg_win.c
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -31,9 +31,8 @@ int phpdbg_exception_handler_win32(EXCEPTION_POINTERS *xp) {
CONTEXT *xc = xp->ContextRecord;
if(xr->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) {
- TSRMLS_FETCH();
- if (phpdbg_watchpoint_segfault_handler((void *)xr->ExceptionInformation[1] TSRMLS_CC) == SUCCESS) {
+ if (phpdbg_watchpoint_segfault_handler((void *)xr->ExceptionInformation[1]) == SUCCESS) {
return EXCEPTION_CONTINUE_EXECUTION;
}
}
diff --git a/sapi/phpdbg/phpdbg_win.h b/sapi/phpdbg/phpdbg_win.h
index bc51c3f247..9e1501b263 100644
--- a/sapi/phpdbg/phpdbg_win.h
+++ b/sapi/phpdbg/phpdbg_win.h
@@ -1,6 +1,6 @@
/*
+----------------------------------------------------------------------+
- | PHP Version 5 |
+ | PHP Version 7 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2015 The PHP Group |
+----------------------------------------------------------------------+
@@ -34,4 +34,4 @@ void phpdbg_win_set_mm_heap(zend_mm_heap *heap);
int phpdbg_exception_handler_win32(EXCEPTION_POINTERS *xp);
-#endif \ No newline at end of file
+#endif
diff --git a/sapi/phpdbg/tests/basic_run.phpt b/sapi/phpdbg/tests/basic_run.phpt
new file mode 100644
index 0000000000..beb19b535a
--- /dev/null
+++ b/sapi/phpdbg/tests/basic_run.phpt
@@ -0,0 +1,8 @@
+--TEST--
+Basic run
+--PHPDBG--
+r
+q
+--EXPECTF--
+prompt> [Nothing to execute!]
+prompt>
diff --git a/sapi/phpdbg/tests/breakpoints_001.phpt b/sapi/phpdbg/tests/breakpoints_001.phpt
new file mode 100644
index 0000000000..934f0d3554
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_001.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Fundamental breakpoints functionality
+--PHPDBG--
+b 3
+r
+b 4
+c
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:3]
+prompt> [Breakpoint #0 at %s:3, hits: 1]
+>00003: echo 1;
+ 00004: echo 2;
+ 00005: echo 3;
+prompt> [Breakpoint #1 added at %s:4]
+prompt> 1
+[Breakpoint #1 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: echo 4;
+prompt> 234
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+echo 4;
+
diff --git a/sapi/phpdbg/tests/breakpoints_002.phpt b/sapi/phpdbg/tests/breakpoints_002.phpt
new file mode 100644
index 0000000000..18aaef1f36
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_002.phpt
@@ -0,0 +1,40 @@
+--TEST--
+Preserve breakpoints on restart
+--PHPDBG--
+b breakpoints_002.php:4
+r
+b 3
+r
+y
+c
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:4]
+prompt> 1
+[Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: echo 4;
+prompt> [Breakpoint #1 added at %s:3]
+prompt> Do you really want to restart execution? (type y or n): [Breakpoint #1 at %s:3, hits: 1]
+>00003: echo 1;
+ 00004: echo 2;
+ 00005: echo 3;
+prompt> 1
+[Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: echo 4;
+prompt> 234
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+echo 4;
+
diff --git a/sapi/phpdbg/tests/breakpoints_003.phpt b/sapi/phpdbg/tests/breakpoints_003.phpt
new file mode 100644
index 0000000000..8caa64632b
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_003.phpt
@@ -0,0 +1,33 @@
+--TEST--
+Test deleting breakpoints
+--PHPDBG--
+b 4
+b del 0
+b 5
+r
+b del 1
+r
+y
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:4]
+prompt> [Deleted breakpoint #0]
+prompt> [Breakpoint #1 added at %s:5]
+prompt> 12
+[Breakpoint #1 at %s:5, hits: 1]
+>00005: echo 3;
+ 00006: echo 4;
+ 00007:
+prompt> [Deleted breakpoint #1]
+prompt> Do you really want to restart execution? (type y or n): 1234
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+echo 4;
+
diff --git a/sapi/phpdbg/tests/breakpoints_004.phpt b/sapi/phpdbg/tests/breakpoints_004.phpt
new file mode 100644
index 0000000000..27ebd0bea2
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_004.phpt
@@ -0,0 +1,41 @@
+--TEST--
+Test opcode breakpoints
+--PHPDBG--
+b ZEND_ECHO
+r
+c
+
+
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at ZEND_ECHO]
+prompt> [Breakpoint #0 in ZEND_ECHO at %s:3, hits: 1]
+>00003: echo 1;
+ 00004: echo 2;
+ 00005: echo 3;
+prompt> 1
+[Breakpoint #0 in ZEND_ECHO at %s:4, hits: 2]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: echo 4;
+prompt> 2
+[Breakpoint #0 in ZEND_ECHO at %s:5, hits: 3]
+>00005: echo 3;
+ 00006: echo 4;
+ 00007:
+prompt> 3
+[Breakpoint #0 in ZEND_ECHO at %s:6, hits: 4]
+>00006: echo 4;
+ 00007:
+prompt> 4
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+echo 4;
diff --git a/sapi/phpdbg/tests/breakpoints_005.phpt b/sapi/phpdbg/tests/breakpoints_005.phpt
new file mode 100644
index 0000000000..653dab9fcc
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_005.phpt
@@ -0,0 +1,28 @@
+--TEST--
+Test breakpoint into function context
+--PHPDBG--
+b breakpoints_005.php:4
+r
+ev $bar
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:4]
+prompt> [Breakpoint #0 at %s:4, hits: 1]
+>00004: var_dump($bar);
+ 00005: }
+ 00006:
+prompt> test
+prompt> string(4) "test"
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+function foo($bar) {
+ var_dump($bar);
+}
+
+foo("test");
+
diff --git a/sapi/phpdbg/tests/breakpoints_006.phpt b/sapi/phpdbg/tests/breakpoints_006.phpt
new file mode 100644
index 0000000000..fa6f0cdc5b
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_006.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Basic function breakpoints
+--PHPDBG--
+b foo
+r
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at foo]
+prompt> [Breakpoint #0 in foo() at %s:4, hits: 1]
+>00004: var_dump($bar);
+ 00005: }
+ 00006:
+prompt> string(4) "test"
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+function foo($bar) {
+ var_dump($bar);
+}
+
+foo("test");
+
diff --git a/sapi/phpdbg/tests/breakpoints_007.phpt b/sapi/phpdbg/tests/breakpoints_007.phpt
new file mode 100644
index 0000000000..f921c257c5
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_007.phpt
@@ -0,0 +1,25 @@
+--TEST--
+Basic method breakpoints
+--PHPDBG--
+b bar::foo
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at bar::foo]
+prompt> [Breakpoint #0 in bar::foo() at %s:5, hits: 1]
+>00005: var_dump($bar);
+ 00006: }
+ 00007: }
+prompt>
+--FILE--
+<?php
+
+class bar {
+ function foo($bar) {
+ var_dump($bar);
+ }
+}
+
+(new bar)->foo("test");
+
diff --git a/sapi/phpdbg/tests/breakpoints_008.phpt b/sapi/phpdbg/tests/breakpoints_008.phpt
new file mode 100644
index 0000000000..cbe5042c2b
--- /dev/null
+++ b/sapi/phpdbg/tests/breakpoints_008.phpt
@@ -0,0 +1,34 @@
+--TEST--
+Test namespaced and non-lowercase breakpoint names
+--PHPDBG--
+b foo\bar::foo
+b \Foo\Bar::Foo
+r
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at foo\bar::foo]
+prompt> [Breakpoint exists at Foo\Bar::Foo]
+prompt> [Breakpoint #0 in foo\bar::foo() at %s:6, hits: 1]
+>00006: var_dump($bar);
+ 00007: }
+ 00008: }
+prompt> string(4) "test"
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+namespace Foo {
+ class Bar {
+ function Foo($bar) {
+ var_dump($bar);
+ }
+ }
+}
+
+namespace {
+ (new \Foo\Bar)->Foo("test");
+}
+
diff --git a/sapi/phpdbg/tests/clean_001.phpt b/sapi/phpdbg/tests/clean_001.phpt
new file mode 100644
index 0000000000..0500850448
--- /dev/null
+++ b/sapi/phpdbg/tests/clean_001.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Cleaning must preserve breakpoints
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+b 4
+b foo
+r
+c
+clean
+y
+c
+r
+c
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:4]
+prompt> [Breakpoint #1 added at foo]
+prompt> 1
+[Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: foo();
+prompt> 23
+[Breakpoint #1 in foo() at %s:9, hits: 1]
+>00009: echo 4;
+ 00010: }
+ 00011:
+prompt> Do you really want to clean your current environment? (type y or n): Cleaning Execution Environment
+Classes %d
+Functions %d
+Constants %d
+Includes 0
+prompt> [Not running]
+prompt> 1
+[Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: foo();
+prompt> 23
+[Breakpoint #1 in foo() at %s:9, hits: 1]
+>00009: echo 4;
+ 00010: }
+ 00011:
+prompt> 4
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+foo();
+
+function foo() {
+ echo 4;
+}
diff --git a/sapi/phpdbg/tests/clear_001.phpt b/sapi/phpdbg/tests/clear_001.phpt
new file mode 100644
index 0000000000..96d73990eb
--- /dev/null
+++ b/sapi/phpdbg/tests/clear_001.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Test clearing breakpoints
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+b 4
+b foo
+r
+clear
+c
+i b
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:4]
+prompt> [Breakpoint #1 added at foo]
+prompt> 1
+[Breakpoint #0 at %s:4, hits: 1]
+>00004: echo 2;
+ 00005: echo 3;
+ 00006: foo();
+prompt> Clearing Breakpoints
+File 1
+Functions 1
+Methods 0
+Oplines 0
+File oplines 0
+Function oplines 0
+Method oplines 0
+Conditionals 0
+prompt> 234
+[Script ended normally]
+prompt> prompt>
+--FILE--
+<?php
+
+echo 1;
+echo 2;
+echo 3;
+foo();
+
+function foo() {
+ echo 4;
+}
diff --git a/sapi/phpdbg/tests/commands/0001_basic.test b/sapi/phpdbg/tests/commands/0001_basic.test
deleted file mode 100644
index 08aa9ab664..0000000000
--- a/sapi/phpdbg/tests/commands/0001_basic.test
+++ /dev/null
@@ -1,8 +0,0 @@
-#######################################################
-# name: basic
-# purpose: check basic functionality of phpdbg console
-# expect: TEST::EXACT
-# options: -rr
-#######################################################
-# [Nothing to execute!]
-#######################################################
diff --git a/sapi/phpdbg/tests/commands/0002_set.test b/sapi/phpdbg/tests/commands/0002_set.test
deleted file mode 100644
index 468ac6d9ea..0000000000
--- a/sapi/phpdbg/tests/commands/0002_set.test
+++ /dev/null
@@ -1,21 +0,0 @@
-#################################################
-# name: set
-# purpose: tests for set commands
-# expect: TEST::CISTRING
-# options: -rr
-#################################################
-# setting prompt color
-# setting error color
-# setting notice color
-# Failed to find breakpoint #0
-# oplog disabled
-# opened oplog test.log
-# nothing
-#################################################
-set color prompt none
-set color error none
-set color notice none
-set prompt promot>
-set break 0
-set oplog
-set oplog test.log
diff --git a/sapi/phpdbg/tests/commands/0101_info.test b/sapi/phpdbg/tests/commands/0101_info.test
deleted file mode 100644
index 397a45c992..0000000000
--- a/sapi/phpdbg/tests/commands/0101_info.test
+++ /dev/null
@@ -1,19 +0,0 @@
-#################################################
-# name: info
-# purpose: test info commands
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[User Classes (%d)]
-#User Class test (3)
-#|---- in phpdbginit code on line %d
-#################################################
-<:
-class test {
- public function testMethod(){}
- private function testPrivateMethod(){}
- protected function testProtectedMethod(){}
-}
-:>
-info classes
-q
diff --git a/sapi/phpdbg/tests/commands/0102_print.test b/sapi/phpdbg/tests/commands/0102_print.test
deleted file mode 100644
index de4acb7651..0000000000
--- a/sapi/phpdbg/tests/commands/0102_print.test
+++ /dev/null
@@ -1,28 +0,0 @@
-#################################################
-# name: print
-# purpose: test print commands
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[User Class: test]
-#Methods (3):
-#L%d-%d test::testMethod() %s
-# L%d %s ZEND_RETURN C%d <unused> <unused>
-# L%d-%d test::testPrivateMethod() %s
-# L%d %s ZEND_RETURN C%d <unused> <unused>
-# L%d-%d test::testProtectedMethod() %s
-# L%d %s ZEND_RETURN C%d <unused> <unused>
-#[User Method testMethod]
-# L%d-%d test::testMethod() %s
-# L%d %s ZEND_RETURN C%d <unused> <unused>
-#################################################
-<:
-class test {
- public function testMethod(){}
- private function testPrivateMethod(){}
- protected function testProtectedMethod(){}
-}
-:>
-print class test
-print method test::testMethod
-q
diff --git a/sapi/phpdbg/tests/commands/0103_register.test b/sapi/phpdbg/tests/commands/0103_register.test
deleted file mode 100644
index 703a12f771..0000000000
--- a/sapi/phpdbg/tests/commands/0103_register.test
+++ /dev/null
@@ -1,28 +0,0 @@
-#################################################
-# name: register
-# purpose: test registration functions
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[Registered test_function]
-#array(5) {
-# [0]=>
-# int(1)
-# [1]=>
-# int(2)
-# [2]=>
-# int(3)
-# [3]=>
-# int(4)
-# [4]=>
-# int(5)
-#}
-#################################################
-<:
-function test_function() {
- var_dump(func_get_args());
-}
-:>
-R test_function
-test_function 1 2 3 4 5
-q
diff --git a/sapi/phpdbg/tests/commands/0104_clean.test b/sapi/phpdbg/tests/commands/0104_clean.test
deleted file mode 100644
index c7a579be17..0000000000
--- a/sapi/phpdbg/tests/commands/0104_clean.test
+++ /dev/null
@@ -1,15 +0,0 @@
-#################################################
-# name: clean
-# purpose: test cleaning environment
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[Cleaning Execution Environment]
-#Classes %d
-#Functions %d
-#Constants %d
-#Includes %d
-#[Nothing to execute!]
-#################################################
-clean
-quit
diff --git a/sapi/phpdbg/tests/commands/0105_clear.test b/sapi/phpdbg/tests/commands/0105_clear.test
deleted file mode 100644
index b547b0d6ba..0000000000
--- a/sapi/phpdbg/tests/commands/0105_clear.test
+++ /dev/null
@@ -1,18 +0,0 @@
-#################################################
-# name: clear
-# purpose: test clearing breakpoints
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[Clearing Breakpoints]
-#File%w%d
-#Functions%w%d
-#Methods%w%d
-#Oplines%w%d
-#File oplines%w%d
-#Function oplines%w%d
-#Method oplines%w%d
-#Conditionals%w%d
-#################################################
-clear
-quit
diff --git a/sapi/phpdbg/tests/commands/0106_compile.test b/sapi/phpdbg/tests/commands/0106_compile.test
deleted file mode 100644
index 7193600ea3..0000000000
--- a/sapi/phpdbg/tests/commands/0106_compile.test
+++ /dev/null
@@ -1,18 +0,0 @@
-#################################################
-# name: compile
-# purpose: test compiling code
-# expect: TEST::FORMAT
-# options: -rr
-#################################################
-#[Attempting compilation of %s]
-#[Success]
-#Hello World
-#################################################
-<:
-define('OUT',
- tempnam(null, "phpdbg"));
-file_put_contents(OUT, "<?php echo \"Hello World\"; ?>");
-phpdbg_exec(OUT);
-:>
-run
-quit
diff --git a/sapi/phpdbg/tests/delimiter.phpt b/sapi/phpdbg/tests/delimiter.phpt
new file mode 100644
index 0000000000..da5f681783
--- /dev/null
+++ b/sapi/phpdbg/tests/delimiter.phpt
@@ -0,0 +1,7 @@
+--TEST--
+Test # delimiter parsing and execution
+--PHPDBG--
+ev 1 + 3 # ev 2 ** 3#q
+--EXPECTF--
+prompt> 4
+8
diff --git a/sapi/phpdbg/tests/exceptions_001.phpt b/sapi/phpdbg/tests/exceptions_001.phpt
new file mode 100644
index 0000000000..991ea1cc71
--- /dev/null
+++ b/sapi/phpdbg/tests/exceptions_001.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Properly handle exceptions going to be uncaught
+--PHPDBG--
+r
+t
+ev 1 + 2
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> handle first
+[Uncaught Error in %s on line 16: Call to undefined function foo()]
+>00016: foo(); // Error
+ 00017: } catch (\Exception $e) {
+ 00018: var_dump($e);
+prompt> frame #0: {closure}() at %s:16
+frame #1: {main} at %s:20
+prompt> 3
+prompt> [Uncaught Error in %s on line 16]
+Error: Call to undefined function foo() in %s:16
+Stack trace:
+#0 %s(20): {closure}()
+#1 {main}
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+(function() {
+ try {
+ foo(); // Error
+ } catch (\Exception $e) {
+ var_dump($e);
+ } finally {
+ print "handle first\n";
+ return "ok";
+ }
+})();
+
+(function() {
+ try {
+ foo(); // Error
+ } catch (\Exception $e) {
+ var_dump($e);
+ }
+})();
diff --git a/sapi/phpdbg/tests/exceptions_002.phpt b/sapi/phpdbg/tests/exceptions_002.phpt
new file mode 100644
index 0000000000..f304cc25db
--- /dev/null
+++ b/sapi/phpdbg/tests/exceptions_002.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Test exceptions in eval during exception
+--PHPDBG--
+r
+ev next_error()
+c
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> handle first
+[Uncaught Error in %s on line 16: Call to undefined function foo()]
+>00016: foo(); // Error
+ 00017: } catch (\Exception $e) {
+ 00018: var_dump($e);
+prompt>
+Fatal error: Uncaught Error: Call to undefined function next_error() in eval()'d code:1
+Stack trace:
+#0 %s(16): unknown()
+#1 %s(20): {closure}()
+#2 {main}
+ thrown in eval()'d code on line 1
+prompt> [Uncaught Error in %s on line 16]
+Error: Call to undefined function foo() in %s:16
+Stack trace:
+#0 %s(20): {closure}()
+#1 {main}
+[Script ended normally]
+prompt> [The stack contains nothing !]
+prompt>
+--FILE--
+<?php
+
+(function() {
+ try {
+ foo(); // Error
+ } catch (\Exception $e) {
+ var_dump($e);
+ } finally {
+ print "handle first\n";
+ return "ok";
+ }
+})();
+
+(function() {
+ try {
+ foo(); // Error
+ } catch (\Exception $e) {
+ var_dump($e);
+ }
+})();
diff --git a/sapi/phpdbg/tests/exceptions_003.phpt b/sapi/phpdbg/tests/exceptions_003.phpt
new file mode 100644
index 0000000000..fffe7a9296
--- /dev/null
+++ b/sapi/phpdbg/tests/exceptions_003.phpt
@@ -0,0 +1,54 @@
+--TEST--
+Test breaks on HANDLE_EXCEPTION
+--PHPDBG--
+b 5
+r
+s
+
+s
+
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:5]
+prompt> [Breakpoint #0 at %s:5, hits: 1]
+>00005: x();
+ 00006: } finally {
+ 00007: print "ok\n";
+prompt> [L0 %s HANDLE_EXCEPTION %s]
+>00005: x();
+ 00006: } finally {
+ 00007: print "ok\n";
+prompt> [L7 %s ECHO "ok " %s]
+>00007: print "ok\n";
+ 00008: }
+ 00009: } catch (Error $e) {
+prompt> ok
+[L7 %s FAST_RET<TO_CATCH> ~%d J7 %s]
+[L9 %s CATCH "Error" $e 1 %s]
+>00005: x();
+ 00006: } finally {
+ 00007: print "ok\n";
+prompt> [L10 %s ECHO "caught " %s]
+>00010: print "caught\n";
+ 00011: }
+ 00012:
+prompt> caught
+[L10 %s RETURN 1 %s]
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+try {
+ try {
+ x();
+ } finally {
+ print "ok\n";
+ }
+} catch (Error $e) {
+ print "caught\n";
+}
+
+?>
diff --git a/sapi/phpdbg/tests/finish_leave_001.phpt b/sapi/phpdbg/tests/finish_leave_001.phpt
new file mode 100644
index 0000000000..774776c05f
--- /dev/null
+++ b/sapi/phpdbg/tests/finish_leave_001.phpt
@@ -0,0 +1,41 @@
+--TEST--
+test finish and leave commands
+--PHPDBG--
+b bar
+b 5
+r
+finish
+leave
+leave
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at bar]
+prompt> [Breakpoint #1 added at %s:5]
+prompt> [Breakpoint #0 in bar() at %s:9, hits: 1]
+>00009: return "world";
+ 00010: }
+ 00011:
+prompt> [Breakpoint #1 at %s:5, hits: 1]
+>00005: return ["hello", $other];
+ 00006: }
+ 00007:
+prompt> [Breaking for leave at %s:5]
+>00005: return ["hello", $other];
+ 00006: }
+ 00007:
+prompt> [Already at the end of the function]
+prompt>
+--FILE--
+<?php
+function foo() {
+ $other = bar();
+
+ return ["hello", $other];
+}
+
+function bar() {
+ return "world";
+}
+
+foo();
diff --git a/sapi/phpdbg/tests/generator_run.phpt b/sapi/phpdbg/tests/generator_run.phpt
new file mode 100644
index 0000000000..798d77051e
--- /dev/null
+++ b/sapi/phpdbg/tests/generator_run.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Ensure proper saving of EX(opline)
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> caught Generator exception
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+function gen() {
+ try {
+ throw new Exception;
+ } catch(Exception $e) {
+ yield "caught Generator exception";
+ }
+}
+
+foreach (gen() as $v) {
+ print $v;
+}
diff --git a/sapi/phpdbg/tests/info_001.phpt b/sapi/phpdbg/tests/info_001.phpt
new file mode 100644
index 0000000000..b988235757
--- /dev/null
+++ b/sapi/phpdbg/tests/info_001.phpt
@@ -0,0 +1,80 @@
+--TEST--
+Test basic info functionality
+--INI--
+auto_globals_jit=0
+--PHPDBG--
+i classes
+i funcs
+b foo
+r
+i v
+i g
+i b
+i d
+i F
+i e
+i l
+c
+i v
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [User Classes (1)]
+User Class Foo\Bar (2)
+|---- in %s on line 4
+prompt> [User Functions (1)]
+|-------- foo in %s on line 14
+prompt> [Breakpoint #0 added at foo]
+prompt> string(4) "test"
+[Breakpoint #0 in foo() at %s:15, hits: 1]
+>00015: var_dump(strrev($baz));
+ 00016: }
+ 00017:
+prompt> [Variables in foo() (1)]
+Address Refs Type Variable
+%s 1 string $baz
+string (4) "test"
+prompt> [Superglobal variables (8)]
+Address Refs Type Variable
+%s 2 array $_GET
+%s 2 array $_POST
+%s 2 array $_COOKIE
+%s 2 array $_SERVER
+%s 2 array $_ENV
+%s 1 array $_REQUEST
+%s 2 array $_FILES
+%s 1 array &$GLOBALS
+prompt> ------------------------------------------------
+Function Breakpoints:
+#0 foo
+prompt> [User-defined constants (0)]
+prompt> [Included files: 0]
+prompt> [No error found!]
+prompt> [Literal Constants in foo() (2)]
+|-------- C0 -------> [var_dump]
+|-------- C1 -------> [strrev]
+prompt> string(4) "tset"
+[Script ended normally]
+prompt> [No active op array!]
+prompt>
+--FILE--
+<?php
+
+namespace Foo {
+ class Bar {
+ function Foo($bar) {
+ var_dump($bar);
+ }
+
+ function baz() { }
+ }
+}
+
+namespace {
+ function foo($baz) {
+ var_dump(strrev($baz));
+ }
+
+ (new \Foo\Bar)->Foo("test");
+ foo("test");
+}
diff --git a/sapi/phpdbg/tests/info_002.phpt b/sapi/phpdbg/tests/info_002.phpt
new file mode 100644
index 0000000000..faeca0e430
--- /dev/null
+++ b/sapi/phpdbg/tests/info_002.phpt
@@ -0,0 +1,31 @@
+--TEST--
+info constants test
+--PHPDBG--
+b 10
+r
+i d
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:10]
+prompt> [Breakpoint #0 at %s:10, hits: 1]
+>00010: print B;
+ 00011:
+prompt> [User-defined constants (2)]
+Address Refs Type Constant
+%s 1 integer A
+int (10)
+%s 1 integer B
+int (100)
+prompt>
+--FILE--
+<?php
+
+const A = 10;
+const B = C::D * A;
+
+class C {
+ const D = 10;
+}
+
+print B;
diff --git a/sapi/phpdbg/tests/normal_exit.phpt b/sapi/phpdbg/tests/normal_exit.phpt
new file mode 100644
index 0000000000..692614e98f
--- /dev/null
+++ b/sapi/phpdbg/tests/normal_exit.phpt
@@ -0,0 +1,15 @@
+--TEST--
+A script with die() must end "normally"
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Script ended normally]
+prompt>
+--FILE--
+<?php
+
+(function($argv) {
+ die();
+})($argv);
diff --git a/sapi/phpdbg/tests/phpdbg_break_next.phpt b/sapi/phpdbg/tests/phpdbg_break_next.phpt
new file mode 100644
index 0000000000..37ee2e8282
--- /dev/null
+++ b/sapi/phpdbg/tests/phpdbg_break_next.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Test phpdbg_break_next() function
+--PHPDBG--
+r
+c
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> A
+[Breakpoint #0 added at %s]
+[Breakpoint #0 in %s at %s:5, hits: 1]
+>00005: echo 'B';
+ 00006:
+prompt> B
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+echo 'A';
+phpdbg_break_next();
+echo 'B';
diff --git a/sapi/phpdbg/tests/phpdbg_oplog_001.phpt b/sapi/phpdbg/tests/phpdbg_oplog_001.phpt
new file mode 100644
index 0000000000..e4e558b9fa
--- /dev/null
+++ b/sapi/phpdbg/tests/phpdbg_oplog_001.phpt
@@ -0,0 +1,58 @@
+--TEST--
+Test phpdbg_*_oplog() functions
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> halloarray(2) {
+ ["%s"]=>
+ array(5) {
+ [13]=>
+ int(1)
+ [17]=>
+ int(2)
+ [18]=>
+ int(2)
+ [19]=>
+ int(3)
+ [21]=>
+ int(4)
+ }
+ ["A::b"]=>
+ array(3) {
+ [4]=>
+ int(1)
+ [5]=>
+ int(3)
+ [8]=>
+ int(2)
+ }
+}
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+class A {
+ public function b($c = 1) {
+ if ($c == 1) {
+ // comment
+ }
+ }
+}
+
+phpdbg_start_oplog();
+
+echo "hallo";
+
+// fcalls
+
+$a = new A();
+$a->b();
+$a->b('ha');
+
+var_dump(phpdbg_end_oplog(["functions" => true]));
+
diff --git a/sapi/phpdbg/tests/phpdbg_oplog_002.phpt b/sapi/phpdbg/tests/phpdbg_oplog_002.phpt
new file mode 100644
index 0000000000..b9ba905caa
--- /dev/null
+++ b/sapi/phpdbg/tests/phpdbg_oplog_002.phpt
@@ -0,0 +1,16 @@
+--TEST--
+phpdbg_end_oplog() alone must not crash
+--PHPDBG--
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt>
+Warning: Can not end an oplog without starting it in %s on line 3
+NULL
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+var_dump(phpdbg_end_oplog());
diff --git a/sapi/phpdbg/tests/print_001.phpt b/sapi/phpdbg/tests/print_001.phpt
new file mode 100644
index 0000000000..1f7a5ac0b9
--- /dev/null
+++ b/sapi/phpdbg/tests/print_001.phpt
@@ -0,0 +1,67 @@
+--TEST--
+Basic print functionality
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+p foo
+p class \Foo\bar
+p
+p e
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [User Function foo (8 ops)]
+L14-16 foo() %s - %s + 8 ops
+ L14 #0 RECV 1 $baz
+ L15 #1 INIT_FCALL%s %d %s "var_dump"
+ L15 #2 INIT_FCALL%s %d %s "strrev"
+ L15 #3 SEND_VAR $baz 1
+ L15 #4 DO_%cCALL @0
+ L15 #5 SEND_VAR @0 1
+ L15 #6 DO_%cCALL
+ L16 #7 RETURN null
+prompt> [User Class: Foo\Bar (2 methods)]
+L5-7 Foo\Bar::Foo() %s - %s + 5 ops
+ L5 #0 RECV 1 $bar
+ L6 #1 INIT_NS_FCALL_BY_NAME "Foo\\var_dump"
+ L6 #2 SEND_VAR_EX $bar 1
+ L6 #3 DO_FCALL
+ L7 #4 RETURN null
+L9-9 Foo\Bar::baz() %s - %s + 1 ops
+ L9 #0 RETURN null
+prompt> [Not Executing!]
+prompt> [Context %s (11 ops)]
+L1-19 {main}() %s - %s + 11 ops
+ L4 #0 NOP
+ L14 #1 NOP
+ L18 #2 NEW "Foo\\Bar" @1
+ L18 #3 DO_FCALL
+ L18 #4 INIT_METHOD_CALL @1 "Foo"
+ L18 #5 SEND_VAL_EX "test" 1
+ L18 #6 DO_FCALL
+ L19 #7 INIT_FCALL%s %d %s "foo"
+ L19 #8 SEND_VAL "test" 1
+ L19 #9 DO_FCALL
+ L19 #10 RETURN 1
+prompt>
+--FILE--
+<?php
+
+namespace Foo {
+ class Bar {
+ function Foo($bar) {
+ var_dump($bar);
+ }
+
+ function baz() { }
+ }
+}
+
+namespace {
+ function foo($baz) {
+ var_dump(strrev($baz));
+ }
+
+ (new \Foo\Bar)->Foo("test");
+ foo("test");
+}
diff --git a/sapi/phpdbg/tests/print_002.phpt b/sapi/phpdbg/tests/print_002.phpt
new file mode 100644
index 0000000000..3a824986c1
--- /dev/null
+++ b/sapi/phpdbg/tests/print_002.phpt
@@ -0,0 +1,51 @@
+--TEST--
+Relative print commands
+--INI--
+opcache.enable_cli=0
+--PHPDBG--
+b foo
+r
+p
+p o
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at foo]
+prompt> string(4) "test"
+[Breakpoint #0 in foo() at %s:15, hits: 1]
+>00015: var_dump(strrev($baz));
+ 00016: }
+ 00017:
+prompt> [Stack in foo() (8 ops)]
+L14-16 foo() %s - %s + 8 ops
+ L14 #0 RECV 1 $baz
+ L15 #1 INIT_FCALL%s %d %s "var_dump"
+ L15 #2 INIT_FCALL%s %d %s "strrev"
+ L15 #3 SEND_VAR $baz 1
+ L15 #4 DO_%cCALL @0
+ L15 #5 SEND_VAR @0 1
+ L15 #6 DO_%cCALL
+ L16 #7 RETURN null
+prompt> [L15 %s INIT_FCALL%s %d %s "var_dump" %s]
+prompt>
+--FILE--
+<?php
+
+namespace Foo {
+ class Bar {
+ function Foo($bar) {
+ var_dump($bar);
+ }
+
+ function baz() { }
+ }
+}
+
+namespace {
+ function foo($baz) {
+ var_dump(strrev($baz));
+ }
+
+ (new \Foo\Bar)->Foo("test");
+ foo("test");
+}
diff --git a/sapi/phpdbg/tests/run-tests.php b/sapi/phpdbg/tests/run-tests.php
deleted file mode 100644
index 1cc31d815e..0000000000
--- a/sapi/phpdbg/tests/run-tests.php
+++ /dev/null
@@ -1,597 +0,0 @@
-<?php
-namespace phpdbg\testing {
-
- /*
- * Workaround ...
- */
- if (!defined('DIR_SEP'))
- define('DIR_SEP', '\\' . DIRECTORY_SEPARATOR);
-
- /**
- * TestConfigurationExceptions are thrown
- * when the configuration prohibits tests executing
- *
- * @package phpdbg
- * @subpackage testing
- */
- class TestConfigurationException extends \Exception {
-
- /**
- *
- * @param array Tests confguration
- * @param message Exception message
- * @param ... formatting parameters
- */
- public function __construct() {
- $argv = func_get_args();
-
- if (count($argv)) {
-
- $this->config = array_shift($argv);
- $this->message = vsprintf(
- array_shift($argv), $argv);
- }
- }
- }
-
- /**
- *
- * @package phpdbg
- * @subpackage testing
- */
- class TestsConfiguration implements \ArrayAccess {
-
- /**
- *
- * @param array basic configuration
- * @param array argv
- */
- public function __construct($config, $cmd) {
- $this->options = $config;
- while (($key = array_shift($cmd))) {
- switch (substr($key, 0, 1)) {
- case '-': switch(substr($key, 1, 1)) {
- case '-': {
- $arg = substr($key, 2);
- if (($e=strpos($arg, '=')) !== false) {
- $key = substr($arg, 0, $e);
- $value = substr($arg, $e+1);
- } else {
- $key = $arg;
- $value = array_shift($cmd);
- }
-
- if (isset($key) && isset($value)) {
- switch ($key) {
- case 'phpdbg':
- case 'width':
- $this->options[$key] = $value;
- break;
-
- default: {
- if (isset($config[$key])) {
- if (is_array($config[$key])) {
- $this->options[$key][] = $value;
- } else {
- $this->options[$key] = array($config[$key], $value);
- }
- } else {
- $this->options[$key] = $value;
- }
- }
- }
-
- }
- } break;
-
- default:
- $this->flags[] = substr($key, 1);
- } break;
- }
- }
-
- if (!is_executable($this->options['phpdbg'])) {
- throw new TestConfigurationException(
- $this->options, 'phpdbg could not be found at the specified path (%s)', $this->options['phpdbg']);
- } else $this->options['phpdbg'] = realpath($this->options['phpdbg']);
-
- $this->options['width'] = (integer) $this->options['width'];
-
- /* display properly, all the time */
- if ($this->options['width'] < 50) {
- $this->options['width'] = 50;
- }
-
- /* calculate column widths */
- $this->options['lwidth'] = ceil($this->options['width'] / 3);
- $this->options['rwidth'] = ceil($this->options['width'] - $this->options['lwidth']) - 5;
- }
-
- public function hasFlag($flag) {
- return in_array(
- $flag, $this->flags);
- }
-
- public function offsetExists($offset) { return isset($this->options[$offset]); }
- public function offsetGet($offset) { return $this->options[$offset]; }
- public function offsetUnset($offset) { unset($this->options[$offset]); }
- public function offsetSet($offset, $data) { $this->options[$offset] = $data; }
-
- protected $options = array();
- protected $flags = array();
- }
-
- /**
- * Tests is the console programming API for the test suite
- *
- * @package phpdbg
- * @subpackage testing
- */
- class Tests {
-
- /**
- * Construct the console object
- *
- * @param array basic configuration
- * @param array command line
- */
- public function __construct(TestsConfiguration $config) {
- $this->config = $config;
-
- if ($this->config->hasFlag('help') ||
- $this->config->hasFlag('h')) {
- $this->showUsage();
- exit;
- }
- }
-
- /**
- * Find valid paths as specified by configuration
- *
- */
- public function findPaths($in = null) {
- $paths = array();
- $where = ($in != null) ? array($in) : $this->config['path'];
-
- foreach ($where as $path) {
- if ($path) {
- if (is_dir($path)) {
- $paths[] = $path;
- foreach (scandir($path) as $child) {
- if ($child != '.' && $child != '..') {
- $paths = array_merge(
- $paths, $this->findPaths("$path/$child"));
- }
- }
- }
- }
- }
-
- return $paths;
- }
-
- /**
- *
- * @param string the path to log
- */
- public function logPath($path) {
- printf(
- '%s [%s]%s',
- str_repeat(
- '-', $this->config['width'] - strlen($path)),
- $path, PHP_EOL);
- }
-
- /**
- *
- * @param string the path to log
- */
- public function logPathStats($path) {
- if (!isset($this->stats[$path])) {
- return;
- }
-
- $total = array_sum($this->stats[$path]);
-
- if ($total) {
- @$this->totals[true] += $this->stats[$path][true];
- @$this->totals[false] += $this->stats[$path][false];
-
- $stats = @sprintf(
- "%d/%d %%%d",
- $this->stats[$path][true],
- $this->stats[$path][false],
- (100 / $total) * $this->stats[$path][true]);
-
- printf(
- '%s [%s]%s',
- str_repeat(
- ' ', $this->config['width'] - strlen($stats)),
- $stats, PHP_EOL);
-
- printf("%s%s", str_repeat('-', $this->config['width']+3), PHP_EOL);
- printf("%s", PHP_EOL);
- }
- }
-
- /**
- *
- */
- public function logStats() {
- $total = array_sum($this->totals);
- $stats = @sprintf(
- "%d/%d %%%d",
- $this->totals[true],
- $this->totals[false],
- (100 / $total) * $this->totals[true]);
- printf(
- '%s [%s]%s',
- str_repeat(
- ' ', $this->config['width'] - strlen($stats)),
- $stats, PHP_EOL);
-
- }
-
- /**
- *
- */
- protected function showUsage() {
- printf('usage: php %s [flags] [options]%s', $this->config['exec'], PHP_EOL);
- printf('[options]:%s', PHP_EOL);
- printf("\t--path\t\tadd a path to scan outside of tests directory%s", PHP_EOL);
- printf("\t--width\t\tset line width%s", PHP_EOL);
- printf("\t--options\toptions to pass to phpdbg%s", PHP_EOL);
- printf("\t--phpdbg\tpath to phpdbg binary%s", PHP_EOL);
- printf('[flags]:%s', PHP_EOL);
- printf("\t-diff2stdout\t\twrite diff to stdout instead of files%s", PHP_EOL);
- printf("\t-nodiff\t\tdo not write diffs on failure%s", PHP_EOL);
- printf("\t-nolog\t\tdo not write logs on failure%s", PHP_EOL);
- printf('[examples]:%s', PHP_EOL);
- printf("\tphp %s --phpdbg=/usr/local/bin/phpdbg --path=/usr/src/phpdbg/tests --options -n%s",
- $this->config['exec'], PHP_EOL);
-
- }
-
- /**
- * Find valid tests at the specified path (assumed valid)
- *
- * @param string a valid path
- */
- public function findTests($path) {
- $tests = array();
-
- foreach (scandir($path) as $file) {
- if ($file == '.' || $file == '..')
- continue;
-
- $test = sprintf('%s/%s', $path, $file);
-
- if (preg_match('~\.test$~', $test)) {
- $tests[] = new Test($this->config, $test);
- }
- }
-
- return $tests;
- }
-
- /**
- *
- * @param Test the test to log
- */
- public function logTest($path, Test $test) {
- @$this->stats[$path][($result=$test->getResult())]++;
-
- printf(
- "%-{$this->config['lwidth']}s %-{$this->config['rwidth']}s [%s]%s",
- $test->name,
- $test->purpose,
- $result ? "PASS" : "FAIL",
- PHP_EOL);
-
- return $result;
- }
-
- protected $config;
- }
-
- class Test {
- /*
- * Expect exact line for line match
- */
- const EXACT = 0x00000001;
-
- /*
- * Expect strpos() !== false
- */
- const STRING = 0x00000010;
-
- /*
- * Expect stripos() !== false
- */
- const CISTRING = 0x00000100;
-
- /*
- * Formatted output
- */
- const FORMAT = 0x00001000;
-
- /**
- * Format specifiers
- */
- private static $format = array(
- 'search' => array(
- '%e',
- '%s',
- '%S',
- '%a',
- '%A',
- '%w',
- '%i',
- '%d',
- '%x',
- '%f',
- '%c',
- '%t',
- '%T'
- ),
- 'replace' => array(
- DIR_SEP,
- '[^\r\n]+',
- '[^\r\n]*',
- '.+',
- '.*',
- '\s*',
- '[+-]?\d+',
- '\d+',
- '[0-9a-fA-F]+',
- '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?',
- '.',
- '\t',
- '\t+'
- )
- );
-
- /**
- * Constructs a new Test object given a specilized phpdbginit file
- *
- * @param array configuration
- * @param string file
- */
- public function __construct(TestsConfiguration $config, $file) {
- if (($handle = fopen($file, 'r'))) {
- while (($line = fgets($handle))) {
- $trim = trim($line);
-
- switch (substr($trim, 0, 1)) {
- case '#': if (($chunks = array_map('trim', preg_split('~:~', substr($trim, 1), 2)))) {
- if (property_exists($this, $chunks[0])) {
- switch ($chunks[0]) {
- case 'expect': {
- if ($chunks[1]) {
- switch (strtoupper($chunks[1])) {
- case 'TEST::EXACT':
- case 'EXACT': { $this->expect = TEST::EXACT; } break;
-
- case 'TEST::STRING':
- case 'STRING': { $this->expect = TEST::STRING; } break;
-
- case 'TEST::CISTRING':
- case 'CISTRING': { $this->expect = TEST::CISTRING; } break;
-
- case 'TEST::FORMAT':
- case 'FORMAT': { $this->expect = TEST::FORMAT; } break;
-
- default:
- throw new TestConfigurationException(
- $this->config, "unknown type of expectation (%s)", $chunks[1]);
- }
- }
- } break;
-
- default: {
- $this->$chunks[0] = $chunks[1];
- }
- }
- } else switch(substr($trim, 1, 1)) {
- case '#': { /* do nothing */ } break;
-
- default: {
- $line = preg_replace(
- "~(\r\n)~", "\n", substr($trim, 1));
-
- $line = trim($line);
-
- switch ($this->expect) {
- case TEST::FORMAT:
- $this->match[] = str_replace(
- self::$format['search'],
- self::$format['replace'], preg_quote($line));
- break;
-
- default: $this->match[] = $line;
- }
- }
- }
- } break;
-
- default:
- break 2;
- }
- }
- fclose($handle);
-
- $this->config = $config;
- $this->file = $file;
- }
- }
-
- /**
- * Obvious!!
- *
- */
- public function getResult() {
- $options = sprintf('-i%s -nqb', $this->file);
-
- if ($this->options) {
- $options = sprintf(
- '%s %s %s',
- $options,
- $this->config['options'],
- $this->options
- );
- } else {
- $options = sprintf(
- '%s %s', $options, $this->config['options']
- );
- }
-
- $result = `{$this->config['phpdbg']} {$options}`;
-
- if ($result) {
- foreach (preg_split('~(\r|\n)~', $result) as $num => $line) {
- if (!$line && !isset($this->match[$num]))
- continue;
-
- switch ($this->expect) {
- case TEST::EXACT: {
- if (strcmp($line, $this->match[$num]) !== 0) {
- $this->diff['wants'][$num] = &$this->match[$num];
- $this->diff['gets'][$num] = $line;
- }
- } continue 2;
-
- case TEST::STRING: {
- if (strpos($line, $this->match[$num]) === false) {
- $this->diff['wants'][$num] = &$this->match[$num];
- $this->diff['gets'][$num] = $line;
- }
- } continue 2;
-
- case TEST::CISTRING: {
- if (stripos($line, $this->match[$num]) === false) {
- $this->diff['wants'][$num] = &$this->match[$num];
- $this->diff['gets'][$num] = $line;
- }
- } continue 2;
-
- case TEST::FORMAT: {
- $line = trim($line);
- if (!preg_match("/^{$this->match[$num]}\$/s", $line)) {
- $this->diff['wants'][$num] = &$this->match[$num];
- $this->diff['gets'][$num] = $line;
- }
- } continue 2;
- }
- }
- }
-
- $this->writeLog($result);
- $this->writeDiff();
-
- return (count($this->diff) == 0);
- }
-
- /**
- * Write diff to disk if configuration allows it
- *
- */
- protected function writeDiff() {
- if (count($this->diff['wants'])) {
- if (!$this->config->hasFlag('nodiff')) {
- if ($this->config->hasFlag('diff2stdout')) {
- $difffile = "php://stdout";
- file_put_contents($difffile, "====DIFF====\n");
- } else {
- $difffile = sprintf(
- '%s/%s.diff',
- dirname($this->file), basename($this->file));
- }
-
- if (($diff = fopen($difffile, 'w+'))) {
-
- foreach ($this->diff['wants'] as $line => $want) {
- $got = $this->diff['gets'][$line];
-
- fprintf(
- $diff, '(%d) -%s%s', $line+1, $want, PHP_EOL);
- fprintf(
- $diff, '(%d) +%s%s', $line+1, $got, PHP_EOL);
- }
-
- fclose($diff);
- }
- }
- } else unlink($diff);
- }
-
- /**
- * Write log to disk if configuration allows it
- *
- */
- protected function writeLog($result = null) {
- $log = sprintf(
- '%s/%s.log',
- dirname($this->file), basename($this->file));
-
- if (count($this->diff) && $result) {
- if (!in_array('nolog', $this->config['flags'])) {
- @file_put_contents(
- $log, $result);
- }
- } else unlink($log);
- }
-
- public $name;
- public $purpose;
- public $file;
- public $options;
- public $expect;
-
- protected $match;
- protected $diff;
- protected $stats;
- protected $totals;
- }
-}
-
-namespace {
- use \phpdbg\Testing\Test;
- use \phpdbg\Testing\Tests;
- use \phpdbg\Testing\TestsConfiguration;
-
- $cwd = dirname(__FILE__);
- $cmd = $_SERVER['argv'];
-
- $retval = 0;
-
- {
- $config = new TestsConfiguration(array(
- 'exec' => realpath(array_shift($cmd)),
- 'phpdbg' => realpath(sprintf(
- '%s/../phpdbg', $cwd
- )),
- 'path' => array(
- realpath(dirname(__FILE__))
- ),
- 'flags' => array(),
- 'width' => 75
- ), $cmd);
-
- $tests = new Tests($config);
-
- foreach ($tests->findPaths() as $path) {
- $tests->logPath($path);
-
- foreach ($tests->findTests($path) as $test) {
- $retval |= !$tests->logTest($path, $test);
- }
-
- $tests->logPathStats($path);
- }
-
- $tests->logStats();
- }
-
- die($retval);
-}
-?>
diff --git a/sapi/phpdbg/tests/run_001.phpt b/sapi/phpdbg/tests/run_001.phpt
new file mode 100644
index 0000000000..30aab1f17a
--- /dev/null
+++ b/sapi/phpdbg/tests/run_001.phpt
@@ -0,0 +1,56 @@
+--TEST--
+Test argv passing
+--PHPDBG--
+r
+r 1 2 3
+r
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> int(5)
+array(5) {
+ [0]=>
+ string(%d) "%s"
+ [1]=>
+ string(2) "--"
+ [2]=>
+ string(1) "1"
+ [3]=>
+ string(1) "2"
+ [4]=>
+ string(1) "3"
+}
+[Script ended normally]
+prompt> int(5)
+array(4) {
+ [0]=>
+ string(%d) "%s"
+ [1]=>
+ string(1) "1"
+ [2]=>
+ string(1) "2"
+ [3]=>
+ string(1) "3"
+}
+[Script ended normally]
+prompt> int(5)
+array(5) {
+ [0]=>
+ string(%d) "%s"
+ [1]=>
+ string(2) "--"
+ [2]=>
+ string(1) "1"
+ [3]=>
+ string(1) "2"
+ [4]=>
+ string(1) "3"
+}
+[Script ended normally]
+prompt>
+--ARGS--
+1 2 3
+--FILE--
+<?php
+
+var_dump($argc, $argv);
diff --git a/sapi/phpdbg/tests/stepping_001.phpt b/sapi/phpdbg/tests/stepping_001.phpt
new file mode 100644
index 0000000000..074eeb47fa
--- /dev/null
+++ b/sapi/phpdbg/tests/stepping_001.phpt
@@ -0,0 +1,65 @@
+--TEST--
+Stepping with exceptions must not be stuck at CATCH
+--PHPDBG--
+b ZEND_THROW
+r
+s
+
+
+
+
+
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at ZEND_THROW]
+prompt> [Breakpoint #0 in ZEND_THROW at %s:4, hits: 1]
+>00004: throw new Exception;
+ 00005: }
+ 00006:
+prompt> [L0 %s HANDLE_EXCEPTION %s]
+>00004: throw new Exception;
+ 00005: }
+ 00006:
+prompt> [L0 %s HANDLE_EXCEPTION %s]
+[L9 %s CATCH "Exception" $e 1 %s]
+>00008: foo();
+ 00009: } catch (Exception $e) {
+ 00010: echo "ok";
+prompt> [L10 %s ECHO "ok" %s]
+>00010: echo "ok";
+ 00011: } finally {
+ 00012: echo " ... ok";
+prompt> ok
+[L10 %s FAST_CALL J8 ~%d %s]
+[L12 %s ECHO " ... ok" %s]
+>00012: echo " ... ok";
+ 00013: }
+ 00014:
+prompt> ... ok
+[L12 %s FAST_RET ~%d %s]
+[L10 %s JMP J10 %s]
+>00010: echo "ok";
+ 00011: } finally {
+ 00012: echo " ... ok";
+prompt> [L12 %s RETURN 1 %s]
+>00012: echo " ... ok";
+ 00013: }
+ 00014:
+prompt> [Script ended normally]
+prompt>
+--FILE--
+<?php
+
+function foo() {
+ throw new Exception;
+}
+
+try {
+ foo();
+} catch (Exception $e) {
+ echo "ok";
+} finally {
+ echo " ... ok";
+}
diff --git a/sapi/phpdbg/tests/watch_001.phpt b/sapi/phpdbg/tests/watch_001.phpt
new file mode 100644
index 0000000000..1183bb0e57
--- /dev/null
+++ b/sapi/phpdbg/tests/watch_001.phpt
@@ -0,0 +1,46 @@
+--TEST--
+Test simple recursive watchpoint
+--PHPDBG--
+b 3
+r
+w r $b
+c
+
+
+
+q
+--EXPECTF--
+[Successful compilation of %s]
+prompt> [Breakpoint #0 added at %s:3]
+prompt> [Breakpoint #0 at %s:3, hits: 1]
+>00003: $a = 1;
+ 00004: $b = [$a];
+ 00005:
+prompt> [Set recursive watchpoint on $b]
+prompt> [Breaking on watchpoint $b]
+Old value:
+New value: Array ([0] => 1)
+>00006: unset($b);
+ 00007: $b = 2;
+ 00008:
+prompt> [Breaking on watchpoint $b]
+Old value inaccessible or destroyed
+New value:
+>00007: $b = 2;
+ 00008:
+prompt> [Breaking on watchpoint $b]
+Old value:
+New value: 2
+>00007: $b = 2;
+ 00008:
+prompt> [$b was removed, removing watchpoint recursively]
+[Script ended normally]
+prompt>
+--FILE--
+<?php
+
+$a = 1;
+$b = [$a];
+
+unset($b);
+$b = 2;
diff --git a/sapi/phpdbg/xml.md b/sapi/phpdbg/xml.md
new file mode 100644
index 0000000000..56dcaaa1f7
--- /dev/null
+++ b/sapi/phpdbg/xml.md
@@ -0,0 +1,651 @@
+phpdbg XML format
+=================
+
+Common attributes
+=================
+
+severity
+--------
+
+- indicates the genre of phpdbg system output
+- usually one of these values:
+ - normal
+ - notice
+ - error
+
+msgout
+------
+
+- text message output related to the xml data (e.g. &lt;intro severity="normal" help="help" msgout="To get help using phpdbg type &amp;quot;help&amp;quot; and press enter" />)
+
+req
+---
+
+- the request id, if one was passed to the last command (via -r %d, where %d is the id) (and the output is related to that message)
+
+file
+----
+
+- refers to a filename
+
+method
+------
+
+- format classname::methodname
+- refers to a method
+
+function
+--------
+
+- refers to a function
+
+symbol
+------
+
+- either function or method (is method if "::" are present)
+
+opline
+------
+
+- in hexadecimal format
+- refers to a specific pointer to a (zend_)op
+
+opcode
+------
+
+- refers to an opcode (ZEND_*)
+
+type
+----
+
+- general attribute for most errors, describes the genre of the error
+
+General tags
+============
+
+intro
+-----
+
+- appears on startup if -q flag wasn't provided as command line arg
+- before any input possibility
+- attributes may be spread over multiple tags
+- wrapped in &lt;intros> tag
+
+### attributes ###
+
+- version: current phpdbg version (as string)
+- help: command name for help
+- report: URL for bug reporting
+
+
+phpdbg
+------
+
+- general text message output from phpdbg system
+
+stream
+------
+
+- any output by PHP itself (e.g. &lt;stream type="stdout">test&lt;/stream>)
+
+### attributes ###
+
+- type: stderr or stdout
+
+php
+---
+
+- php error output
+
+### attributes ###
+
+- msg: the error message
+
+
+General error tags
+==================
+
+command
+-------
+
+- general errors about commands
+
+### possible attributes ###
+
+- type
+ - toomanyargs: more arguments than allowed
+ - noarg: argument missing
+ - wrongarg: wrong type of argument (e.g. letters instead of integer)
+ - toofewargs: not enough arguments
+ - notfound: command (or subcommand) doesn't exist
+ - ambiguous: command was ambiguous
+ - invalidcommand: command input is totally invalid
+ - (nostack: should not happen: is an internal error)
+ - (emptystack: should not happen: is an internal error)
+- command: passed command
+- subcommand: passed subcommand (present if the error is related to the subcommand)
+- expected: count of expected arguments
+- got: type of argument for type "wrongarg"
+- num: if possible, information about which parameter had a wrong argument
+
+inactive
+--------
+
+- by type
+ - op_array: nothing was yet compiled (probably because no execution context set)
+ - symbol_table: no symbol table present (not yet initiailized or already destructed)
+ - noexec: not in execution
+ - memory_manager: using the native memory manager (malloc, free, realloc) instead of e.g. the Zend MM
+ - notfound: file not found
+ - nocontext: execution context was not set (or compilation had failed)
+ - isrunning: command requires no running script
+
+
+Commands
+========
+
+export
+------
+
+- tag: &lt;exportbreakpoint />
+- usually triggered by successful export command
+- may appear when cleaning to temporary store breakpoints
+- errors by type
+ - openfailure: could not create file
+
+### attributes ###
+
+- count: number of exported breakpoints
+
+break / info break
+------------------
+
+- General tag for breakpoint creation, deletion and hits is "&lt;breakpoint />"
+
+### possible attributes ###
+
+- id: the breakpoint id (if the leave command was executed, the id has the value "leave")
+- num: the nth opline of a function/method/file
+- add: has value "success"/"fail": a brekpoint was successfully/not added
+- pending: the breakpoint is waiting for resolving (e.g. a file opline on a not yet loaded file)
+- deleted: has value "success"/"fail": a breakpoint was successfully/not deleted
+- eval: the condition on conditional breakpoints
+- file
+- opline
+- opcode
+- symbol
+- function
+- method
+- line
+
+
+- listing breakpoints always in a container element "&lt;breakpoints>"
+ - Child nodes:
+ - function
+ - method
+ - file
+ - opline
+ - methodopline
+ - functionopline
+ - fileopline
+ - evalfunction
+ - evalfunctionopline
+ - evalmethod
+ - evalmethodopline
+ - evalfile
+ - evalopline
+ - eval
+ - opcode
+ - attributes:
+ - name: name of the symbol (function/method/file/opcode)
+ - disabled: empty value if enabled, non-empty if enabled
+
+- errors (by type)
+ - exists: the breakpoint already exists
+ - maxoplines: tries to break at an opline (usedoplinenum) higher than the number of present oplines (in maxoplinenum)
+ - nomethod: method doesn't exist
+ - internalfunction: one cannot break on an opline of an internal function
+ - notregular: tries to set a breakpoint in not a regular file
+ - (invalidparameter: should not happen: is an internal error)
+
+frame
+-----
+
+- General tag for frames is "&lt;frame>"
+- always has id attribute; if it only has id attribute, it just indicates current frame number, no other elements follow
+- may contain other elements (of type &lt;arg>) when contained in &lt;backtrace> tag
+- &lt;arg> always contains a &lt;stream> element, the value of the variable
+
+### possible attributes ###
+
+- id: the frame id, current frame has id 0 (frames with internal function calls have the same id than their called frame)
+- symbol ("{main}" is root frame)
+- file
+- line
+- internal: has value "internal" when being an internal function call (one cannot inspect that frame)
+
+- being an error: (by type)
+ - maxnum: tried to access a frame with a number higher than existing (or &lt; 0)
+
+### attributes on &lt;arg> ###
+
+- variadic: has a non-empty value if the argument is variadic
+- name: variable name of parameter
+
+info (subcommands)
+------------------
+
+### break ###
+
+- See above ("break / info break")
+
+### files ###
+
+- lists included files
+- &lt;includedfileinfo num="" /> with num having an integer value, indicating the number of included files
+- &lt;includedfile name=""/>: one per file, with name being the file path of the included file
+
+### error ###
+
+- gets last error
+- &lt;lasterror error="" (file="" line="") />
+- error attribute contains the last error as a string, is empty if there's no last error
+
+### vars / globals ###
+
+- &lt;variableinfo num="" /> with num having an integer value, indicating the number of (local or superglobal) variables
+- if info vars was used it'll have also one of these attributes:
+ - method
+ - function
+ - file
+ - opline
+- for each variable there is a &lt;variable> followed by a &lt;variabledetails> element
+- &lt;variable address="" refcount="" type="" name="" />
+ - address: pointer to zval (hexadecimal)
+ - refcount: refcount of zval
+ - type: the variable type (long, string, ...). If the value is "unknown", the other attributes are meaningless
+ - name: the name of the variable
+ - refstatus: empty if the zval is not a reference
+ - class: the class the object in the zval is an instance of
+ - resource: the type of the resource in the zval
+
+### literal ###
+
+- &lt;literalinfo num="" /> with num having an integer value, indicating the number of literals, optional arguments are:
+ - method
+ - function
+ - file
+ - opline
+- for each literal there is a &lt;literal> followed by a &lt;stream type="stdout"> which prints the value of the literal
+- &lt;literal id="" />: where id is the internal identifier of the literal
+
+### memory ###
+
+- Format:
+
+ &lt;meminfo />
+ &lt;current />
+ &lt;used mem="" />
+ &lt;real mem="" />
+ &lt;peak />
+ &lt;used mem="" />
+ &lt;real mem="" />
+
+- mem is an attribute whose value is a float. The memory is given in kilobytes (1 kB == 1024 bytes)
+
+### classes ###
+
+- &lt;classinfo num="" /> with num having an integer value, indicating the number of loaded user-defined classes
+- Each class is enumerated with first a &lt;class>, then an optional &lt;parents> container and then a &lt;classsource> element
+- The &lt;parents> container contains the &lt;class> elements of the parent of the last &lt;class> element.
+- &lt;class type="" flags="" name="" methodcount="" />
+ - type: either "User" or "Internal"
+ - flags: either "Interface", "Class" or "Abstract Class"
+- &lt;classsource /> where the class was defined, if there are no attributes, location is unknown, usually defined by
+ - file
+ - line
+
+### funcs ###
+
+- &lt;functioninfo num="" /> with num having an integer value, indicating the number of loaded user-defined functions
+- Each class is enumerated with first a &lt;function> and then a &lt;functionsource> element
+- &lt;function name="" />
+- &lt;functionsource /> where the function was defined, if there are no attributes, location is unknown, usually defined by
+ - file
+ - line
+
+list
+----
+
+- consists of &lt;line> elements wrapped in a &lt;list> container
+- &lt;list file=""> is the container element with file being the filename
+- &lt;line line="" code="" /> with value of code being the whole line of code in the line specified in the line attribute
+ - current: this attribute is set to "current" if that line is the line where the executor currently is
+
+print
+-----
+
+### without a subcommand ###
+
+- &lt;print> elements are wrapped in a &lt;printinfo> element
+- there may be a variable number of &lt;print> elements with a variable count of args inside the &lt;printinfo> element
+- possible args are:
+ - readline: yes/no - readline enabled or disabled
+ - libedit: yes/no - libedit enabled or disabled
+ - context: current executing context
+ - compiled: yes/no - are there actual compiled ops?
+ - stepping: @@ TODO (meaningless for now) @@
+ - quiet: on/off - should it always print the opline being currently executed?
+ - oplog: on/off - are oplines logged in a file?
+ - ops: number of opcodes in current executing context
+ - vars: number of compiled variables (CV)
+ - executing: yes/no - in executor?
+ - vmret: the return value of the last executed opcode
+ - default: continue
+ - 1: return from vm
+ - 2: enter stack frame
+ - 3: leave stack frame
+ - classes: number of classes
+ - functions: number of functions
+ - constants: number of constants
+ - includes: number of included files
+
+### with a subcommand ###
+
+- introduced by &lt;printinfo num="" /> (except for print opline) with num being the number of opcodes and one of these args:
+ - file
+ - method
+ - function
+ - class (then also type and flags attributes, see info classes command for their meanings)
+ - symbol (also type and flags attributes; here the value of flags is either "Method" or "Function")
+- if there is a class method, the methods are all wrapped in a &lt;printmethods> container
+- then comes a &lt;printoplineinfo type="" /> where type is either "User" or "Internal"
+- the &lt;printoplineinfo> has either a method or a function attribute
+- if the type is "Internal"
+ - there are no oplines, it's an internal method or function
+- if the type is "User"
+ - it has these attributes
+ - startline: the first line of code where the method or function is defined
+ - endline: the lastt line of code where the method or function is defined
+ - file: the file of code where the method or function is defined
+ - is followed by the oplines of that method or function (&lt;print> elements)
+- &lt;print line="%u" opline="%p" opcode="%s" op="%s" />
+- in case of print opline it emits a single &lt;opline line="" opline="" opcode="" op="" file="" />
+
+exec
+----
+
+- command executing and compiling a given file
+ - &lt;exec type="unset" context="" />: indicates unsetting of the old context
+ - &lt;exec type="unsetops" />: indicates unsetting of the old compiled opcodes
+ - &lt;exec type="unchanged" />: same execution context chosen again
+ - &lt;exec type="set" context="" />: indicates setting of the new context
+- errors by tag
+ - &lt;compile>
+ - openfailure: couldn't open file
+ - compilefailure: The file indicated in context couldn't be compiled
+ - &lt;exec>
+ - invalid: given context (attribute) is not matching a valid file or symlink
+ - notfound: given context (attribute) does not exist
+
+run / &lt;stop> tag
+-------------------
+
+- runs the script (set via exec command)
+- &lt;stop type="end" />: script execution ended normally
+- (error) &lt;stop type="bailout" /> the VM bailed out (usually because there was some error)
+- compile failures see under exec, errors, &lt;compile>
+
+step
+----
+
+- steps by one line or opcode (as defined via set stepping) default is one line
+- returns back to the executor
+
+continue
+--------
+
+- returns back to the executor
+
+until
+-----
+
+- temporarily disables all the breakpoints on that line until that line was left once
+- returns back to the executor
+
+finish
+------
+
+- temporarily disables all the breakpoints until the end of the current frame
+- returns back to the executor
+
+leave
+------
+
+- temporarily disables all the breakpoints past the end of the current frame and then stops
+- returns back to the executor
+
+back
+----
+
+- prints backtrace
+- see frame command
+
+ev
+--
+
+- eval()uates some code
+- output wrapped in &lt;eval> tags
+
+sh
+--
+
+- executes shell command
+- still pipes to stdout ... without wrapping &lt;stream> !!! (@@ TODO @@)
+
+source
+------
+
+- executes a file in .phpdbginit format
+- errors by type
+ - notfound: file not found
+
+register
+--------
+
+- registers a function to be used like a command
+- &lt;register function="" />: successfully registered function
+- errors by type
+ - notfound: no such function
+ - inuse: function already registered
+
+quit
+----
+
+- quits phpdbg
+- if successful connection will be closed...
+
+clean
+-----
+
+- cleans environment (basically a shutdown + new startup)
+- &lt;clean> tags wrapped in a &lt;cleaninfo> container
+- possible attributes of &lt;clean> tag
+ - classes: number of classes
+ - functions: number of functions
+ - constants: number of constants
+ - includes: number of included files
+
+clear
+-----
+
+- removes all breakpoints
+- &lt;clear> tags wrapped in a &lt;clearinfo> container
+- possible attributes of &lt;clear> tag (value is always the number of defined breakpoints of that type)
+ - files
+ - functions
+ - methods
+ - oplines
+ - fileoplines
+ - functionoplines
+ - methodoplines
+ - eval
+
+watch
+-----
+
+- watchpoints generally are identified by a variable (one may need to switch frames first...)
+- &lt;watch variable="" />, &lt;watchrecursive variable="" /> and &lt;watcharray variable="" /> (normal, array, recursive)
+- &lt;watch> if error, by type:
+ - undefined: tried to set a watchpoint on a not (yet) defined variable
+ - notiterable: element which is tried to be accessed as an object or array is nor array nor object
+ - invalidinput: generally malformed input
+- &lt;watchdelete variable="" />: when "watch delete" was used on a watchpoint
+- (error) &lt;watchdelete type="nowatch" />: that watchpoint doesn't exist, so couldn't be deleted
+- for hit watchpoints etc., see Other tags, &lt;watch*>
+- when using watch list, &lt;watchvariable> elements are wrapped in a &lt;watchlist> container
+ - &lt;watchvariable variable="" on="" type="" />
+ - variable: watched variable (may be a variable of another scope!)
+ - on: values are array or variable, depending on what is watched
+ - type: values are recursive or simple, depending on whether the watchpoint is checked recursively or not
+
+set
+---
+
+- a general error is type="wrongargs" where a wrong argument was passed to a subcommand; tag is then &lt;set*>
+
+### prompt ###
+
+- without other args, a &lt;setpromt str="" /> tag is emitted where the value of the str attribue is the value of the prompt
+- when there is another arg, the prompt is changed to that arg, no further xml answer
+
+### break ###
+
+- enables / disables a given breakpoint silently with no further xml answer
+- if the boolean switch is omitted, it emits current state in a &lt;setbreak id="" active="" /> where active is on or off
+- error with type="nobreak", when no breakpoint with the given id exists
+
+### breaks ###
+
+- generally enables / disables breakpoint functionality silently with no further xml answer
+- if the boolean switch is omitted, it emits current state in a &lt;setbreaks active="" /> where active is on or off
+
+### color ###
+
+- sets the color on prompt, error or notices
+- &lt;setcolor type="" color="" code="" />: code is the color code of color, type is either:
+ - prompt
+ - error
+ - notice
+- errors by type:
+ - nocolor: color doesn't exist
+ - invalidtype: type wasn't one of the three allowed types
+
+### colors ###
+
+- generally enables / disables colors silently with no further xml answer
+- if the boolean switch is omitted, it emits current state in a &lt;setcolors active="" /> where active is on or off
+
+### oplog ###
+
+- sets oplog
+- (error) &lt;setoplog type="openfailure" file="" /> when it couldn't open the passed file path
+- &lt;setoplog type="closingold" /> is emitted when there was a previous open oplog (and a file is passed)
+- if no further argument is passed, it emits current state in a &lt;setoplog active="" /> where active is on or off
+
+### quiet ###
+
+- generally enables / disables quietness silently with no further xml answer
+- if the boolean switch is omitted, it emits current state in a &lt;setquiet active="" /> where active is on or off
+
+### setpping ###
+
+- sets stepping to either opcode or line (so a step command will either advance one op or one line)
+- if no further argument is passed, it emits current state in a &lt;setoplog type="" /> where active is opcode or line
+
+### refcount ###
+
+- generally enables / disables showing of refcount in watchpoint breaks silently with no further xml answer
+- if the boolean switch is omitted, it emits current state in a &lt;setrefcount active="" /> where active is on or off
+
+wait
+----
+
+- internally executes exec, so exec will output first (if binding to socket worked)
+
+### attributes ###
+
+- import: has value "success"/"fail"
+- missingmodule/missingextension: modules/extensions loaded in the target SAPI, but not in phpdbg
+
+### errors (by type) ###
+
+- nosocket: couldn't establish socket
+- invaliddata: invalid JSON passed to socket
+
+dl
+--
+
+- loads a module or Zend extension at a given path
+- if a relative path is passed, it's relative to the extension_dir ini setting
+
+### attributes ###
+
+- extensiontype: "Zend extension" or "module"
+- name: the extension name
+- path: the path where it was loaded
+
+### errors (by type) ###
+
+- unsupported: dynamic extension loading is unsupported
+- relpath: relative path given, but no extension_dir defined
+- unknown: general error with internal DL_LOAD() (for message see msg attribute)
+- wrongapi: wrong Zend engine version (apineeded / apiinstalled attributes give information about the API versions)
+- wrongbuild: unmatched build versions (buildneeded / buildinstalled attributes give information about the build versions)
+- registerfailure: registering module failed
+- startupfailure: couldn't startup Zend extension / module
+- initfailure: couldn't initialize module
+- nophpso: passed shared object is not a valid Zend extension nor module
+
+- errors may have the module or extension attribute when their name is already known at the point of failure
+
+Other tags
+==========
+
+&lt;signal>
+-----------
+
+- received caught signal
+
+### attributes ###
+
+- type: type of signal (e.g. SIGINT)
+
+### by type ###
+
+- SIGINT: interactive mode is entered...
+
+&lt;watch*>
+-----------
+
+- generally emitted on hit watchpoint
+- &lt;watchdelete variable="" />: when a variable was unset, the watchpoint is removed too
+- &lt;watchhit variable="" />: when ever a watched variable is changed, followed by a &lt;watchdata> container
+- &lt;watchdata> may contain
+ - for watchpoints on variables:
+ - each of these &lt;watch*> tags conatins a type attribute whose value is either "old" or "new")
+ - &lt;watchvalue type="" inaccessible="inaccessible" />: old value is inaccessible
+ - &lt;watchvalue type=""> may contain a &lt;stream> element which indicates the old/new (type attribute) value of the variable
+ - &lt;watchrefcount type="" refcount="" isref="" />: old/new (type attribute) refcount and isref, both numbers
+ - isref: if the value is 0, it's not a reference, else it is one
+ - for watchpoints on arrays:
+ - &lt;watchsize> inspects size variations of an array (the sum):
+ - removed: number of elements removed
+ - added: number of elements added
+ - &lt;watcharrayptr>: if this tag appears, the internal pointer of the array way changed
+
+&lt;signalsegv>
+---------------
+
+- generally emitted when data couldn't be fetched (e.g. by accessing inconsistent data); only used in hard interrupt mode
+- it might mean that data couldn't be fetched at all, or that only incomplete data was fetched (e.g. when a fixed number of following attributes are fetched, this tag will mark a stop of fetching if none or not all tags were printed)