Skip to content

Commit

Permalink
Split out base globals into their own file/struct
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Oct 7, 2021
1 parent 1fda048 commit 9f167b9
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 43 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Mon, Oct 04, 2021 - Xdebug 3.1.0
<dir name="base">
<file name="base.c" role="src" />
<file name="base.h" role="src" />
<file name="base_globals.h" role="src" />
<file name="base_private.h" role="src" />
<file name="filter.c" role="src" />
<file name="filter.h" role="src" />
Expand Down
45 changes: 5 additions & 40 deletions php_xdebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
# include "config.h"
#endif

#include "base/base_globals.h"
#include "coverage/branch_info.h"
#include "coverage/code_coverage.h"
#include "debugger/debugger.h"
Expand Down Expand Up @@ -75,46 +76,9 @@ ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xdebug);

int xdebug_is_output_tty();

struct xdebug_base_info {
xdebug_vector *stack;
#if PHP_VERSION_ID >= 80100
xdebug_hash *fiber_stacks;
#endif
xdebug_nanotime_context nanotime_context;
uint64_t start_nanotime;
unsigned int prev_memory;
zif_handler orig_set_time_limit_func;
zif_handler orig_error_reporting_func;
zif_handler orig_pcntl_exec_func;
zif_handler orig_pcntl_fork_func;
int output_is_tty;
zend_bool in_debug_info;
zend_long error_reporting_override;
zend_bool error_reporting_overridden;
unsigned int function_count;
zend_string *last_eval_statement;
char *last_exception_trace;

/* in-execution checking */
zend_bool in_execution;
zend_bool in_var_serialisation;

/* filters */
zend_long filter_type_code_coverage;
zend_long filter_type_stack;
zend_long filter_type_tracing;
xdebug_llist *filters_code_coverage;
xdebug_llist *filters_stack;
xdebug_llist *filters_tracing;

struct {
zend_long max_nesting_level;
} settings;
};

ZEND_BEGIN_MODULE_GLOBALS(xdebug)
struct xdebug_base_info base;
struct {
xdebug_base_globals_t base;
xdebug_coverage_globals_t coverage;
xdebug_debugger_globals_t debugger;
xdebug_develop_globals_t develop;
Expand All @@ -124,6 +88,7 @@ ZEND_BEGIN_MODULE_GLOBALS(xdebug)
xdebug_tracing_globals_t tracing;
} globals;
struct {
xdebug_base_settings_t base;
xdebug_coverage_settings_t coverage;
xdebug_debugger_settings_t debugger;
xdebug_develop_settings_t develop;
Expand All @@ -140,7 +105,7 @@ ZEND_END_MODULE_GLOBALS(xdebug)
#define XG(v) (xdebug_globals.v)
#endif

#define XG_BASE(v) (XG(base.v))
#define XINI_BASE(v) (XG(base.settings.v))
#define XG_BASE(v) (XG(globals.base.v))
#define XINI_BASE(v) (XG(settings.base.v))

#endif
62 changes: 62 additions & 0 deletions src/base/base_globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
+----------------------------------------------------------------------+
| Xdebug |
+----------------------------------------------------------------------+
| Copyright (c) 2002-2021 Derick Rethans |
+----------------------------------------------------------------------+
| This source file is subject to version 1.01 of the Xdebug license, |
| that is bundled with this package in the file LICENSE, and is |
| available at through the world-wide-web at |
| https://xdebug.org/license.php |
| If you did not receive a copy of the Xdebug license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/

#ifndef __XDEBUG_BASE_GLOBALS_H__
#define __XDEBUG_BASE_GLOBALS_H__

#include "lib/hash.h"
#include "lib/llist.h"
#include "lib/timing.h"
#include "lib/vector.h"

typedef struct _xdebug_base_globals_t {
xdebug_vector *stack;
#if PHP_VERSION_ID >= 80100
xdebug_hash *fiber_stacks;
#endif
xdebug_nanotime_context nanotime_context;
uint64_t start_nanotime;
unsigned int prev_memory;
zif_handler orig_set_time_limit_func;
zif_handler orig_error_reporting_func;
zif_handler orig_pcntl_exec_func;
zif_handler orig_pcntl_fork_func;
int output_is_tty;
zend_bool in_debug_info;
zend_long error_reporting_override;
zend_bool error_reporting_overridden;
unsigned int function_count;
zend_string *last_eval_statement;
char *last_exception_trace;

/* in-execution checking */
zend_bool in_execution;
zend_bool in_var_serialisation;

/* filters */
zend_long filter_type_code_coverage;
zend_long filter_type_stack;
zend_long filter_type_tracing;
xdebug_llist *filters_code_coverage;
xdebug_llist *filters_stack;
xdebug_llist *filters_tracing;
} xdebug_base_globals_t;

typedef struct _xdebug_base_settings_t {
zend_long max_nesting_level;
} xdebug_base_settings_t;

#endif // __XDEBUG_BASE_GLOBALS_H__
1 change: 1 addition & 0 deletions src/lib/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define __XDEBUG_VECTOR_H__

#include <stddef.h>
#include "mm.h"

typedef void (*xdebug_vector_dtor)(void *);

Expand Down
6 changes: 3 additions & 3 deletions xdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("xdebug.var_display_max_depth", "3", PHP_INI_ALL, OnUpdateLong, settings.library.display_max_depth, zend_xdebug_globals, xdebug_globals)

/* Base settings */
STD_PHP_INI_ENTRY("xdebug.max_nesting_level", "256", PHP_INI_ALL, OnUpdateLong, base.settings.max_nesting_level, zend_xdebug_globals, xdebug_globals)
STD_PHP_INI_ENTRY("xdebug.max_nesting_level", "256", PHP_INI_ALL, OnUpdateLong, settings.base.max_nesting_level, zend_xdebug_globals, xdebug_globals)

/* Develop settings */
STD_PHP_INI_ENTRY("xdebug.cli_color", "0", PHP_INI_ALL, OnUpdateLong, settings.develop.cli_color, zend_xdebug_globals, xdebug_globals)
Expand Down Expand Up @@ -384,7 +384,7 @@ PHP_INI_BEGIN()
XDEBUG_CHANGED_INI_ENTRY(xdebug.trace_enable_trigger_value)
PHP_INI_END()

static void xdebug_init_base_globals(struct xdebug_base_info *xg)
static void xdebug_init_base_globals(xdebug_base_globals_t *xg)
{
xg->stack = NULL;
xg->in_debug_info = 0;
Expand All @@ -407,7 +407,7 @@ static void php_xdebug_init_globals(zend_xdebug_globals *xg)
memset(&xg->globals, 0, sizeof(xg->globals));

xdebug_init_library_globals(&xg->globals.library);
xdebug_init_base_globals(&xg->base);
xdebug_init_base_globals(&xg->globals.base);

if (XDEBUG_MODE_IS(XDEBUG_MODE_COVERAGE)) {
xdebug_init_coverage_globals(&xg->globals.coverage);
Expand Down

0 comments on commit 9f167b9

Please sign in to comment.