Skip to content

Commit

Permalink
Instead of using an output buffer, we now overwrite sapi_module.ub_wr…
Browse files Browse the repository at this point in the history
…ite.
  • Loading branch information
derickr committed Mar 12, 2012
1 parent f0fc522 commit 44a5378
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 41 deletions.
8 changes: 1 addition & 7 deletions tests/bug00790-2.phpt
Expand Up @@ -24,18 +24,12 @@ dbgpRun( $data, $commands );

-> run -i 2
<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="break" reason="ok"><xdebug:message filename="file:///tmp/xdebug-dbgp-test.php" lineno="14"></xdebug:message></response>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="2" status="break" reason="ok"><xdebug:message filename="file:///tmp/xdebug-dbgp-test.php" lineno="15"></xdebug:message></response>

-> run -i 3
<?xml version="1.0" encoding="iso-8859-1"?>
<stream xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" type="stdout" encoding="base64"><![CDATA[%s]]></stream>

<?xml version="1.0" encoding="iso-8859-1"?>
<stream xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" type="stdout" encoding="base64"><![CDATA[dGVzdAo=]]></stream>

<?xml version="1.0" encoding="iso-8859-1"?>
<stream xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" type="stdout" encoding="base64"><![CDATA[YWdhaW4K]]></stream>

<?xml version="1.0" encoding="iso-8859-1"?>
<response xmlns="urn:debugger_protocol_v1" xmlns:xdebug="http://xdebug.org/dbgp/xdebug" command="run" transaction_id="3" status="stopping" reason="ok"></response>

Expand Down
44 changes: 25 additions & 19 deletions xdebug.c
Expand Up @@ -77,6 +77,9 @@ 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);

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);
#endif

static void xdebug_throw_exception_hook(zval *exception TSRMLS_DC);
int xdebug_exit_handler(ZEND_OPCODE_HANDLER_ARGS);
Expand All @@ -85,6 +88,9 @@ int zend_xdebug_initialised = 0;
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);
#if PHP_VERSION_ID >= 50400
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);

Expand Down Expand Up @@ -339,6 +345,14 @@ static void php_xdebug_init_globals (zend_xdebug_globals *xg TSRMLS_DC)
sapi_module.header_handler = xdebug_header_handler;
}
xg->headers = NULL;

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

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

return SUCCESS;
Expand Down Expand Up @@ -773,20 +793,16 @@ static void xdebug_stack_element_dtor(void *dummy, void *elem)
#endif

#if PHP_VERSION_ID >= 50400
int xdebug_output_handler(void **handler_context, php_output_context *c)
int xdebug_ub_write(const char *string, unsigned int length TSRMLS_DC)
{
TSRMLS_FETCH();

if (XG(remote_enabled)) {
XG(context).handler->remote_stream_output(c TSRMLS_CC);
return SUCCESS;
} else {
c->out.data = c->in.data;
c->out.size = c->in.used;
c->out.used = c->in.used;
c->out.free = 0;
return SUCCESS;
if (-1 == XG(context).handler->remote_stream_output(string, length TSRMLS_CC)) {
return 0;
}
}
return xdebug_orig_ub_write(string, length);
}
#endif

Expand All @@ -795,9 +811,6 @@ PHP_RINIT_FUNCTION(xdebug)
zend_function *orig;
char *idekey;
zval **dummy;
#if PHP_VERSION_ID >= 50400
php_output_handler *h;
#endif

/* get xdebug ini entries from the environment also */
XG(ide_key) = NULL;
Expand Down Expand Up @@ -917,13 +930,6 @@ PHP_RINIT_FUNCTION(xdebug)

XG(headers) = xdebug_llist_alloc(xdebug_llist_string_dtor);

#if PHP_VERSION_ID >= 50400
h = php_output_handler_create_internal("xdebug", sizeof("xdebug"), xdebug_output_handler, 1, 0 TSRMLS_CC);
php_output_handler_start(h TSRMLS_CC);

XG(stdout_mode) = 0;
#endif

return SUCCESS;
}

Expand Down
19 changes: 6 additions & 13 deletions xdebug_handler_dbgp.c
Expand Up @@ -2700,23 +2700,16 @@ int xdebug_dbgp_breakpoint(xdebug_con *context, xdebug_llist *stack, char *file,
}

#if PHP_VERSION_ID >= 50400
void xdebug_dbgp_stream_output(php_output_context *c TSRMLS_DC)
int xdebug_dbgp_stream_output(const char *string, unsigned int length TSRMLS_DC)
{
if (XG(stdout_mode) == 0 || XG(stdout_mode) == 1) {
c->out.data = c->in.data;
c->out.size = c->in.used;
c->out.used = c->in.used;
c->out.free = 0;
} else {
c->out.data = estrdup("");
c->out.size = 0;
c->out.used = 0;
c->out.free = 1;
if ((XG(stdout_mode) == 1 || XG(stdout_mode) == 2) && length) {
xdebug_send_stream("stdout", string, length TSRMLS_CC);
}

if ((XG(stdout_mode) == 1 || XG(stdout_mode) == 2) && c->in.used) {
xdebug_send_stream("stdout", c->in.data, c->in.used TSRMLS_CC);
if (XG(stdout_mode) == 0 || XG(stdout_mode) == 1) {
return 0;
}
return -1;
}
#endif

Expand Down
2 changes: 1 addition & 1 deletion xdebug_handler_dbgp.h
Expand Up @@ -93,7 +93,7 @@ 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_breakpoint(xdebug_con *context, xdebug_llist *stack, char *file, long lineno, int type, char *exception, char *message);
#if PHP_VERSION_ID >= 50400
void xdebug_dbgp_stream_output(php_output_context *c 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);
char *xdebug_dbgp_get_revision(void);
Expand Down
2 changes: 1 addition & 1 deletion xdebug_handlers.h
Expand Up @@ -114,7 +114,7 @@ struct _xdebug_remote_handler {

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

/* Eval ID registration and removal */
Expand Down

0 comments on commit 44a5378

Please sign in to comment.