Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Compile
run: |
phpize
./configure --enable-php-debugger
./configure --enable-php-debugger-dev
make -j$(nproc)

- name: Find PHP
Expand Down
8 changes: 5 additions & 3 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ dnl config.m4 for extension PHP Debugger (based on Xdebug)

PHP_ARG_ENABLE(php-debugger, whether to enable PHP Debugger support,
[ --enable-php-debugger Enable PHP Debugger support])
PHP_ARG_ENABLE(xdebug-dev, whether to enable PHP Debugger developer build flags,
[ --enable-xdebug-dev PHP Debugger: Enable developer flags],, no)
PHP_ARG_ENABLE(php-debugger-dev, whether to enable PHP Debugger developer build flags,
[ --enable-php-debugger-dev PHP Debugger: Enable developer flags],, no)



Expand Down Expand Up @@ -53,7 +53,7 @@ if test "$PHP_PHP_DEBUGGER" != "no"; then

CPPFLAGS=$old_CPPFLAGS

if test "$PHP_XDEBUG_DEV" = "yes"; then
if test "$PHP_PHP_DEBUGGER_DEV" = "yes"; then
AX_CHECK_COMPILE_FLAG(-Wbool-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wbool-conversion")
AX_CHECK_COMPILE_FLAG(-Wdeclaration-after-statement, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wdeclaration-after-statement")
AX_CHECK_COMPILE_FLAG(-Wdiscarded-qualifiers, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wdiscarded-qualifiers")
Expand Down Expand Up @@ -85,6 +85,8 @@ if test "$PHP_PHP_DEBUGGER" != "no"; then
AX_CHECK_COMPILE_FLAG(-Wstring-conversion, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wstring-conversion")
AX_CHECK_COMPILE_FLAG(-Wwrite-strings, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wwrite-strings")
AX_CHECK_COMPILE_FLAG(-Wpointer-arith, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wpointer-arith")
AX_CHECK_COMPILE_FLAG(-Wstrict-prototypes, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wstrict-prototypes")
AX_CHECK_COMPILE_FLAG(-Wold-style-definition, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -Wold-style-definition")
AX_CHECK_COMPILE_FLAG(-fdiagnostics-show-option, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fdiagnostics-show-option")
AX_CHECK_COMPILE_FLAG(-fno-exceptions, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fno-exceptions")
AX_CHECK_COMPILE_FLAG(-fno-omit-frame-pointer, _MAINTAINER_CFLAGS="$_MAINTAINER_CFLAGS -fno-omit-frame-pointer")
Expand Down
2 changes: 1 addition & 1 deletion php_xdebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ PHP_RSHUTDOWN_FUNCTION(xdebug);
PHP_MINFO_FUNCTION(xdebug);
ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xdebug);

int xdebug_is_output_tty();
int xdebug_is_output_tty(void);

ZEND_BEGIN_MODULE_GLOBALS(xdebug)
struct {
Expand Down
283 changes: 6 additions & 277 deletions src/base/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,277 +329,6 @@ void xdebug_build_fname(xdebug_func *tmp, zend_execute_data *edata)
#define NO_VARIADIC INT_MAX
#define DEBUG 0

static void collect_params_internal(function_stack_entry *fse, zend_execute_data *zdata, zend_op_array *op_array)
{
int i;
int is_variadic = !!(zdata->func->common.fn_flags & ZEND_ACC_VARIADIC);
int is_trampoline = !!(zdata->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE);
int variadic_at_pos = NO_VARIADIC;
int variadic_sensitive = 0;
int names_expected = 0;
int arguments_sent = 0;
int arguments_storage = 0;

arguments_sent = ZEND_CALL_NUM_ARGS(zdata);
if (arguments_sent > USHRT_MAX) {
return;
}

names_expected = zdata->func->internal_function.num_args;
if (names_expected > arguments_sent) {
names_expected = arguments_sent;
}
#if DEBUG
fprintf(stderr, "\nF: %s\n - CALL_NUM_ARGS: %d, op_array->num_args: %d, is_variadic: %d, trampoline: %d\n", fse->function.function, ZEND_CALL_NUM_ARGS(zdata), op_array->num_args, is_variadic, is_trampoline);
#endif

/* If this function is variadic, we have an extra name field in arg_info, and also an extra
* argument sent to the function. */
if (is_variadic && !is_trampoline) {
names_expected++;
}

/* Pick the highest of "expected arguments" and "arguments given" (also
* taking into account the extra one for variadics */
if (names_expected > arguments_sent) {
arguments_storage = names_expected;
} else {
arguments_storage = arguments_sent;
}

fse->varc = arguments_storage;
fse->var = xdmalloc(fse->varc * sizeof(xdebug_var_name));

#if DEBUG
fprintf(stderr, " - names_expected: %d, arguments_sent: %d, arguments_storage: %d, fse->varc: %d\n", names_expected, arguments_sent, arguments_storage, fse->varc);
#endif

/* Initialise everything in storage */
for (i = 0; i < fse->varc; i++) {
fse->var[i].name = NULL;
ZVAL_UNDEF(&fse->var[i].data);
fse->var[i].is_variadic = 0;
}

/* Collect Names */
for (i = 0; i < names_expected; i++) {
if (op_array->arg_info[i].name) {
#if PHP_VERSION_ID >= 80600
fse->var[i].name = zend_string_copy(zdata->func->internal_function.arg_info[i].name);
#else
fse->var[i].name = zend_string_init(
zdata->func->internal_function.arg_info[i].name,
strlen(zdata->func->internal_function.arg_info[i].name),
0
);
#endif

/* If an argument is a variadic, then we mark that on this 'name',
* and also remember which position the variadic started */
if (ZEND_ARG_IS_VARIADIC(&op_array->arg_info[i]) && variadic_at_pos == NO_VARIADIC) {
fse->var[i].is_variadic = 1;
variadic_at_pos = i;
}
}
}

/* Collect Arguments */
for (i = 0; i < arguments_sent; i++) {
#if PHP_VERSION_ID >= 80200
zend_attribute *attribute;
#else
void *attribute = NULL;
#endif

/* The index in ZEND_CALL_ARG is 1-based */
#if DEBUG
fprintf(stderr, "Copying argument %d\n", i);
#endif
#if PHP_VERSION_ID >= 80200
attribute = zend_get_parameter_attribute_str(
zdata->func->common.attributes,
"sensitiveparameter",
sizeof("sensitiveparameter") - 1,
i
);
#endif
if (attribute && fse->var[i].is_variadic) {
variadic_sensitive = 1;
}
# if DEBUG
fprintf(stderr, "SENSTIVIVE %d ", attribute != NULL);
# endif

if ((variadic_sensitive || attribute != NULL) && !fse->var[i].is_variadic) {
ZVAL_STRING(&(fse->var[i].data), "[Sensitive Parameter]");
} else {
ZVAL_COPY(&(fse->var[i].data), ZEND_CALL_ARG(zdata, i + 1));
}
#if DEBUG
fprintf(stderr, "OK\n");
#endif
}

if (ZEND_CALL_INFO(zdata) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
zend_string *name;
zval *param;
int i = fse->varc;

fse->varc += zend_hash_num_elements(zdata->extra_named_params);
fse->var = xdrealloc(fse->var, fse->varc * sizeof(xdebug_var_name));

ZEND_HASH_FOREACH_STR_KEY_VAL(zdata->extra_named_params, name, param) {
fse->var[i].name = zend_string_copy(name);
ZVAL_COPY(&(fse->var[i].data), param);
fse->var[i].is_variadic = 0;
i++;
} ZEND_HASH_FOREACH_END();
}

#if DEBUG
for (i = 0; i < fse->varc; i++) {
fprintf(stderr, "%2d %-20s %c %s\n", i, fse->var[i].name ? ZSTR_VAL(fse->var[i].name) : "---", fse->var[i].is_variadic ? 'V' : ' ', xdebug_get_zval_value_line(&fse->var[i].data, 0, NULL)->d);
}
#endif
}

static void collect_params(function_stack_entry *fse, zend_execute_data *zdata, zend_op_array *op_array)
{
int i;
int is_variadic = !!(zdata->func->common.fn_flags & ZEND_ACC_VARIADIC);
int is_trampoline = !!(zdata->func->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE);
int variadic_at_pos = NO_VARIADIC;
int variadic_sensitive = 0;
int names_expected = 0;
int arguments_sent = 0;
int arguments_storage = 0;

arguments_sent = ZEND_CALL_NUM_ARGS(zdata);

/* The op_array contains the number of * (named) arguments. */
names_expected = op_array->num_args;

#if DEBUG
fprintf(stderr, "\nF: %s\n - CALL_NUM_ARGS: %d, op_array->num_args: %d, is_variadic: %d, trampoline: %d\n", fse->function.function, ZEND_CALL_NUM_ARGS(zdata), op_array->num_args, is_variadic, is_trampoline);
#endif

/* If this function is variadic, we have an extra name field in arg_info, and also an extra
* argument sent to the function. */
if (is_variadic && !is_trampoline) {
names_expected++;
arguments_sent++;
}

/* Pick the highest of "expected arguments" and "arguments given" (also
* taking into account the extra one for variadics */
if (names_expected > arguments_sent) {
arguments_storage = names_expected;
} else {
arguments_storage = arguments_sent;
}

fse->varc = arguments_storage;
fse->var = xdmalloc(fse->varc * sizeof(xdebug_var_name));

#if DEBUG
fprintf(stderr, " - names_expected: %d, arguments_sent: %d, arguments_storage: %d, fse->varc: %d\n", names_expected, arguments_sent, arguments_storage, fse->varc);
#endif

/* Initialise everything in storage */
for (i = 0; i < fse->varc; i++) {
fse->var[i].name = NULL;
ZVAL_UNDEF(&fse->var[i].data);
fse->var[i].is_variadic = 0;
}

/* Collect Names */
for (i = 0; i < names_expected; i++) {
if (op_array->arg_info[i].name) {
fse->var[i].name = zend_string_copy(op_array->arg_info[i].name);
}

/* If an argument is a variadic, then we mark that on this 'name',
* and also remember which position the variadic started */
if (ZEND_ARG_IS_VARIADIC(&op_array->arg_info[i]) && variadic_at_pos == NO_VARIADIC) {
fse->var[i].is_variadic = 1;
variadic_at_pos = i;
}
}

/* Collect Arguments */
for (i = 0; i < fse->varc; i++) {
#if PHP_VERSION_ID >= 80200
zend_attribute *attribute;
#else
void *attribute = NULL;
#endif

/* The index in ZEND_CALL_ARG is 1-based */
#if DEBUG
fprintf(stderr, "Copying argument %d: ", i);
#endif
if (i < names_expected || is_trampoline) {
#if DEBUG
fprintf(stderr, "ARG ");
#endif
#if PHP_VERSION_ID >= 80200
attribute = zend_get_parameter_attribute_str(
zdata->func->common.attributes,
"sensitiveparameter",
sizeof("sensitiveparameter") - 1,
i
);
#endif
if (attribute && fse->var[i].is_variadic) {
variadic_sensitive = 1;
}
# if DEBUG
fprintf(stderr, "SENSITIVE %d ", attribute != NULL);
# endif

if ((variadic_sensitive || attribute != NULL) && !fse->var[i].is_variadic) {
ZVAL_STRING(&(fse->var[i].data), "[Sensitive Parameter]");
} else {
ZVAL_COPY(&(fse->var[i].data), ZEND_CALL_ARG(zdata, i + 1));
}
} else {
#if DEBUG
fprintf(stderr, "VAR_NUM ");
#endif
if (variadic_sensitive) {
ZVAL_STRING(&(fse->var[i].data), "[Sensitive Parameter]");
} else {
ZVAL_COPY(&(fse->var[i].data), ZEND_CALL_VAR_NUM(zdata, zdata->func->op_array.last_var + zdata->func->op_array.T + i - names_expected));
}
}
#if DEBUG
fprintf(stderr, "OK\n");
#endif
}

if (ZEND_CALL_INFO(zdata) & ZEND_CALL_HAS_EXTRA_NAMED_PARAMS) {
zend_string *name;
zval *param;
int i = fse->varc;

fse->varc += zend_hash_num_elements(zdata->extra_named_params);
fse->var = xdrealloc(fse->var, fse->varc * sizeof(xdebug_var_name));

ZEND_HASH_FOREACH_STR_KEY_VAL(zdata->extra_named_params, name, param) {
fse->var[i].name = zend_string_copy(name);
ZVAL_COPY(&(fse->var[i].data), param);
fse->var[i].is_variadic = 0;
i++;
} ZEND_HASH_FOREACH_END();
}

#if DEBUG
for (i = 0; i < fse->varc; i++) {
fprintf(stderr, "%2d %-20s %c %s\n", i, fse->var[i].name ? ZSTR_VAL(fse->var[i].name) : "---", fse->var[i].is_variadic ? 'V' : ' ', xdebug_get_zval_value_line(&fse->var[i].data, 0, NULL)->d);
}
#endif
}

function_stack_entry *xdebug_add_stack_frame(zend_execute_data *zdata, zend_op_array *op_array, int type)
{
zend_execute_data *edata;
Expand Down Expand Up @@ -1188,7 +917,7 @@ void xdebug_base_minit(INIT_FUNC_ARGS)
xdebug_base_overloaded_functions_setup();
}

void xdebug_base_mshutdown()
void xdebug_base_mshutdown(void)
{
/* Reset compile and error callbacks */
zend_compile_file = old_compile_file;
Expand All @@ -1201,13 +930,13 @@ void xdebug_base_mshutdown()
#endif
}

void xdebug_base_post_startup()
void xdebug_base_post_startup(void)
{
old_compile_file = zend_compile_file;
zend_compile_file = xdebug_compile_file;
}

void xdebug_base_rinit()
void xdebug_base_rinit(void)
{
XG_BASE(statement_handler_enabled) = true;
XG_BASE(observer_active) = true;
Expand Down Expand Up @@ -1269,7 +998,7 @@ void xdebug_base_rinit()
}
}

void xdebug_base_rinit_if_enabled()
void xdebug_base_rinit_if_enabled(void)
{
CG(compiler_options) = CG(compiler_options) | ZEND_COMPILE_EXTENDED_STMT;
xdebug_disable_opcache_optimizer();
Expand All @@ -1286,7 +1015,7 @@ void xdebug_base_rinit_if_enabled()
}
}

void xdebug_base_post_deactivate()
void xdebug_base_post_deactivate(void)
{
xdebug_hash_destroy(XG_BASE(fiber_stacks));
XG_BASE(fiber_stacks) = NULL;
Expand All @@ -1312,7 +1041,7 @@ void xdebug_base_post_deactivate()
#endif
}

void xdebug_base_rshutdown()
void xdebug_base_rshutdown(void)
{
/* Signal that we're no longer in a request */
XG_BASE(in_execution) = 0;
Expand Down
12 changes: 6 additions & 6 deletions src/base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
#define __XDEBUG_BASE_H__

void xdebug_base_minit(INIT_FUNC_ARGS);
void xdebug_base_mshutdown();
void xdebug_base_mshutdown(void);

void xdebug_base_post_startup();
void xdebug_base_post_startup(void);

void xdebug_base_rinit();
void xdebug_base_rinit_if_enabled();
void xdebug_base_post_deactivate();
void xdebug_base_rshutdown();
void xdebug_base_rinit(void);
void xdebug_base_rinit_if_enabled(void);
void xdebug_base_post_deactivate(void);
void xdebug_base_rshutdown(void);

void xdebug_func_dtor_by_ref(xdebug_func *elem); /* TODO: Remove this API */
void xdebug_func_dtor(xdebug_func *elem);
Expand Down
Loading
Loading