Skip to content

Commit

Permalink
Use the new output handling code for PHP 5.1.0-PHP 5.3.x too.
Browse files Browse the repository at this point in the history
  • Loading branch information
derickr committed Mar 12, 2012
1 parent 44a5378 commit 071bcc4
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 119 deletions.
7 changes: 0 additions & 7 deletions php_xdebug.h
Expand Up @@ -265,14 +265,7 @@ ZEND_BEGIN_MODULE_GLOBALS(xdebug)
char *lasttransid; char *lasttransid;


/* output redirection */ /* output redirection */
#if PHP_VERSION_ID < 50400
php_output_globals stdio;
int stdout_redirected;
int stderr_redirected;
int stdin_redirected;
#else
int stdout_mode; int stdout_mode;
#endif


/* aggregate profiling */ /* aggregate profiling */
HashTable aggr_calls; HashTable aggr_calls;
Expand Down
11 changes: 1 addition & 10 deletions xdebug.c
Expand Up @@ -77,9 +77,7 @@ void (*xdebug_new_error_cb)(int type, const char *error_filename, const uint err
void xdebug_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args); void xdebug_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);


static int xdebug_header_handler(sapi_header_struct *h XG_SAPI_HEADER_OP_DC, sapi_headers_struct *s TSRMLS_DC); static int xdebug_header_handler(sapi_header_struct *h XG_SAPI_HEADER_OP_DC, sapi_headers_struct *s TSRMLS_DC);
#if PHP_VERSION_ID >= 50400
static int xdebug_ub_write(const char *string, unsigned int lenght TSRMLS_DC); static int xdebug_ub_write(const char *string, unsigned int lenght TSRMLS_DC);
#endif


static void xdebug_throw_exception_hook(zval *exception TSRMLS_DC); static void xdebug_throw_exception_hook(zval *exception TSRMLS_DC);
int xdebug_exit_handler(ZEND_OPCODE_HANDLER_ARGS); int xdebug_exit_handler(ZEND_OPCODE_HANDLER_ARGS);
Expand All @@ -88,9 +86,7 @@ int zend_xdebug_initialised = 0;
int zend_xdebug_global_offset = -1; int zend_xdebug_global_offset = -1;


int (*xdebug_orig_header_handler)(sapi_header_struct *h XG_SAPI_HEADER_OP_DC, sapi_headers_struct *s TSRMLS_DC); int (*xdebug_orig_header_handler)(sapi_header_struct *h XG_SAPI_HEADER_OP_DC, sapi_headers_struct *s TSRMLS_DC);
#if PHP_VERSION_ID >= 50400
int (*xdebug_orig_ub_write)(const char *string, unsigned int len TSRMLS_DC); int (*xdebug_orig_ub_write)(const char *string, unsigned int len TSRMLS_DC);
#endif


static int xdebug_trigger_enabled(int setting, char *var_name TSRMLS_DC); static int xdebug_trigger_enabled(int setting, char *var_name TSRMLS_DC);


Expand Down Expand Up @@ -346,13 +342,11 @@ static void php_xdebug_init_globals (zend_xdebug_globals *xg TSRMLS_DC)
} }
xg->headers = NULL; xg->headers = NULL;


#if PHP_VERSION_ID >= 50400
/* Capturing output */ /* Capturing output */
if (sapi_module.ub_write != xdebug_ub_write) { if (sapi_module.ub_write != xdebug_ub_write) {
xdebug_orig_ub_write = sapi_module.ub_write; xdebug_orig_ub_write = sapi_module.ub_write;
sapi_module.ub_write = xdebug_ub_write; sapi_module.ub_write = xdebug_ub_write;
} }
#endif
} }


static void php_xdebug_shutdown_globals (zend_xdebug_globals *xg TSRMLS_DC) static void php_xdebug_shutdown_globals (zend_xdebug_globals *xg TSRMLS_DC)
Expand Down Expand Up @@ -687,12 +681,11 @@ PHP_MINIT_FUNCTION(xdebug)
xdebug_orig_header_handler = sapi_module.header_handler; xdebug_orig_header_handler = sapi_module.header_handler;
sapi_module.header_handler = xdebug_header_handler; sapi_module.header_handler = xdebug_header_handler;
} }
# if PHP_VERSION_ID >= 50400
if (sapi_module.ub_write != xdebug_ub_write) { if (sapi_module.ub_write != xdebug_ub_write) {
xdebug_orig_ub_write = sapi_module.ub_write; xdebug_orig_ub_write = sapi_module.ub_write;
sapi_module.ub_write = xdebug_ub_write; sapi_module.ub_write = xdebug_ub_write;
} }
# endif
#endif #endif


return SUCCESS; return SUCCESS;
Expand Down Expand Up @@ -792,7 +785,6 @@ static void xdebug_stack_element_dtor(void *dummy, void *elem)
#define COOKIE_ENCODE #define COOKIE_ENCODE
#endif #endif


#if PHP_VERSION_ID >= 50400
int xdebug_ub_write(const char *string, unsigned int length TSRMLS_DC) int xdebug_ub_write(const char *string, unsigned int length TSRMLS_DC)
{ {
TSRMLS_FETCH(); TSRMLS_FETCH();
Expand All @@ -804,7 +796,6 @@ int xdebug_ub_write(const char *string, unsigned int length TSRMLS_DC)
} }
return xdebug_orig_ub_write(string, length); return xdebug_orig_ub_write(string, length);
} }
#endif


PHP_RINIT_FUNCTION(xdebug) PHP_RINIT_FUNCTION(xdebug)
{ {
Expand Down
87 changes: 2 additions & 85 deletions xdebug_handler_dbgp.c
Expand Up @@ -1339,43 +1339,6 @@ static int xdebug_send_stream(const char *name, const char *str, uint str_length
return 0; return 0;
} }


#if PHP_VERSION_ID < 50400
static int xdebug_header_write(const char *str, uint str_length TSRMLS_DC)
{
/* nesting_level is zero when final output is sent to sapi */
if (OG(ob_nesting_level) < 1) {
zend_unset_timeout(TSRMLS_C);
if (XG(stdout_redirected) != 0) {
xdebug_send_stream("stdout", str, str_length TSRMLS_CC);
}
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3) || PHP_MAJOR_VERSION >= 6
zend_set_timeout(EG(timeout_seconds), 0);
#else
zend_set_timeout(EG(timeout_seconds));
#endif
}
return XG(stdio).php_header_write(str, str_length TSRMLS_CC);
}

static int xdebug_body_write(const char *str, uint str_length TSRMLS_DC)
{
/* nesting_level is zero when final output is sent to sapi. We also dont
* want to write if headers are not sent yet, the output layer will handle
* this correctly later. */
if (OG(ob_nesting_level) < 1 && SG(headers_sent)) {
zend_unset_timeout(TSRMLS_C);
if (XG(stdout_redirected) != 0) {
xdebug_send_stream("stdout", str, str_length TSRMLS_CC);
}
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3) || PHP_MAJOR_VERSION >= 6
zend_set_timeout(EG(timeout_seconds), 0);
#else
zend_set_timeout(EG(timeout_seconds));
#endif
}
return XG(stdio).php_body_write(str, str_length TSRMLS_CC);
}
#endif


DBGP_FUNC(stderr) DBGP_FUNC(stderr)
{ {
Expand All @@ -1392,31 +1355,9 @@ DBGP_FUNC(stdout)
} }


mode = strtol(CMD_OPTION('c'), NULL, 10); mode = strtol(CMD_OPTION('c'), NULL, 10);
#if PHP_VERSION_ID < 50400
if (mode == 0 && XG(stdout_redirected) != 0) {
if (XG(stdio).php_body_write != NULL && OG(php_body_write)) {
OG(php_body_write) = XG(stdio).php_body_write;
OG(php_header_write) = XG(stdio).php_header_write;

XG(stdio).php_body_write = NULL;
XG(stdio).php_header_write = NULL;
success = "1";
}
} else if (mode != 0 && XG(stdout_redirected) == 0) {
if (XG(stdio).php_body_write == NULL && OG(php_body_write)) {
XG(stdio).php_body_write = OG(php_body_write);
OG(php_body_write) = xdebug_body_write;
XG(stdio).php_header_write = OG(php_header_write);
OG(php_header_write) = xdebug_header_write;
success = "1";
}
}

XG(stdout_redirected) = mode;
#else
XG(stdout_mode) = mode; XG(stdout_mode) = mode;
success = "1"; success = "1";
#endif
xdebug_xml_add_attribute_ex(*retval, "success", xdstrdup(success), 0, 1); xdebug_xml_add_attribute_ex(*retval, "success", xdstrdup(success), 0, 1);
} }


Expand Down Expand Up @@ -1476,13 +1417,7 @@ DBGP_FUNC(detach)
xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_strings[XG(reason)]); xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_strings[XG(reason)]);
XG(context).handler->remote_deinit(&(XG(context))); XG(context).handler->remote_deinit(&(XG(context)));
XG(remote_enabled) = 0; XG(remote_enabled) = 0;
#if PHP_VERSION_ID < 50400
XG(stdout_redirected) = 0;
XG(stderr_redirected) = 0;
XG(stdin_redirected) = 0;
#else
XG(stdout_mode) = 0; XG(stdout_mode) = 0;
#endif
} }




Expand Down Expand Up @@ -2444,14 +2379,6 @@ int xdebug_dbgp_init(xdebug_con *context, int mode)
XG(lastcmd) = NULL; XG(lastcmd) = NULL;
XG(lasttransid) = NULL; XG(lasttransid) = NULL;


#if PHP_VERSION_ID < 50400
XG(stdout_redirected) = 0;
XG(stderr_redirected) = 0;
XG(stdin_redirected) = 0;
XG(stdio).php_body_write = NULL;
XG(stdio).php_header_write = NULL;
#endif

response = xdebug_xml_node_init("init"); response = xdebug_xml_node_init("init");
xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1"); xdebug_xml_add_attribute(response, "xmlns", "urn:debugger_protocol_v1");
xdebug_xml_add_attribute(response, "xmlns:xdebug", "http://xdebug.org/dbgp/xdebug"); xdebug_xml_add_attribute(response, "xmlns:xdebug", "http://xdebug.org/dbgp/xdebug");
Expand Down Expand Up @@ -2549,15 +2476,7 @@ int xdebug_dbgp_deinit(xdebug_con *context)


xdebug_dbgp_cmdloop(context, 0 TSRMLS_CC); xdebug_dbgp_cmdloop(context, 0 TSRMLS_CC);
} }
#if PHP_VERSION_ID < 50400
if (XG(stdio).php_body_write != NULL && OG(php_body_write)) {
OG(php_body_write) = XG(stdio).php_body_write;
OG(php_header_write) = XG(stdio).php_header_write;

XG(stdio).php_body_write = NULL;
XG(stdio).php_header_write = NULL;
}
#endif
if (XG(remote_enabled)) { if (XG(remote_enabled)) {
options = (xdebug_var_export_options*) context->options; options = (xdebug_var_export_options*) context->options;
xdfree(options->runtime); xdfree(options->runtime);
Expand Down Expand Up @@ -2699,7 +2618,6 @@ int xdebug_dbgp_breakpoint(xdebug_con *context, xdebug_llist *stack, char *file,
return 1; return 1;
} }


#if PHP_VERSION_ID >= 50400
int xdebug_dbgp_stream_output(const char *string, unsigned int length TSRMLS_DC) int xdebug_dbgp_stream_output(const char *string, unsigned int length TSRMLS_DC)
{ {
if ((XG(stdout_mode) == 1 || XG(stdout_mode) == 2) && length) { if ((XG(stdout_mode) == 1 || XG(stdout_mode) == 2) && length) {
Expand All @@ -2711,7 +2629,6 @@ int xdebug_dbgp_stream_output(const char *string, unsigned int length TSRMLS_DC)
} }
return -1; return -1;
} }
#endif


static char *create_eval_key_file(char *filename, int lineno) static char *create_eval_key_file(char *filename, int lineno)
{ {
Expand Down
15 changes: 0 additions & 15 deletions xdebug_handler_dbgp.h
Expand Up @@ -92,24 +92,10 @@ int xdebug_dbgp_init(xdebug_con *context, int mode);
int xdebug_dbgp_deinit(xdebug_con *context); int xdebug_dbgp_deinit(xdebug_con *context);
int xdebug_dbgp_error(xdebug_con *context, int type, char *exception_type, char *message, const char *location, const uint line, xdebug_llist *stack); int xdebug_dbgp_error(xdebug_con *context, int type, char *exception_type, char *message, const char *location, const uint line, xdebug_llist *stack);
int xdebug_dbgp_breakpoint(xdebug_con *context, xdebug_llist *stack, char *file, long lineno, int type, char *exception, char *message); int xdebug_dbgp_breakpoint(xdebug_con *context, xdebug_llist *stack, char *file, long lineno, int type, char *exception, char *message);
#if PHP_VERSION_ID >= 50400
int xdebug_dbgp_stream_output(const char *string, unsigned int length TSRMLS_DC); int xdebug_dbgp_stream_output(const char *string, unsigned int length TSRMLS_DC);
#endif
int xdebug_dbgp_register_eval_id(xdebug_con *context, function_stack_entry *fse); int xdebug_dbgp_register_eval_id(xdebug_con *context, function_stack_entry *fse);
char *xdebug_dbgp_get_revision(void); char *xdebug_dbgp_get_revision(void);


#if PHP_VERSION_ID < 50400
#define xdebug_handler_dbgp { \
xdebug_dbgp_init, \
xdebug_dbgp_deinit, \
xdebug_dbgp_error, \
xdebug_dbgp_breakpoint, \
xdebug_dbgp_register_eval_id, \
xdebug_dbgp_get_revision \
}
#endif

#if PHP_VERSION_ID >= 50400
#define xdebug_handler_dbgp { \ #define xdebug_handler_dbgp { \
xdebug_dbgp_init, \ xdebug_dbgp_init, \
xdebug_dbgp_deinit, \ xdebug_dbgp_deinit, \
Expand All @@ -119,7 +105,6 @@ char *xdebug_dbgp_get_revision(void);
xdebug_dbgp_register_eval_id, \ xdebug_dbgp_register_eval_id, \
xdebug_dbgp_get_revision \ xdebug_dbgp_get_revision \
} }
#endif


#endif #endif


2 changes: 0 additions & 2 deletions xdebug_handlers.h
Expand Up @@ -112,10 +112,8 @@ struct _xdebug_remote_handler {
/* Breakpoints */ /* Breakpoints */
int (*remote_breakpoint)(xdebug_con *h, xdebug_llist *stack, char *file, long lineno, int type, char *exception, char *message); int (*remote_breakpoint)(xdebug_con *h, xdebug_llist *stack, char *file, long lineno, int type, char *exception, char *message);


#if PHP_VERSION_ID >= 50400
/* Output redirection */ /* Output redirection */
int (*remote_stream_output)(const char *string, unsigned int length TSRMLS_DC); int (*remote_stream_output)(const char *string, unsigned int length TSRMLS_DC);
#endif


/* Eval ID registration and removal */ /* Eval ID registration and removal */
int (*register_eval_id)(xdebug_con *h, function_stack_entry *fse); int (*register_eval_id)(xdebug_con *h, function_stack_entry *fse);
Expand Down

0 comments on commit 071bcc4

Please sign in to comment.