php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #71234
Patch bug71234.patch revision 2015-12-30 02:52 UTC by laruence@php.net

Patch bug71234.patch for phpdbg Bug #71234

Patch version 2015-12-30 02:52 UTC

Return to Bug #71234 | Download this patch
Patch Revisions:

Developer: laruence@php.net

diff --git a/sapi/phpdbg/phpdbg.c b/sapi/phpdbg/phpdbg.c
index 39279c4..49f8dd1 100644
--- a/sapi/phpdbg/phpdbg.c
+++ b/sapi/phpdbg/phpdbg.c
@@ -1504,33 +1504,13 @@ phpdbg_main:
 			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;
+				flags |= PHPDBG_DO_HELP;
 			} break;
 
-			case 'V': {
-				sapi_startup(phpdbg);
-				phpdbg->startup(phpdbg);
-				printf(
-					"phpdbg %s (built: %s %s)\nPHP %s, Copyright (c) 1997-2015 The PHP Group\n%s",
-					PHPDBG_VERSION,
-					__DATE__,
-					__TIME__,
-					PHP_VERSION,
-					get_zend_version()
-				);
-				sapi_deactivate();
-				sapi_shutdown();
-				return 0;
-			} break;
+			case 'V':
+				flags |= PHPDBG_DO_VERSION;
+			 break;
 		}
 
 		php_optarg = NULL;
@@ -1594,424 +1574,448 @@ phpdbg_main:
 	phpdbg->ini_entries = ini_entries;
 
 	if (phpdbg->startup(phpdbg) == SUCCESS) {
-		zend_mm_heap *mm_heap;
+		if ((flags & (PHPDBG_DO_VERSION|PHPDBG_DO_HELP)) == 0) {
+			zend_mm_heap *mm_heap;
 #ifdef _WIN32
-    EXCEPTION_POINTERS *xp;
-    __try {
+			EXCEPTION_POINTERS *xp;
+			__try {
 #endif
-		void* (*_malloc)(size_t);
-		void (*_free)(void*);
-		void* (*_realloc)(void*, size_t);
+				void* (*_malloc)(size_t);
+				void (*_free)(void*);
+				void* (*_realloc)(void*, size_t);
 
-		/* set flags from command line */
-		PHPDBG_G(flags) = flags;
+				/* set flags from command line */
+				PHPDBG_G(flags) = flags;
 
-		if (settings > (zend_phpdbg_globals *) 0x2) {
+				if (settings > (zend_phpdbg_globals *) 0x2) {
 #ifdef ZTS
-			*((zend_phpdbg_globals *) (*((void ***) TSRMLS_CACHE))[TSRM_UNSHUFFLE_RSRC_ID(phpdbg_globals_id)]) = *settings;
+					*((zend_phpdbg_globals *) (*((void ***) TSRMLS_CACHE))[TSRM_UNSHUFFLE_RSRC_ID(phpdbg_globals_id)]) = *settings;
 #else
-			phpdbg_globals = *settings;
+					phpdbg_globals = *settings;
 #endif
-			free(settings);
-		}
+					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);
-			}
+				/* 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);
+					sigaction(SIGIO, &sigio_struct, NULL);
 #endif
 
-			/* set remote flag to stop service shutting down upon quit */
-			remote = 1;
+					/* set remote flag to stop service shutting down upon quit */
+					remote = 1;
 #ifndef _WIN32
-		} else {
+				} else {
 
-			signal(SIGHUP, phpdbg_sighup_handler);
+					signal(SIGHUP, phpdbg_sighup_handler);
 #endif
-		}
+				}
 
-		mm_heap = zend_mm_get_heap();
-		zend_mm_get_custom_handlers(mm_heap, &_malloc, &_free, &_realloc);
+				mm_heap = zend_mm_get_heap();
+				zend_mm_get_custom_handlers(mm_heap, &_malloc, &_free, &_realloc);
 
-		use_mm_wrappers = !_malloc && !_realloc && !_free;
+				use_mm_wrappers = !_malloc && !_realloc && !_free;
 
-		phpdbg_init_list();
+				phpdbg_init_list();
 
-		PHPDBG_G(original_free_function) = _free;
-		_free = phpdbg_watch_efree;
+				PHPDBG_G(original_free_function) = _free;
+				_free = phpdbg_watch_efree;
 
-		if (use_mm_wrappers) {
+				if (use_mm_wrappers) {
 #if ZEND_DEBUG
-			zend_mm_set_custom_debug_handlers(mm_heap, phpdbg_malloc_wrapper, phpdbg_free_wrapper, phpdbg_realloc_wrapper);
+					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);
+					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);
-		}
+				} else {
+					zend_mm_set_custom_handlers(mm_heap, _malloc, _free, _realloc);
+				}
 
-		phpdbg_setup_watchpoints();
+				phpdbg_setup_watchpoints();
 
 #if defined(ZEND_SIGNALS) && !defined(_WIN32)
-		zend_try {
-			zend_signal_activate();
-		} zend_end_try();
+				zend_try {
+					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)); } zend_end_try();
-		zend_try { zend_sigaction(SIGBUS, &signal_struct, &PHPDBG_G(old_sigsegv_signal)); } 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));
+				sigaction(SIGSEGV, &signal_struct, &PHPDBG_G(old_sigsegv_signal));
+				sigaction(SIGBUS, &signal_struct, &PHPDBG_G(old_sigsegv_signal));
 #endif
 
-		PHPDBG_G(sapi_name_ptr) = sapi_name;
+				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;
+				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;
-		}
+					free(exec);
+					exec = NULL;
+				}
 
-		php_output_activate();
-		php_output_deactivate();
+				php_output_activate();
+				php_output_deactivate();
 
-		if (SG(sapi_headers).mimetype) {
-			efree(SG(sapi_headers).mimetype);
-			SG(sapi_headers).mimetype = NULL;
-		}
+				if (SG(sapi_headers).mimetype) {
+					efree(SG(sapi_headers).mimetype);
+					SG(sapi_headers).mimetype = NULL;
+				}
 
-		php_output_activate();
+				php_output_activate();
 
-		{
-			int i;
+				{
+					int i;
 
-			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[0] = PHPDBG_G(exec) ? estrdup(PHPDBG_G(exec)) : estrdup("");
-		}
+					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[0] = PHPDBG_G(exec) ? estrdup(PHPDBG_G(exec)) : estrdup("");
+				}
 
-		if (php_request_startup() == FAILURE) {
-			PUTS("Could not startup");
-			return 1;
-		}
+				if (php_request_startup() == FAILURE) {
+					PUTS("Could not startup");
+					return 1;
+				}
 
-		/* do not install sigint handlers for remote consoles */
-		/* sending SIGINT then provides a decent way of shutting down the server */
+				/* 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) {
+				if (listen < 0) {
 #endif
 #if defined(ZEND_SIGNALS) && !defined(_WIN32)
-			zend_try { zend_signal(SIGINT, phpdbg_sigint_handler); } zend_end_try();
+					zend_try { zend_signal(SIGINT, phpdbg_sigint_handler); } zend_end_try();
 #else
-			signal(SIGINT, phpdbg_sigint_handler);
+					signal(SIGINT, phpdbg_sigint_handler);
 #endif
 #ifndef _WIN32
-		}
+				}
 
-		/* setup io here */
-		if (remote) {
-			PHPDBG_G(flags) |= PHPDBG_IS_REMOTE;
+				/* setup io here */
+				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);
+					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);
-		}
+				/* 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_STDERR].ptr = stderr;
+				PHPDBG_G(io)[PHPDBG_STDERR].fd = fileno(stderr);
 
 #ifndef _WIN32
-		PHPDBG_G(php_stdiop_write) = php_stream_stdio_ops.write;
-		php_stream_stdio_ops.write = phpdbg_stdiop_write;
+				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("oplog", "path=\"%s\"", "Failed to open oplog %s", oplog_file);
-			}
-			free(oplog_file);
-			oplog_file = NULL;
-		}
+				if (oplog_file) { /* open oplog */
+					PHPDBG_G(oplog) = fopen(oplog_file, "w+");
+					if (!PHPDBG_G(oplog)) {
+						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"));
-		phpdbg_set_color_ex(PHPDBG_COLOR_ERROR,   PHPDBG_STRL("red-bold"));
-		phpdbg_set_color_ex(PHPDBG_COLOR_NOTICE,  PHPDBG_STRL("green"));
+				/* set default colors */
+				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(PHPDBG_DEFAULT_PROMPT);
+				/* set default prompt */
+				phpdbg_set_prompt(PHPDBG_DEFAULT_PROMPT);
 
-		/* Make stdin, stdout and stderr accessible from PHP scripts */
-		phpdbg_register_file_handles();
+				/* Make stdin, stdout and stderr accessible from PHP scripts */
+				phpdbg_register_file_handles();
 
-		phpdbg_list_update();
+				phpdbg_list_update();
 
-		if (show_banner && cleaning < 2) {
-			/* print blurb */
-			phpdbg_welcome(cleaning == 1);
-		}
+				if (show_banner && cleaning < 2) {
+					/* print blurb */
+					phpdbg_welcome(cleaning == 1);
+				}
 
-		cleaning = -1;
+				cleaning = -1;
 
-		if (ext_stmt) {
-			CG(compiler_options) |= ZEND_COMPILE_EXTENDED_INFO;
-		}
+				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);
-			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;
+				/* initialize from file */
+				PHPDBG_G(flags) |= PHPDBG_IS_INITIALIZING;
+				zend_try {
+					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;
-		}
+				/* quit if init says so */
+				if (PHPDBG_G(flags) & PHPDBG_IS_QUITTING) {
+					goto phpdbg_out;
+				}
 
-		/* auto compile */
-		if (PHPDBG_G(exec)) {
-			if (settings || phpdbg_startup_run > 0) {
-				PHPDBG_G(flags) |= PHPDBG_DISCARD_OUTPUT;
-			}
+				/* 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();
+					zend_try {
+						phpdbg_compile();
+					} zend_end_try();
 
-			PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT;
-		}
+					PHPDBG_G(flags) &= ~PHPDBG_DISCARD_OUTPUT;
+				}
 
-		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;
-		}
+				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;
+				PG(during_request_startup) = 0;
 
-		phpdbg_fully_started = 1;
+				phpdbg_fully_started = 1;
 
-/* #ifndef for making compiler shutting up */
+				/* #ifndef for making compiler shutting up */
 #ifndef _WIN32
 phpdbg_interact:
 #endif
-		/* phpdbg main() */
-		do {
-			zend_try {
-				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;
-					}
+				/* phpdbg main() */
+				do {
 					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;
-					}
-				}
+						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)) {
-					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;
-				}
+						CG(unclean_shutdown) = 0;
+						phpdbg_interactive(1);
+					} zend_catch {
+						if ((PHPDBG_G(flags) & PHPDBG_IS_CLEANING)) {
+							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;
+						}
 
 #ifndef _WIN32
-				if (!cleaning) {
-					/* remote client disconnected */
-					if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) {
-
-						if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) {
-							/* renegociate connections */
-							phpdbg_remote_init(address, listen, server, &socket, &stream);
-
-							/* set streams */
-							if (stream) {
-								PHPDBG_G(flags) &= ~PHPDBG_IS_QUITTING;
+						if (!cleaning) {
+							/* remote client disconnected */
+							if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) {
+
+								if (PHPDBG_G(flags) & PHPDBG_IS_REMOTE) {
+									/* renegociate connections */
+									phpdbg_remote_init(address, listen, server, &socket, &stream);
+
+									/* set streams */
+									if (stream) {
+										PHPDBG_G(flags) &= ~PHPDBG_IS_QUITTING;
+									}
+
+									/* this must be forced */
+									CG(unclean_shutdown) = 0;
+								} else {
+									/* local consoles cannot disconnect, ignore EOF */
+									PHPDBG_G(flags) &= ~PHPDBG_IS_DISCONNECTED;
+								}
 							}
-
-							/* this must be forced */
-							CG(unclean_shutdown) = 0;
-						} else {
-							/* local consoles cannot disconnect, ignore EOF */
-							PHPDBG_G(flags) &= ~PHPDBG_IS_DISCONNECTED;
 						}
-					}
-				}
 #endif
-			} zend_end_try();
-		} while (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING));
+					} zend_end_try();
+				} while (!(PHPDBG_G(flags) & PHPDBG_IS_STOPPING));
 
 
 #ifndef _WIN32
 phpdbg_out:
-		if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) {
-			PHPDBG_G(flags) &= ~PHPDBG_IS_DISCONNECTED;
-			goto phpdbg_interact;
-		}
+				if ((PHPDBG_G(flags) & PHPDBG_IS_DISCONNECTED)) {
+					PHPDBG_G(flags) &= ~PHPDBG_IS_DISCONNECTED;
+					goto phpdbg_interact;
+				}
 #endif
 
 #ifdef _WIN32
-	} __except(phpdbg_exception_handler_win32(xp = GetExceptionInformation())) {
-		phpdbg_error("segfault", "", "Access violation (Segmentation fault) encountered\ntrying to abort cleanly...");
-	}
+			} __except(phpdbg_exception_handler_win32(xp = GetExceptionInformation())) {
+				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;
-		}
+			if (cleaning <= 0) {
+				PHPDBG_G(flags) &= ~PHPDBG_IS_CLEANING;
+				cleaning = -1;
+			}
 
-		{
-			int i;
-			/* free argv */
-			for (i = SG(request_info).argc; i--;) {
-				efree(SG(request_info).argv[i]);
+			{
+				int i;
+				/* free argv */
+				for (i = SG(request_info).argc; i--;) {
+					efree(SG(request_info).argv[i]);
+				}
+				efree(SG(request_info).argv);
 			}
-			efree(SG(request_info).argv);
-		}
 
-		if (ini_entries) {
-			free(ini_entries);
-		}
+			if (ini_entries) {
+				free(ini_entries);
+			}
 
-		if (ini_override) {
-			free(ini_override);
-		}
+			if (ini_override) {
+				free(ini_override);
+			}
 
-		/* 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);
-		}
+			/* 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));
-		}
+			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));
+			/* backup globals when cleaning */
+			if ((cleaning > 0 || remote) && !quit_immediately) {
+				settings = calloc(1, sizeof(zend_phpdbg_globals));
 
-			php_phpdbg_globals_ctor(settings);
+				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]);
+				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();
+			/* 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 (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++;
+			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();
+			php_output_deactivate();
 
-		zend_try {
-			php_module_shutdown();
-		} zend_end_try();
+			zend_try {
+				php_module_shutdown();
+			} zend_end_try();
 
 #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);
+			/* 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();
+			sapi_shutdown();
+		} else {
+			if ((flags & PHPDBG_DO_VERSION) == PHPDBG_DO_VERSION) {
+				printf(
+						"phpdbg %s (built: %s %s)\nPHP %s, Copyright (c) 1997-2015 The PHP Group\n%s",
+						PHPDBG_VERSION,
+						__DATE__,
+						__TIME__,
+						PHP_VERSION,
+						get_zend_version()
+					  ); 
+			} else {
+				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();
+		}
 	}
 
 	if ((cleaning > 0 || remote) && !quit_immediately) {
diff --git a/sapi/phpdbg/phpdbg.h b/sapi/phpdbg/phpdbg.h
index 63b05cd..56666f8 100644
--- a/sapi/phpdbg/phpdbg.h
+++ b/sapi/phpdbg/phpdbg.h
@@ -197,6 +197,9 @@ int phpdbg_do_parse(phpdbg_param_t *stack, char *input);
 
 #define PHPDBG_HAS_PAGINATION         (1ULL<<36)
 
+#define PHPDBG_DO_VERSION             (1ULL<<37)
+#define PHPDBG_DO_HELP                (1ULL<<38)
+
 #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)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 12:01:29 2024 UTC