From: Bob Weinand <bobwei9@hotmail.com>
Date: Tue, 23 Sep 2014 14:48:37 +0000 (+0200)
Subject: Add info globals command
X-Git-Tag: php-5.6.3RC1~51^2~73
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=92fe2d0a85ab831b01e2de9802da1753c144b808;p=php

Add info globals command
---

diff --git a/phpdbg_help.c b/phpdbg_help.c
index 3244b653ef..57d70c3581 100644
--- a/phpdbg_help.c
+++ b/phpdbg_help.c
@@ -646,6 +646,7 @@ phpdbg_help_text_t phpdbg_help_text[] = {
 "  **funcs**    **f**      show loaded classes" CR
 "  **error**    **e**      show last error" 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"
 },
diff --git a/phpdbg_info.c b/phpdbg_info.c
index 97f88bfa1e..a783bf44fc 100644
--- a/phpdbg_info.c
+++ b/phpdbg_info.c
@@ -37,6 +37,7 @@ const phpdbg_command_t phpdbg_info_commands[] = {
 	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(globals,  "show superglobals",             'g', info_globals, 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_END_COMMAND
@@ -86,9 +87,16 @@ PHPDBG_INFO(error) /* {{{ */
 	return SUCCESS;
 } /* }}} */
 
-PHPDBG_INFO(vars) /* {{{ */
-{
-	HashTable vars;
+static int phpdbg_arm_auto_global(zend_auto_global *auto_global TSRMLS_DC) {
+	if (auto_global->armed) {
+		auto_global->armed = auto_global->auto_global_callback(auto_global->name, auto_global->name_len TSRMLS_CC);
+	}
+
+	return 0;
+}
+
+static int phpdbg_print_symbols(zend_bool show_globals TSRMLS_DC) {
+	HashTable vars, *symtable;
 	HashPosition pos;
 	char *var;
 	zval **data;
@@ -107,22 +115,31 @@ PHPDBG_INFO(vars) /* {{{ */
 		}
 	}
 
+
+	if (show_globals) {
+		zend_hash_apply(CG(auto_globals), (apply_func_t) phpdbg_arm_auto_global TSRMLS_CC);
+		symtable = &EG(symbol_table);
+	} else {
+		symtable = EG(active_symbol_table);
+	}
+
 	zend_hash_init(&vars, 8, NULL, NULL, 0);
 
-	zend_hash_internal_pointer_reset_ex(EG(active_symbol_table), &pos);
-	while (zend_hash_get_current_key_ex(EG(active_symbol_table), &var,
+	zend_hash_internal_pointer_reset_ex(symtable, &pos);
+	while (zend_hash_get_current_key_ex(symtable, &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_get_current_data_ex(symtable, (void **)&data, &pos);
+		if (zend_is_auto_global(var, strlen(var) TSRMLS_CC) ^ !show_globals) {
+			zend_hash_update(&vars, var, strlen(var)+1, (void**)data, sizeof(zval*), NULL);
 		}
-		zend_hash_move_forward_ex(EG(active_symbol_table), &pos);
+		zend_hash_move_forward_ex(symtable, &pos);
 	}
 
-	{
+	if (show_globals) {
+		phpdbg_notice("Superglobal variables (%d)", zend_hash_num_elements(&vars));
+	} else {
 		zend_op_array *ops = EG(active_op_array);
-		
+
 		if (ops->function_name) {
 			if (ops->scope) {
 				phpdbg_notice(
@@ -204,6 +221,16 @@ PHPDBG_INFO(vars) /* {{{ */
 	return SUCCESS;
 } /* }}} */
 
+PHPDBG_INFO(vars) /* {{{ */
+{
+	return phpdbg_print_symbols(0 TSRMLS_CC);
+}
+
+PHPDBG_INFO(globals) /* {{{ */
+{
+	return phpdbg_print_symbols(1 TSRMLS_CC);
+}
+
 PHPDBG_INFO(literal) /* {{{ */
 {
 	if ((EG(in_execution) && EG(active_op_array)) || PHPDBG_G(ops)) {
diff --git a/phpdbg_info.h b/phpdbg_info.h
index c36e6bebd6..6930cdd824 100644
--- a/phpdbg_info.h
+++ b/phpdbg_info.h
@@ -31,6 +31,7 @@ PHPDBG_INFO(classes);
 PHPDBG_INFO(funcs);
 PHPDBG_INFO(error);
 PHPDBG_INFO(vars);
+PHPDBG_INFO(globals);
 PHPDBG_INFO(literal);
 PHPDBG_INFO(memory);