[xdebug-dev] xdebug xdebug/xdebug.c xdebug/xdebug_handler_dbgp.c xdebug/xdebug_handler_dbgp.h xdebug/xdebug_private.h - Allow postmortem analysis.

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Fri, 10 Nov 2006 12:33:29 +0100

Date: Fri Nov 10 12:33:29 CET 2006
User: Derick Rethans
Directory: xdebug

Log Message:
[2.00]
- Allow postmortem analysis.
- Added the non-standard function xcmd_profiler_name_get.
- Fixed a bug where error messages where not added upon errors in the protocol.

Modified files:
           xdebug/xdebug.c (version: 1.361)
           xdebug/xdebug_handler_dbgp.c (version: 1.105)
           xdebug/xdebug_handler_dbgp.h (version: 1.18)
           xdebug/xdebug_private.h (version: 1.21)

[FILE: /xdebug/xdebug.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.360
retrieving revision 1.361
diff -u -r1.360 -r1.361
--- xdebug/xdebug.c:1.360 Fri Oct 20 10:37:42 2006 GMT
+++ xdebug/xdebug.c Fri Nov 10 10:33:29 2006 GMT
@@ -804,6 +804,14 @@
         zend_function *orig;
 #endif
 
+ if (XG(remote_enabled)) {
+ XG(context).handler->remote_deinit(&(XG(context)));
+ xdebug_close_socket(XG(context).socket);
+ if (XG(context).program_name) {
+ xdfree(XG(context).program_name);
+ }
+ }
+
         xdebug_llist_destroy(XG(stack), NULL);
         XG(stack) = NULL;
 
@@ -831,14 +839,6 @@
         xdebug_hash_destroy(XG(code_coverage));
         xdebug_hash_destroy(XG(code_coverage_op_array_cache));
 
- if (XG(remote_enabled)) {
- XG(context).handler->remote_deinit(&(XG(context)));
- xdebug_close_socket(XG(context).socket);
- if (XG(context).program_name) {
- xdfree(XG(context).program_name);
- }
- }
-
         if (XG(context.list.last_file)) {
                 xdfree(XG(context).list.last_file);
         }

[FILE: /xdebug/xdebug_handler_dbgp.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -r1.104 -r1.105
--- xdebug/xdebug_handler_dbgp.c:1.104 Fri Oct 27 19:05:50 2006 GMT
+++ xdebug/xdebug_handler_dbgp.c Fri Nov 10 10:33:29 2006 GMT
@@ -79,7 +79,7 @@
         char *message;
 } xdebug_error_entry;
 
-xdebug_error_entry xdebug_error_codes[23] = {
+xdebug_error_entry xdebug_error_codes[24] = {
         { 0, "no error" },
         { 1, "parse error in command" },
         { 2, "duplicate arguments in command" },
@@ -99,6 +99,7 @@
         { 300, "can not get property" },
         { 301, "stack depth invalid" },
         { 302, "context invalid" },
+ { 800, "profiler not started" },
         { 900, "encoding not supported" },
         { 998, "an internal exception in the debugger" },
         { 999, "unknown error" },
@@ -163,44 +164,50 @@
 DBGP_FUNC(step_over);
 DBGP_FUNC(detach);
 
+/* Non standard comments */
+DBGP_FUNC(xcmd_profiler_name_get);
+
 /*****************************************************************************
 ** Dispatcher tables for supported debug commands
 */
 
 static xdebug_dbgp_cmd dbgp_commands[] = {
         /* DBGP_FUNC_ENTRY(break) */
- DBGP_FUNC_ENTRY(breakpoint_get)
- DBGP_FUNC_ENTRY(breakpoint_list)
- DBGP_FUNC_ENTRY(breakpoint_remove)
- DBGP_FUNC_ENTRY(breakpoint_set)
- DBGP_FUNC_ENTRY(breakpoint_update)
-
- DBGP_FUNC_ENTRY(context_get)
- DBGP_FUNC_ENTRY(context_names)
-
- DBGP_FUNC_ENTRY(eval)
- DBGP_FUNC_ENTRY(feature_get)
- DBGP_FUNC_ENTRY(feature_set)
-
- DBGP_FUNC_ENTRY(typemap_get)
- DBGP_FUNC_ENTRY(property_get)
- DBGP_FUNC_ENTRY(property_set)
- DBGP_FUNC_ENTRY(property_value)
-
- DBGP_FUNC_ENTRY(source)
- DBGP_FUNC_ENTRY(stack_depth)
- DBGP_FUNC_ENTRY(stack_get)
- DBGP_FUNC_ENTRY(status)
-
- DBGP_FUNC_ENTRY(stderr)
- DBGP_FUNC_ENTRY(stdout)
-
- DBGP_CONT_FUNC_ENTRY(stop)
- DBGP_CONT_FUNC_ENTRY(run)
- DBGP_CONT_FUNC_ENTRY(step_into)
- DBGP_CONT_FUNC_ENTRY(step_out)
- DBGP_CONT_FUNC_ENTRY(step_over)
- DBGP_CONT_FUNC_ENTRY(detach)
+ DBGP_FUNC_ENTRY(breakpoint_get, XDEBUG_DBGP_NONE)
+ DBGP_FUNC_ENTRY(breakpoint_list, XDEBUG_DBGP_POST_MORTEM)
+ DBGP_FUNC_ENTRY(breakpoint_remove, XDEBUG_DBGP_NONE)
+ DBGP_FUNC_ENTRY(breakpoint_set, XDEBUG_DBGP_NONE)
+ DBGP_FUNC_ENTRY(breakpoint_update, XDEBUG_DBGP_NONE)
+
+ DBGP_FUNC_ENTRY(context_get, XDEBUG_DBGP_NONE)
+ DBGP_FUNC_ENTRY(context_names, XDEBUG_DBGP_POST_MORTEM)
+
+ DBGP_FUNC_ENTRY(eval, XDEBUG_DBGP_NONE)
+ DBGP_FUNC_ENTRY(feature_get, XDEBUG_DBGP_POST_MORTEM)
+ DBGP_FUNC_ENTRY(feature_set, XDEBUG_DBGP_NONE)
+
+ DBGP_FUNC_ENTRY(typemap_get, XDEBUG_DBGP_POST_MORTEM)
+ DBGP_FUNC_ENTRY(property_get, XDEBUG_DBGP_NONE)
+ DBGP_FUNC_ENTRY(property_set, XDEBUG_DBGP_NONE)
+ DBGP_FUNC_ENTRY(property_value, XDEBUG_DBGP_NONE)
+
+ DBGP_FUNC_ENTRY(source, XDEBUG_DBGP_NONE)
+ DBGP_FUNC_ENTRY(stack_depth, XDEBUG_DBGP_NONE)
+ DBGP_FUNC_ENTRY(stack_get, XDEBUG_DBGP_NONE)
+ DBGP_FUNC_ENTRY(status, XDEBUG_DBGP_POST_MORTEM)
+
+ DBGP_FUNC_ENTRY(stderr, XDEBUG_DBGP_NONE)
+ DBGP_FUNC_ENTRY(stdout, XDEBUG_DBGP_NONE)
+
+ DBGP_CONT_FUNC_ENTRY(stop, XDEBUG_DBGP_NONE)
+ DBGP_CONT_FUNC_ENTRY(run, XDEBUG_DBGP_NONE)
+ DBGP_CONT_FUNC_ENTRY(step_into, XDEBUG_DBGP_NONE)
+ DBGP_CONT_FUNC_ENTRY(step_out, XDEBUG_DBGP_NONE)
+ DBGP_CONT_FUNC_ENTRY(step_over, XDEBUG_DBGP_NONE)
+ DBGP_CONT_FUNC_ENTRY(detach, XDEBUG_DBGP_NONE)
+
+ /* Non standard functions */
+ DBGP_FUNC_ENTRY(xcmd_profiler_name_get, XDEBUG_DBGP_POST_MORTEM)
         { NULL, NULL }
 };
 
@@ -1448,7 +1455,7 @@
                 XDEBUG_STR_CASE_END
 
                 XDEBUG_STR_CASE("supports_postmortem")
- xdebug_xml_add_text(*retval, xdstrdup("0"));
+ xdebug_xml_add_text(*retval, xdstrdup("1"));
                         xdebug_xml_add_attribute(*retval, "supported", "1");
                 XDEBUG_STR_CASE_END
 
@@ -1857,6 +1864,14 @@
         }
 }
 
+DBGP_FUNC(xcmd_profiler_name_get)
+{
+ if (XG(profiler_enabled) && XG(profile_filename)) {
+ xdebug_xml_add_text(*retval, xdstrdup(XG(profile_filename)));
+ } else {
+ RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_PROFILING_NOT_STARTED);
+ }
+}
 
 
 /*****************************************************************************
@@ -2049,6 +2064,7 @@
                 error = xdebug_xml_node_init("error");
                 xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", res), 0, 1);
                 xdebug_xml_add_child(retval, error);
+ ADD_REASON_MESSAGE(res);
         } else {
 
                 /* Execute commands and stuff */
@@ -2061,12 +2077,21 @@
                                 XG(lastcmd) = command->name;
                                 XG(lasttransid) = xdstrdup(CMD_OPTION('i'));
                         }
- command->handler((xdebug_xml_node**) &retval, context, args TSRMLS_CC);
+ if (XG(status) != DBGP_STATUS_STOPPED || (XG(status) == DBGP_STATUS_STOPPED && command->flags & XDEBUG_DBGP_POST_MORTEM)) {
+ command->handler((xdebug_xml_node**) &retval, context, args TSRMLS_CC);
+ ret = command->cont;
+ } else {
+ error = xdebug_xml_node_init("error");
+ xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", XDEBUG_ERROR_COMMAND_UNAVAILABLE), 0, 1);
+ ADD_REASON_MESSAGE(XDEBUG_ERROR_COMMAND_UNAVAILABLE);
+ xdebug_xml_add_child(retval, error);
 
- ret = command->cont;
+ ret = -1;
+ }
                 } else {
                         error = xdebug_xml_node_init("error");
                         xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", XDEBUG_ERROR_UNIMPLEMENTED), 0, 1);
+ ADD_REASON_MESSAGE(XDEBUG_ERROR_UNIMPLEMENTED);
                         xdebug_xml_add_child(retval, error);
 
                         ret = -1;
@@ -2084,7 +2109,7 @@
 
 char *xdebug_dbgp_get_revision(void)
 {
- return "$Revision: 1.104 $";
+ return "$Revision: 1.105 $";
 }
 
 int xdebug_dbgp_cmdloop(xdebug_con *context TSRMLS_DC)
@@ -2246,6 +2271,8 @@
         send_message(context, response TSRMLS_CC);
         xdebug_xml_node_dtor(response);
 
+ xdebug_dbgp_cmdloop(context TSRMLS_CC);
+
         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;

[FILE: /xdebug/xdebug_handler_dbgp.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- xdebug/xdebug_handler_dbgp.h:1.17 Tue Feb 21 19:43:17 2006 GMT
+++ xdebug/xdebug_handler_dbgp.h Fri Nov 10 10:33:29 2006 GMT
@@ -31,6 +31,19 @@
         int code;
 } xdebug_dbgp_result;
 
+#define ADD_REASON_MESSAGE(c) { \
+ xdebug_xml_node *message = xdebug_xml_node_init("message"); \
+ xdebug_error_entry *error_entry = &xdebug_error_codes[0]; \
+ \
+ while (error_entry->message) { \
+ if ((c) == error_entry->code) { \
+ xdebug_xml_add_text(message, xdstrdup(error_entry->message)); \
+ xdebug_xml_add_child(error, message); \
+ } \
+ error_entry++; \
+ } \
+}
+
 #define RETURN_RESULT(s, r, c) { \
         xdebug_xml_node *error = xdebug_xml_node_init("error"); \
         xdebug_xml_node *message = xdebug_xml_node_init("message"); \
@@ -59,13 +72,17 @@
 #define DBGP_FUNC_PARAMETERS xdebug_xml_node **retval, xdebug_con *context, xdebug_dbgp_arg *args TSRMLS_DC
 #define DBGP_FUNC_PASS_PARAMETERS retval, context, args TSRMLS_CC
 #define DBGP_FUNC(name) static void xdebug_dbgp_handle_##name(DBGP_FUNC_PARAMETERS)
-#define DBGP_FUNC_ENTRY(name) { #name, xdebug_dbgp_handle_##name, 0 },
-#define DBGP_CONT_FUNC_ENTRY(name) { #name, xdebug_dbgp_handle_##name, 1 },
+#define DBGP_FUNC_ENTRY(name,flags) { #name, xdebug_dbgp_handle_##name, 0, flags },
+#define DBGP_CONT_FUNC_ENTRY(name,flags) { #name, xdebug_dbgp_handle_##name, 1, flags },
+
+#define XDEBUG_DBGP_NONE 0x00
+#define XDEBUG_DBGP_POST_MORTEM 0x01
 
 typedef struct xdebug_dbgp_cmd {
         char *name;
         void (*handler)(DBGP_FUNC_PARAMETERS);
         int cont;
+ int flags;
 } xdebug_dbgp_cmd;
 
 #define CMD_OPTION(opt) (opt == '-' ? args->value[26] : args->value[(opt) - 'a'])

[FILE: /xdebug/xdebug_private.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- xdebug/xdebug_private.h:1.20 Mon Sep 25 18:20:01 2006 GMT
+++ xdebug/xdebug_private.h Fri Nov 10 10:33:29 2006 GMT
@@ -89,7 +89,7 @@
 #define XDEBUG_ERROR_DUP_ARG 2
 #define XDEBUG_ERROR_INVALID_ARGS 3
 #define XDEBUG_ERROR_UNIMPLEMENTED 4
-#define XDEBUG_ERROR_COMMAND_UNAVAILABLE 5 /* unused */
+#define XDEBUG_ERROR_COMMAND_UNAVAILABLE 5
 
 #define XDEBUG_ERROR_CANT_OPEN_FILE 100
 #define XDEBUG_ERROR_STREAM_REDIRECT_FAILED 101 /* unused */
@@ -107,6 +107,8 @@
 #define XDEBUG_ERROR_STACK_DEPTH_INVALID 301
 #define XDEBUG_ERROR_CONTEXT_INVALID 302 /* unused */
 
+#define XDEBUG_ERROR_PROFILING_NOT_STARTED 400
+
 #define XDEBUG_ERROR_ENCODING_NOT_SUPPORTED 900
 
 typedef struct _xdebug_func {
Received on Fri Nov 10 2006 - 12:33:37 GMT

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