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
6 changes: 3 additions & 3 deletions src/debugger/com.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ void xdebug_debug_init_if_requested_on_xdebug_break()
return;
}

if (xdebug_lib_start_if_mode_is_trigger(XDEBUG_MODE_STEP_DEBUG)) {
if (xdebug_lib_start_if_mode_is_trigger()) {
xdebug_init_debugger();
}
}
Expand Down Expand Up @@ -896,9 +896,9 @@ void xdebug_debug_init_if_requested_at_startup(void)
}

if (
xdebug_lib_start_with_request(XDEBUG_MODE_STEP_DEBUG) ||
xdebug_lib_start_with_request() ||
(!xdebug_lib_never_start_with_request() && xdebug_handle_start_session()) ||
xdebug_lib_start_with_trigger(XDEBUG_MODE_STEP_DEBUG, &found_trigger_value)
xdebug_lib_start_with_trigger(&found_trigger_value)
) {
if (found_trigger_value) {
xdebug_update_ide_key(found_trigger_value);
Expand Down
71 changes: 25 additions & 46 deletions src/lib/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,6 @@ int xdebug_lib_get_start_with_request(void)

int xdebug_lib_set_start_with_request(char *value)
{
if (strcmp(value, "default") == 0) {
XG_LIB(start_with_request) = XDEBUG_START_WITH_REQUEST_DEFAULT;
return 1;
}
if (strcmp(value, "yes") == 0 || strcmp(value, "1") == 0) {
XG_LIB(start_with_request) = XDEBUG_START_WITH_REQUEST_YES;
return 1;
Expand All @@ -263,7 +259,7 @@ int xdebug_lib_set_start_with_request(char *value)
return 0;
}

int xdebug_lib_start_with_request(int for_mode)
int xdebug_lib_start_with_request(void)
{
if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_YES) {
return 1;
Expand Down Expand Up @@ -396,10 +392,10 @@ int xdebug_lib_has_shared_secret(void)
return 0;
}

static int does_shared_secret_match_single(int mode, const char *trimmed_trigger_value, const char *trimmed_shared_secret, char **found_trigger_value)
static int does_shared_secret_match_single(const char *trimmed_trigger_value, const char *trimmed_shared_secret, char **found_trigger_value)
{
if (strcmp(trimmed_shared_secret, trimmed_trigger_value) == 0) {
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_DEBUG, "TRGSEC-MATCH", "The trigger value '%s' matched the shared secret '%s' for mode '%s'", trimmed_trigger_value, trimmed_shared_secret, xdebug_lib_mode_from_value(mode));
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_DEBUG, "TRGSEC-MATCH", "The trigger value '%s' matched the shared secret '%s'", trimmed_trigger_value, trimmed_shared_secret);

if (found_trigger_value != NULL) {
*found_trigger_value = xdstrdup(trimmed_trigger_value);
Expand All @@ -411,7 +407,7 @@ static int does_shared_secret_match_single(int mode, const char *trimmed_trigger
return 0;
}

static int does_shared_secret_match(int mode, const char *trigger_name, const char *trigger_value, char **found_trigger_value)
static int does_shared_secret_match(const char *trigger_name, const char *trigger_value, char **found_trigger_value)
{
int retval = 0;
const char *shared_secret = XINI_LIB(trigger_value);
Expand All @@ -422,14 +418,14 @@ static int does_shared_secret_match(int mode, const char *trigger_name, const ch
int i;
xdebug_arg *values = xdebug_arg_ctor();

xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_DEBUG, "TRGSEC-MULT", "The shared secret (xdebug.trigger_value) is multi-value for mode '%s'", xdebug_lib_mode_from_value(mode));
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_DEBUG, "TRGSEC-MULT", "The shared secret (xdebug.trigger_value) is multi-value");

xdebug_explode(",", shared_secret, values, -1);

for (i = 0; i < values->c; i++) {
char *trimmed_shared_secret = xdebug_trim(values->args[i]);

retval = does_shared_secret_match_single(mode, trimmed_trigger_value, trimmed_shared_secret, found_trigger_value);
retval = does_shared_secret_match_single(trimmed_trigger_value, trimmed_shared_secret, found_trigger_value);

xdfree(trimmed_shared_secret);

Expand All @@ -442,17 +438,17 @@ static int does_shared_secret_match(int mode, const char *trigger_name, const ch
xdebug_arg_dtor(values);

if (retval == 0) {
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "TRGSEC-MNO", "The trigger value '%s', as set through '%s', did not match any of the shared secrets (xdebug.trigger_value) for mode '%s'", trimmed_trigger_value, trigger_name, xdebug_lib_mode_from_value(mode));
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "TRGSEC-MNO", "The trigger value '%s', as set through '%s', did not match any of the shared secrets (xdebug.trigger_value)", trimmed_trigger_value, trigger_name);
}
} else {
char *trimmed_shared_secret = xdebug_trim(shared_secret);

retval = does_shared_secret_match_single(mode, trimmed_trigger_value, trimmed_shared_secret, found_trigger_value);
retval = does_shared_secret_match_single(trimmed_trigger_value, trimmed_shared_secret, found_trigger_value);

xdfree(trimmed_shared_secret);

if (retval == 0) {
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "TRGSEC-NO", "The trigger value '%s', as set through '%s', did not match the shared secret (xdebug.trigger_value) for mode '%s'", trimmed_trigger_value, trigger_name, xdebug_lib_mode_from_value(mode));
xdebug_log_ex(XLOG_CHAN_CONFIG, XLOG_WARN, "TRGSEC-NO", "The trigger value '%s', as set through '%s', did not match the shared secret (xdebug.trigger_value)", trimmed_trigger_value, trigger_name);
}
}

Expand All @@ -461,38 +457,31 @@ static int does_shared_secret_match(int mode, const char *trigger_name, const ch
return retval;
}

static int trigger_enabled(int for_mode, char **found_trigger_value)
static int trigger_enabled(char **found_trigger_value)
{
const char *trigger_value = NULL;
const char *trigger_name = "XDEBUG_TRIGGER";
const char *found_in_global;

xdebug_log(XLOG_CHAN_CONFIG, XLOG_DEBUG, "Checking if trigger 'XDEBUG_TRIGGER' is enabled for mode '%s'", xdebug_lib_mode_from_value(for_mode));
xdebug_log(XLOG_CHAN_CONFIG, XLOG_DEBUG, "Checking if trigger 'XDEBUG_TRIGGER' is enabled");

/* First we check for the generic 'XDEBUG_TRIGGER' option */
trigger_value = xdebug_lib_find_in_globals(trigger_name, &found_in_global);

/* If not found, try the PHP_DEBUGGER_TRIGGER alias */
if (!trigger_value) {
trigger_name = "PHP_DEBUGGER_TRIGGER";
trigger_value = xdebug_lib_find_in_globals("PHP_DEBUGGER_TRIGGER", &found_in_global);
if (trigger_value) {
trigger_name = "PHP_DEBUGGER_TRIGGER";
}
}

/* If not found, we fall back to the per-mode name for backwards compatibility reasons */
if (!trigger_value) {
if (XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG) && (for_mode == XDEBUG_MODE_STEP_DEBUG)) {
trigger_name = "XDEBUG_SESSION";
}

if (trigger_name) {
xdebug_log(XLOG_CHAN_CONFIG, XLOG_INFO, "Trigger value for 'XDEBUG_TRIGGER' not found, falling back to '%s'", trigger_name);
trigger_value = xdebug_lib_find_in_globals(trigger_name, &found_in_global);
}
trigger_name = "XDEBUG_SESSION";
xdebug_log(XLOG_CHAN_CONFIG, XLOG_INFO, "Trigger value for 'XDEBUG_TRIGGER' not found, falling back to '%s'", trigger_name);
trigger_value = xdebug_lib_find_in_globals(trigger_name, &found_in_global);

/* Also try PHP_DEBUGGER_SESSION alias */
if (!trigger_value && XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG) && (for_mode == XDEBUG_MODE_STEP_DEBUG)) {
if (!trigger_value) {
trigger_name = "PHP_DEBUGGER_SESSION";
trigger_value = xdebug_lib_find_in_globals(trigger_name, &found_in_global);
}
Expand All @@ -518,43 +507,33 @@ static int trigger_enabled(int for_mode, char **found_trigger_value)

/* Check if the configured trigger value matches the one found in the
* trigger element */
if (does_shared_secret_match(for_mode, trigger_name, trigger_value, found_trigger_value)) {
if (does_shared_secret_match(trigger_name, trigger_value, found_trigger_value)) {
return 1;
}

return 0;
}

static int is_mode_trigger_and_enabled(int for_mode, int force_trigger, char **found_trigger_value)
static int is_mode_trigger_and_enabled(int force_trigger, char **found_trigger_value)
{
if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_TRIGGER) {
return force_trigger || trigger_enabled(for_mode, found_trigger_value);
}

if (XG_LIB(start_with_request) == XDEBUG_START_WITH_REQUEST_DEFAULT) {
if (
XDEBUG_MODE_IS(XDEBUG_MODE_STEP_DEBUG)
) {
return force_trigger || trigger_enabled(for_mode, found_trigger_value);
}
return force_trigger || trigger_enabled(found_trigger_value);
}

return 0;
}

/* Returns 1 if the mode is 'trigger', or 'default', where the default mode for
* a feature is to trigger, and the trigger is present. If found_trigger_value
/* Returns 1 if the mode is 'trigger' and the trigger is present. If found_trigger_value
* is not NULL, then it is set to the found trigger value */
int xdebug_lib_start_with_trigger(int for_mode, char **found_trigger_value)
int xdebug_lib_start_with_trigger(char **found_trigger_value)
{
return is_mode_trigger_and_enabled(for_mode, 0, found_trigger_value);
return is_mode_trigger_and_enabled(0, found_trigger_value);
}

/* Returns 1 if the mode is 'trigger', or 'default', where the default mode for
* a feature is to trigger. Does not check whether a trigger is present. */
int xdebug_lib_start_if_mode_is_trigger(int for_mode)
/* Returns 1 if the mode is 'trigger'. Does not check whether a trigger is present. */
int xdebug_lib_start_if_mode_is_trigger(void)
{
return is_mode_trigger_and_enabled(for_mode, 1, NULL);
return is_mode_trigger_and_enabled(1, NULL);
}

function_stack_entry *xdebug_get_stack_frame(int nr)
Expand Down
13 changes: 6 additions & 7 deletions src/lib/lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,13 @@ int xdebug_lib_set_mode(const char *mode);
#define RETURN_FALSE_IF_MODE_IS_NOT(m) if (!XDEBUG_MODE_IS((m))) { RETURN_FALSE; }
#define WARN_AND_RETURN_IF_MODE_IS_NOT(m) if (!XDEBUG_MODE_IS((m))) { php_error(E_NOTICE, "Functionality is not enabled"); return; }

#define XDEBUG_START_WITH_REQUEST_DEFAULT 1
#define XDEBUG_START_WITH_REQUEST_YES 2
#define XDEBUG_START_WITH_REQUEST_NO 3
#define XDEBUG_START_WITH_REQUEST_TRIGGER 4
#define XDEBUG_START_WITH_REQUEST_YES 1
#define XDEBUG_START_WITH_REQUEST_NO 2
#define XDEBUG_START_WITH_REQUEST_TRIGGER 3

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to change the values here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is safe. These values are only used internally and not exposed to the user. In the xdebug_lib_set_start_with_request() function the actual value entered by the user, which will be a string will be transformed in one of these flags

int xdebug_lib_set_start_with_request(char *value);
int xdebug_lib_start_with_request(int for_mode);
int xdebug_lib_start_with_trigger(int for_mode, char **found_trigger_value);
int xdebug_lib_start_if_mode_is_trigger(int for_mode);
int xdebug_lib_start_with_request(void);
int xdebug_lib_start_with_trigger(char **found_trigger_value);
int xdebug_lib_start_if_mode_is_trigger(void);
int xdebug_lib_never_start_with_request(void);
int xdebug_lib_get_start_with_request(void);
int xdebug_lib_has_shared_secret(void);
Expand Down
2 changes: 1 addition & 1 deletion tests/debugger/bug02122.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ $commands = array(
);

dbgpRunFile( $filename, $commands, [
'xdebug.start_with_request' => 'default',
'xdebug.start_with_request' => 'trigger',
'xdebug.start_upon_error' => 'yes',
'xdebug.on_demand_debugging_enabled' => 1
]);
Expand Down
31 changes: 0 additions & 31 deletions tests/debugger/start_with_request_default_break.phpt

This file was deleted.

18 changes: 0 additions & 18 deletions tests/debugger/start_with_request_default_break_session_start.phpt

This file was deleted.

37 changes: 0 additions & 37 deletions tests/debugger/start_with_request_default_config.phpt

This file was deleted.

14 changes: 0 additions & 14 deletions tests/debugger/start_with_request_default_no_env.phpt

This file was deleted.

33 changes: 0 additions & 33 deletions tests/debugger/start_with_request_default_session-001.phpt

This file was deleted.

Loading
Loading