[xdebug-dev] xdebug xdebug/xdebug.c xdebug/xdebug_handler_dbgp.c xdebug/xdebug_handler_dbgp.h xdebug/xdebug_handler_gdb.c xdebug/xdebug_handler_gdb.h xdebug/xdebug_handler_php3.c xdebug/xdebug_handler_php3.h xdebug/xdebug_handlers.h xdebug/tests/exception.phpt - Added hook into exception throwing mechinism of PHP so that they can be

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Sat, 17 Apr 2004 01:27:33 +0200

Date: Sat Apr 17 01:27:33 CEST 2004
User: Derick Rethans
Directory: xdebug

Log Message:
[4.00]
- Added hook into exception throwing mechinism of PHP so that they can be
  dealth with in the remote debugger frontends too.
#- Only works with >= PHP 5 RC2

Modified files:
           xdebug/xdebug.c (version: 1.209)
           xdebug/xdebug_handler_dbgp.c (version: 1.38)
           xdebug/xdebug_handler_dbgp.h (version: 1.9)
           xdebug/xdebug_handler_gdb.c (version: 1.74)
           xdebug/xdebug_handler_gdb.h (version: 1.26)
           xdebug/xdebug_handler_php3.c (version: 1.18)
           xdebug/xdebug_handler_php3.h (version: 1.12)
           xdebug/xdebug_handlers.h (version: 1.29)
Added files:
           xdebug/tests/exception.phpt (new version: 1.1)

[FILE: /xdebug/xdebug.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.208
retrieving revision 1.209
diff -u -r1.208 -r1.209
--- xdebug/xdebug.c:1.208 Mon Apr 12 16:31:00 2004 GMT
+++ xdebug/xdebug.c Fri Apr 16 21:27:33 2004 GMT
@@ -51,6 +51,7 @@
 #include "zend_execute.h"
 #include "zend_compile.h"
 #include "zend_extensions.h"
+#include "zend_exceptions.h"
 
 #include "php_xdebug.h"
 #include "xdebug_private.h"
@@ -78,6 +79,8 @@
 void (*new_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);
 
+void xdebug_throw_exception_hook(zval *exception TSRMLS_DC);
+
 static zval *get_zval(znode *node, temp_variable *Ts, int *is_var);
 static char* return_trace_stack_frame(function_stack_entry* i, int html TSRMLS_DC);
 static char* return_trace_stack_retval(function_stack_entry* i, zval* retval TSRMLS_DC);
@@ -456,6 +459,10 @@
 
         if (XG(default_enable)) {
                 zend_error_cb = new_error_cb;
+
+#ifdef ZEND_ENGINE_2
+ zend_throw_exception_hook = xdebug_throw_exception_hook;
+#endif
         }
         XG(remote_enabled) = 0;
         XG(profiler_enabled) = 0;
@@ -1276,6 +1283,37 @@
         return str.d;
 }
 
+#ifdef ZEND_ENGINE_2
+void xdebug_throw_exception_hook(zval *exception TSRMLS_DC)
+{
+ /* Start JIT if requested and not yet enabled */
+ if (XG(remote_enable) && (XG(remote_mode) == XDEBUG_JIT) && !XG(remote_enabled)) {
+ XG(context).socket = xdebug_create_socket(XG(remote_host), XG(remote_port));
+ if (XG(context).socket >= 0) {
+ XG(remote_enabled) = 1;
+ XG(context).program_name = NULL;
+
+ /* Get handler from mode */
+ XG(context).handler = xdebug_handler_get(XG(remote_handler));
+ XG(context).handler->remote_init(&(XG(context)), XDEBUG_JIT, NULL);
+ }
+ }
+ if (XG(remote_enabled)) {
+ zval *message, *file, *line;
+ zend_class_entry *default_ce = zend_exception_get_default();
+ zend_class_entry *exception_ce = zend_get_class_entry(exception TSRMLS_CC);
+
+ message = zend_read_property(default_ce, exception, "message", sizeof("message")-1, 0 TSRMLS_CC);
+ file = zend_read_property(default_ce, exception, "file", sizeof("file")-1, 0 TSRMLS_CC);
+ line = zend_read_property(default_ce, exception, "line", sizeof("line")-1, 0 TSRMLS_CC);
+
+ if (!XG(context).handler->remote_error(&(XG(context)), 0, exception_ce->name, Z_STRVAL_P(message), Z_STRVAL_P(file), Z_LVAL_P(line), XG(stack))) {
+ XG(remote_enabled) = 0;
+ }
+ }
+}
+#endif
+
 void xdebug_error_cb(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args)
 {
         char *buffer, *error_type_str;
@@ -1323,7 +1361,7 @@
                         }
                 }
                 if (XG(remote_enabled)) {
- if (!XG(context).handler->remote_error(&(XG(context)), type, buffer, error_filename, error_lineno, XG(stack))) {
+ if (!XG(context).handler->remote_error(&(XG(context)), type, NULL, buffer, error_filename, error_lineno, XG(stack))) {
                                 XG(remote_enabled) = 0;
                         }
                 }

[FILE: /xdebug/xdebug_handler_dbgp.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.37
retrieving revision 1.38
diff -u -r1.37 -r1.38
--- xdebug/xdebug_handler_dbgp.c:1.37 Mon Apr 12 16:31:00 2004 GMT
+++ xdebug/xdebug_handler_dbgp.c Fri Apr 16 21:27:33 2004 GMT
@@ -1328,7 +1328,7 @@
 
 char *xdebug_dbgp_get_revision(void)
 {
- return "$Revision: 1.37 $";
+ return "$Revision: 1.38 $";
 }
 
 int xdebug_dbgp_cmdloop(xdebug_con *context TSRMLS_DC)
@@ -1463,13 +1463,17 @@
         return 1;
 }
 
-int xdebug_dbgp_error(xdebug_con *context, int 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)
 {
         char *errortype;
         xdebug_xml_node *response;
         TSRMLS_FETCH();
 
- errortype = error_type(type);
+ if (exception_type) {
+ errortype = exception_type;
+ } else {
+ errortype = error_type(type);
+ }
 /*
         runtime_allowed = (
                 (type != E_ERROR) &&
@@ -1483,7 +1487,9 @@
         xdebug_xml_add_text(response, xdstrdup(message));
         send_message(context, response);
         xdebug_xml_node_dtor(response);
- xdfree(errortype);
+ if (!exception_type) {
+ xdfree(errortype);
+ }
 
         xdebug_dbgp_cmdloop(context TSRMLS_CC);
 

[FILE: /xdebug/xdebug_handler_dbgp.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- xdebug/xdebug_handler_dbgp.h:1.8 Thu Mar 25 15:57:31 2004 GMT
+++ xdebug/xdebug_handler_dbgp.h Fri Apr 16 21:27:33 2004 GMT
@@ -82,7 +82,7 @@
 
 int xdebug_dbgp_init(xdebug_con *context, int mode, char *magic_cookie);
 int xdebug_dbgp_deinit(xdebug_con *context);
-int xdebug_dbgp_error(xdebug_con *context, int 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 *xdebug_dbgp_get_revision(void);
 

[FILE: /xdebug/xdebug_handler_gdb.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -r1.73 -r1.74
--- xdebug/xdebug_handler_gdb.c:1.73 Tue Apr 13 18:33:45 2004 GMT
+++ xdebug/xdebug_handler_gdb.c Fri Apr 16 21:27:33 2004 GMT
@@ -1321,7 +1321,7 @@
 
 char *xdebug_gdb_get_revision(void)
 {
- return "$Revision: 1.73 $";
+ return "$Revision: 1.74 $";
 }
 
 int xdebug_gdb_init(xdebug_con *context, int mode, char *magic_cookie)
@@ -1382,7 +1382,7 @@
         return 1;
 }
 
-int xdebug_gdb_error(xdebug_con *context, int type, char *message, const char *file, const uint lineno, xdebug_llist *stack)
+int xdebug_gdb_error(xdebug_con *context, int type, char *exception_type, char *message, const char *file, const uint lineno, xdebug_llist *stack)
 {
         char *errortype;
         int ret;
@@ -1391,7 +1391,11 @@
         int runtime_allowed;
         xdebug_gdb_options *options = (xdebug_gdb_options*) context->options;
 
- errortype = error_type(type);
+ if (exception_type) {
+ errortype = exception_type;
+ } else {
+ errortype = error_type(type);
+ }
 
         runtime_allowed = (
                 (type != E_ERROR) &&
@@ -1409,7 +1413,10 @@
                 print_stackframe(context, 0, XDEBUG_LLIST_VALP(XDEBUG_LLIST_TAIL(stack)), options->response_format, XDEBUG_FRAME_NORMAL);
         }
 
- xdfree(errortype);
+ if (!exception_type) {
+ xdfree(errortype);
+ }
+
         do {
                 SSEND(context->socket, "?cmd\n");
                 option = fd_read_line(context->socket, context->buffer, FD_RL_SOCKET);

[FILE: /xdebug/xdebug_handler_gdb.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -r1.25 -r1.26
--- xdebug/xdebug_handler_gdb.h:1.25 Thu Mar 25 15:57:31 2004 GMT
+++ xdebug/xdebug_handler_gdb.h Fri Apr 16 21:27:33 2004 GMT
@@ -72,7 +72,7 @@
 
 int xdebug_gdb_init(xdebug_con *context, int mode, char *magic_cookie);
 int xdebug_gdb_deinit(xdebug_con *context);
-int xdebug_gdb_error(xdebug_con *context, int type, char *message, const char *file, const uint lineno, xdebug_llist *stack);
+int xdebug_gdb_error(xdebug_con *context, int type, char *exception_type, char *message, const char *file, const uint lineno, xdebug_llist *stack);
 int xdebug_gdb_breakpoint(xdebug_con *context, xdebug_llist *stack, char *file, long lineno, int type);
 char *xdebug_gdb_get_revision(void);
 

[FILE: /xdebug/xdebug_handler_php3.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- xdebug/xdebug_handler_php3.c:1.17 Thu Mar 25 15:57:31 2004 GMT
+++ xdebug/xdebug_handler_php3.c Fri Apr 16 21:27:33 2004 GMT
@@ -74,7 +74,7 @@
 
 char *xdebug_php3_get_revision(void)
 {
- return "$Revision: 1.17 $";
+ return "$Revision: 1.18 $";
 }
 
 int xdebug_php3_init(xdebug_con *context, int mode, char *magic_cookie)
@@ -95,7 +95,7 @@
         xdfree(message_buffer); \
 }
 
-int xdebug_php3_error(xdebug_con *h, int type, char *message, const char *location, const uint line, xdebug_llist *stack)
+int xdebug_php3_error(xdebug_con *h, int type, char *exception_type, char *message, const char *location, const uint line, xdebug_llist *stack)
 {
         char *time_buffer;
         char *hostname;
@@ -110,7 +110,11 @@
                 hostname = estrdup("{unknown}");
         }
         prefix = xdebug_sprintf("%s %s(%lu) ", time_buffer, hostname, getpid());
- errortype = error_type(type);
+ if (exception_type) {
+ errortype = exception_type;
+ } else {
+ errortype = error_type(type);
+ }
 
         /* start */
         SENDMSG(h->socket, xdebug_sprintf("%sstart: %s\n", prefix, errortype));
@@ -138,7 +142,9 @@
         /* stop */
         SENDMSG(h->socket, xdebug_sprintf("%sstop: %s\n", prefix, errortype));
 
- xdfree(errortype);
+ if (!exception_type) {
+ xdfree(errortype);
+ }
         xdfree(prefix);
         xdfree(hostname);
 

[FILE: /xdebug/xdebug_handler_php3.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- xdebug/xdebug_handler_php3.h:1.11 Thu Mar 25 15:57:31 2004 GMT
+++ xdebug/xdebug_handler_php3.h Fri Apr 16 21:27:33 2004 GMT
@@ -24,7 +24,7 @@
 
 int xdebug_php3_init(xdebug_con *context, int mode, char *magic_cookie);
 int xdebug_php3_deinit(xdebug_con *context);
-int xdebug_php3_error(xdebug_con *context, int type, char *message, const char *location, const uint line, xdebug_llist *stack);
+int xdebug_php3_error(xdebug_con *context, int type, char *exception_type, char *message, const char *location, const uint line, xdebug_llist *stack);
 char *xdebug_php3_get_revision(void);
 
 #define xdebug_handler_php3 { \

[FILE: /xdebug/xdebug_handlers.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- xdebug/xdebug_handlers.h:1.28 Mon Apr 12 16:31:00 2004 GMT
+++ xdebug/xdebug_handlers.h Fri Apr 16 21:27:33 2004 GMT
@@ -96,7 +96,7 @@
         int (*remote_deinit)(xdebug_con *h);
 
         /* Stack messages */
- int (*remote_error)(xdebug_con *h, int type, char *message, const char *location, const uint line, xdebug_llist *stack);
+ int (*remote_error)(xdebug_con *h, int type, char *exception_type, char *message, const char *location, const uint line, xdebug_llist *stack);
 
         /* Breakpoints */
         int (*remote_breakpoint)(xdebug_con *h, xdebug_llist *stack, char *file, long lineno, int type);

[FILE: /xdebug/tests/exception.phpt]

--TEST--
Test to see if exceptions still work with Xdebug's hook enabled.
--SKIPIF--
<?php if(version_compare(zend_version(), "2.0.0-dev", '<')) echo "skip Zend Engine 2 only\n"; ?>
--INI--
xdebug.default_enable=1
xdebug.auto_trace=0
xdebug.collect_params=0
xdebug.show_mem_delta=0
xdebug.profiler_enable=0
--FILE--
<?php

class FooException extends Exception {
}

function a() {
        try {
                throw new FooException('foo');
        } catch (Exception $e) {
                echo "Caught\n";
        }
}

a();
?>
--EXPECT--
Caught
Received on Sat Apr 17 2004 - 01:27:34 BST

This archive was generated by hypermail 2.2.0 : Sun Jun 24 2018 - 04:00:02 BST