[xdebug-dev] xdebug xdebug/xdebug_compat.c xdebug/xdebug_handler_dbgp.c xdebug/xdebug_handler_dbgp.h xdebug/debugclient/main.c - Added error messages to returned errors (in most cases)

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Thu, 11 Nov 2004 17:30:12 +0100

Date: Thu Nov 11 17:30:12 CET 2004
User: Derick Rethans
Directory: xdebug

Log Message:
[2.00]
- Added error messages to returned errors (in most cases)
- Make property_get and property_value finally work as they should, including
  retrieving information from different depths then the most top stack frame.
- Fixed warnings because of updated API numbers

Modified files:
           xdebug/xdebug_compat.c (version: 1.6)
           xdebug/xdebug_handler_dbgp.c (version: 1.66)
           xdebug/xdebug_handler_dbgp.h (version: 1.14)
           xdebug/debugclient/main.c (version: 1.30)

[FILE: /xdebug/xdebug_compat.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- xdebug/xdebug_compat.c:1.5 Mon Jul 19 17:51:26 2004 GMT
+++ xdebug/xdebug_compat.c Thu Nov 11 15:30:12 2004 GMT
@@ -16,7 +16,7 @@
    | Modifications: Derick Rethans <derick[@]xdebug.org> |
    +----------------------------------------------------------------------+
  */
-/* $Id: cvstemp,v 1.5 2004/07/19 19:51:26 helly Exp $ */
+/* $Id: cvstemp,v 1.6 2004/11/11 16:30:12 derick Exp $ */
 
 #include "php.h"
 #include "main/php_version.h"
@@ -303,7 +303,7 @@
                                         || ((int)T->str_offset.offset<0)
                                         || (T->str_offset.str->value.str.len <= T->str_offset.offset)) {
                                         zend_error(E_NOTICE, "Uninitialized string offset: %d", T->str_offset.offset);
-#if ZEND_EXTENSION_API_NO >= 220040718
+#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1
                                         T->tmp_var.value.str.val = STR_EMPTY_ALLOC();
 #else
                                         T->tmp_var.value.str.val = empty_string;
@@ -370,7 +370,7 @@
                                                                 || (T->EA.data.str_offset.offset<0)
                                                                 || (T->EA.data.str_offset.str->value.str.len <= T->EA.data.str_offset.offset)) {
                                                                 zend_error(E_NOTICE, "Uninitialized string offset: %d", T->EA.data.str_offset.offset);
-#if ZEND_EXTENSION_API_NO >= 220040718
+#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1
                                                                 T->tmp_var.value.str.val = STR_EMPTY_ALLOC();
 #else
                                                                 T->tmp_var.value.str.val = empty_string;

[FILE: /xdebug/xdebug_handler_dbgp.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -r1.65 -r1.66
--- xdebug/xdebug_handler_dbgp.c:1.65 Mon Nov 08 08:40:28 2004 GMT
+++ xdebug/xdebug_handler_dbgp.c Thu Nov 11 15:30:12 2004 GMT
@@ -73,6 +73,37 @@
 char *xdebug_dbgp_reason_strings[4] =
         {"ok", "error", "aborted", "exception"};
 
+typedef struct {
+ int code;
+ char *message;
+} xdebug_error_entry;
+
+xdebug_error_entry xdebug_error_codes[23] = {
+ { 0, "no error" },
+ { 1, "parse error in command" },
+ { 2, "duplicate arguments in command" },
+ { 3, "invalid or missing options" },
+ { 4, "unimplemented command" },
+ { 5, "command is not available" },
+ { 100, "can not open file" },
+ { 101, "stream redirect failed" },
+ { 200, "breakpoint could not be set" },
+ { 201, "breakpoint type is not supported" },
+ { 202, "invalid breakpoint line" },
+ { 203, "no code on breakpoint line" },
+ { 204, "invalid breakpoint state" },
+ { 205, "no such breakpoint" },
+ { 206, "error evaluating code" },
+ { 207, "invalid expression" },
+ { 300, "can not get property" },
+ { 301, "stack depth invalid" },
+ { 302, "context invalid" },
+ { 900, "encoding not supported" },
+ { 998, "an internal exception in the debugger" },
+ { 999, "unknown error" },
+ { -1, NULL }
+};
+
 #define XDEBUG_STR_SWITCH_DECL char *__switch_variable
 #define XDEBUG_STR_SWITCH(s) __switch_variable = (s);
 #define XDEBUG_STR_CASE(s) if (strcmp(__switch_variable, s) == 0) {
@@ -245,7 +276,7 @@
         return NULL;
 }
 
-static xdebug_xml_node* get_symbol_contents(char* name, int name_length TSRMLS_DC)
+static xdebug_xml_node* get_symbol(char* name, int name_length TSRMLS_DC)
 {
         zval *retval;
 
@@ -257,6 +288,19 @@
         return NULL;
 }
 
+int get_symbol_contents(char* name, int name_length, xdebug_xml_node *node TSRMLS_DC)
+{
+ zval *retval;
+
+ retval = get_symbol_contents_zval(name, name_length TSRMLS_CC);
+ if (retval) {
+ xdebug_var_export_xml_node(&retval, name, node, 1 TSRMLS_CC);
+ return 1;
+ }
+
+ return 0;
+}
+
 static char* return_source(char *filename, int begin, int end TSRMLS_DC)
 {
         php_stream *stream;
@@ -1105,16 +1149,19 @@
         xdebug_xml_node *contents;
         zval ret_zval;
         int res;
+ HashTable *tmp_symbol_table;
 
- contents = get_symbol_contents(name, name_length TSRMLS_CC);
-
+ contents = get_symbol(name, name_length TSRMLS_CC);
         if (!contents && !no_eval) {
                 char *varname = NULL;
                 if (var_only && name[0] != '$') {
                         varname = xdebug_sprintf("$%s", name);
                 }
                 /* if we cannot get the value directly, then try eval */
+ tmp_symbol_table = EG(active_symbol_table);
+ EG(active_symbol_table) = XG(active_symbol_table);
                 res = _xdebug_do_eval(varname ? varname : name, &ret_zval TSRMLS_CC);
+ EG(active_symbol_table) = tmp_symbol_table;
                 if (res != FAILURE && (!non_null || Z_TYPE_P(&ret_zval) != IS_NULL)) {
                         contents = get_zval_value_xml_node(name, &ret_zval);
                         zval_dtor(&ret_zval);
@@ -1215,54 +1262,67 @@
         }
 }
 
-
-DBGP_FUNC(property_value)
+static int add_variable_contents_node(xdebug_xml_node *node, char *name, int name_length, int var_only, int non_null, int no_eval TSRMLS_DC)
 {
- zval *var_data;
- zval ret_zval;
- zval *p_ret_zval = &ret_zval;
- int res;
- char *name = CMD_OPTION('n');
- long context_id = 0, depth = 0;
-
- /* XXX TODO
- * handle the depth value and set the property at a specific stack depth
- *
- * handle the context_id value and set the property in the correct context
- */
+ int contents_found;
+ zval ret_zval;
+ int res;
+ HashTable *tmp_symbol_table;
 
- if (CMD_OPTION('d')) {
- depth = strtol(CMD_OPTION('d'), NULL, 10);
+ contents_found = get_symbol_contents(name, name_length, node TSRMLS_CC);
+ if (!contents_found && !no_eval) {
+ char *varname = NULL;
+ if (var_only && name[0] != '$') {
+ varname = xdebug_sprintf("$%s", name);
+ }
+ /* if we cannot get the value directly, then try eval */
+ tmp_symbol_table = EG(active_symbol_table);
+ EG(active_symbol_table) = XG(active_symbol_table);
+ res = _xdebug_do_eval(varname ? varname : name, &ret_zval TSRMLS_CC);
+ EG(active_symbol_table) = tmp_symbol_table;
+ if (res != FAILURE && (!non_null || Z_TYPE_P(&ret_zval) != IS_NULL)) {
+ zval *tmp_zval = &ret_zval;
+
+ xdebug_var_export_xml_node(&tmp_zval, name, node, 1 TSRMLS_CC);
+ contents_found = 1;
+ zval_dtor(&ret_zval);
+ }
+ if (varname) {
+ xdfree(varname);
+ }
         }
- if (CMD_OPTION('c')) {
- context_id = strtol(CMD_OPTION('c'), NULL, 10);
+ if (contents_found) {
+ return SUCCESS;
         }
+ return FAILURE;
+}
+DBGP_FUNC(property_value)
+{
+ int depth = -1;
+ function_stack_entry *fse;
 
- if (!name) {
+ if (!CMD_OPTION('n')) {
                 RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_INVALID_ARGS);
         }
 
- XG(active_symbol_table) = EG(active_symbol_table);
- var_data = get_symbol_contents_zval(name, strlen(name) + 1 TSRMLS_CC);
- XG(active_symbol_table) = NULL;
-
- if (var_data) {
- /* XXX cheesy and lame, gets more than we want */
- xdebug_var_export_xml_node(&p_ret_zval, name, *retval, 0 TSRMLS_CC);
- zval_dtor(p_ret_zval);
+ if (CMD_OPTION('d')) {
+ depth = strtol(CMD_OPTION('d'), NULL, 10);
+ }
+ /* Set the symbol table corresponding with the requested stack depth */
+ if (depth == -1) {
+ XG(active_symbol_table) = EG(active_symbol_table);
         } else {
- /* if we cannot get the value directly, then try eval */
- res = _xdebug_do_eval(CMD_OPTION('n'), p_ret_zval TSRMLS_CC);
- if (res == FAILURE) {
- RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTANT);
+ if ((fse = xdebug_get_stack_frame(depth TSRMLS_CC))) {
+ XG(active_symbol_table) = fse->symbol_table;
                 } else {
- /* XXX cheesy and lame, gets more than we want */
- xdebug_var_export_xml_node(&p_ret_zval, name, *retval, 0 TSRMLS_CC);
- zval_dtor(p_ret_zval);
+ RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_STACK_DEPTH_INVALID);
                 }
         }
-}
 
+ if (add_variable_contents_node(*retval, CMD_OPTION('n'), strlen(CMD_OPTION('n')) + 1, 1, 0, 0 TSRMLS_CC) == FAILURE) {
+ RETURN_RESULT(XG(status), XG(reason), XDEBUG_ERROR_PROPERTY_NON_EXISTANT);
+ }
+}
 static void attach_used_var_with_contents(void *xml, xdebug_hash_element* he)
 {
         char *name = (char*) he->ptr;
@@ -1271,7 +1331,7 @@
         xdebug_xml_node *contents;
         TSRMLS_FETCH();
 
- contents = get_symbol_contents(name, strlen(name) + 1 TSRMLS_CC);
+ contents = get_symbol(name, strlen(name) + 1 TSRMLS_CC);
         if (contents) {
                 xdebug_xml_add_child(node, contents);
         } else {
@@ -1572,6 +1632,7 @@
         }
 
         /* Handle parse errors */
+ /* FIXME: use RETURN_RESULT here too */
         if (res != XDEBUG_ERROR_OK) {
                 error = xdebug_xml_node_init("error");
                 xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%lu", res), 0, 1);
@@ -1611,7 +1672,7 @@
 
 char *xdebug_dbgp_get_revision(void)
 {
- return "$Revision: 1.65 $";
+ return "$Revision: 1.66 $";
 }
 
 int xdebug_dbgp_cmdloop(xdebug_con *context TSRMLS_DC)

[FILE: /xdebug/xdebug_handler_dbgp.h]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- xdebug/xdebug_handler_dbgp.h:1.13 Sun Jul 18 17:52:08 2004 GMT
+++ xdebug/xdebug_handler_dbgp.h Thu Nov 11 15:30:12 2004 GMT
@@ -33,23 +33,20 @@
 
 #define RETURN_RESULT(s, r, c) { \
         xdebug_xml_node *error = xdebug_xml_node_init("error"); \
- \
- xdebug_xml_add_attribute(*retval, "status", xdebug_dbgp_status_strings[(s)]); \
- xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_strings[(r)]); \
- xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%u", (c)), 0, 1); \
- xdebug_xml_add_child(*retval, error); \
- return; \
-}
-
-#define RETURN_RESULT_MESSAGE(s, r, c, msg) { \
- xdebug_xml_node *error = xdebug_xml_node_init("error"); \
         xdebug_xml_node *message = xdebug_xml_node_init("message"); \
+ xdebug_error_entry *error_entry = &xdebug_error_codes[0]; \
         \
         xdebug_xml_add_attribute(*retval, "status", xdebug_dbgp_status_strings[(s)]); \
         xdebug_xml_add_attribute(*retval, "reason", xdebug_dbgp_reason_strings[(r)]); \
         xdebug_xml_add_attribute_ex(error, "code", xdebug_sprintf("%u", (c)), 0, 1); \
- xdebug_xml_add_text(message, xdstrdup(msg), 0, 1); \
- xdebug_xml_add_child(error, message); \
+ \
+ 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++; \
+ } \
         xdebug_xml_add_child(*retval, error); \
         return; \
 }

[FILE: /xdebug/debugclient/main.c]

===================================================================
RCS file: cvstemp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -r1.29 -r1.30
--- xdebug/debugclient/main.c:1.29 Wed Oct 06 04:58:02 2004 GMT
+++ xdebug/debugclient/main.c Thu Nov 11 15:30:12 2004 GMT
@@ -50,7 +50,7 @@
 #define MSG_NOSIGNAL 0
 #endif
 
-#define DEBUGCLIENT_VERSION "0.8.0"
+#define DEBUGCLIENT_VERSION "0.9.0"
 #define DEFAULT_PORT 9000
 
 #ifdef HAVE_LIBEDIT
@@ -114,6 +114,7 @@
 {
         int port = DEFAULT_PORT; /* Port number to listen for connections */
         int ssocket = 0; /* Socket file descriptor */
+ int debug_once = 1; /* Whether to allow more than one debug session (1 = no) */
         struct sockaddr_in server_in;
         struct sockaddr_in client_in;
         int client_in_len;
@@ -154,10 +155,10 @@
         printf("- libedit support: enabled\n");
 #endif
 
-#ifndef WIN32
+#ifndef WIN32
         /* Option handling */
         while (1) {
- opt = getopt(argc, argv, "hp:v");
+ opt = getopt(argc, argv, "hp:v1");
 
                 if (opt == -1) {
                         break;
@@ -170,6 +171,7 @@
                                 printf("\t-h\tShow this help\n");
                                 printf("\t-p\tSpecify the port to listen on (default = 9000)\n");
                                 printf("\t-v\tShow version number and exit\n");
+ printf("\t-1\tDebug once and then exit\n");
                                 exit(0);
                                 break;
                         case 'v':
@@ -179,13 +181,16 @@
                                 port = atoi(optarg);
                                 printf("Listening on TCP port %d.\n", port);
                                 break;
+ case '1':
+ debug_once = 0;
+ break;
                 }
- }
+ }
 #endif
 
         /* Main loop that listens for connections from the debug client and that
          * does all the communications handling. */
- while (1) {
+ do {
                 ssocket = socket(AF_INET, SOCK_STREAM, 0);
                 if (ssocket < 0) {
                         fprintf(stderr, "socket: couldn't create socket\n");
@@ -289,5 +294,5 @@
 
                 /* Sleep some time to reset the TCP/IP connection */
                 sleep(1);
- }
+ } while (debug_once);
 }
Received on Thu Nov 11 2004 - 17:30:15 GMT

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