Skip to content
Browse files

Added support for serialized "collect_params".

This is option 5 to collect_params, and when enabled will also add serialized
return values into the machine readable traces as an extra line with type "R".
  • Loading branch information...
1 parent 0837146 commit c53907b8d776eb09a84deabb20bc1b7d8535ac7a @derickr derickr committed Sep 10, 2013
Showing with 92 additions and 14 deletions.
  1. +3 −3 xdebug.c
  2. +6 −1 xdebug_stack.c
  3. +47 −9 xdebug_tracing.c
  4. +1 −1 xdebug_tracing.h
  5. +34 −0 xdebug_var.c
  6. +1 −0 xdebug_var.h
View
6 xdebug.c
@@ -1451,10 +1451,10 @@ void xdebug_execute_ex(zend_execute_data *execute_data TSRMLS_DC)
if (op_array->fn_flags & ZEND_ACC_GENERATOR) {
t = xdebug_return_trace_stack_generator_retval(fse, (zend_generator *) EG(return_value_ptr_ptr) TSRMLS_CC);
} else {
- t = xdebug_return_trace_stack_retval(fse, *EG(return_value_ptr_ptr) TSRMLS_CC);
+ t = xdebug_return_trace_stack_retval(fse, function_nr, *EG(return_value_ptr_ptr) TSRMLS_CC);
}
#else
- t = xdebug_return_trace_stack_retval(fse, *EG(return_value_ptr_ptr) TSRMLS_CC);
+ t = xdebug_return_trace_stack_retval(fse, function_nr, *EG(return_value_ptr_ptr) TSRMLS_CC);
#endif
fprintf(XG(trace_file), "%s", t);
fflush(XG(trace_file));
@@ -1571,7 +1571,7 @@ void xdebug_execute_internal(zend_execute_data *current_execute_data, struct _ze
if (cur_opcode) {
zval *ret = xdebug_zval_ptr(cur_opcode->XDEBUG_TYPE(result), &(cur_opcode->result), current_execute_data TSRMLS_CC);
if (ret) {
- char* t = xdebug_return_trace_stack_retval(fse, ret TSRMLS_CC);
+ char* t = xdebug_return_trace_stack_retval(fse, function_nr, ret TSRMLS_CC);
fprintf(XG(trace_file), "%s", t);
fflush(XG(trace_file));
xdfree(t);
View
7 xdebug_stack.c
@@ -337,7 +337,7 @@ void xdebug_append_printable_stack(xdebug_str *str, int html TSRMLS_DC)
c = 1;
}
- if (i->var[j].name && XG(collect_params) >= 4) {
+ if (i->var[j].name && XG(collect_params) == 4) {
if (html) {
xdebug_str_add(str, xdebug_sprintf("<span>$%s = </span>", i->var[j].name), 1);
} else {
@@ -358,6 +358,8 @@ void xdebug_append_printable_stack(xdebug_str *str, int html TSRMLS_DC)
xdebug_str_add(str, xdebug_sprintf("<span title='%s'>%s</span>", tmp_fancy_value, tmp_fancy_synop_value), 1);
break;
case 3: /* full */
+ case 4: /* full (with var_name) */
+ case 5: /* serialized */
default:
xdebug_str_add(str, xdebug_sprintf("<span>%s</span>", tmp_fancy_value), 1);
break;
@@ -375,6 +377,9 @@ void xdebug_append_printable_stack(xdebug_str *str, int html TSRMLS_DC)
default:
tmp_value = xdebug_get_zval_value(i->var[j].addr, 0, NULL);
break;
+ case 5:
+ tmp_value = xdebug_get_zval_value_serialized(i->var[j].addr, 0, NULL);
+ break;
}
if (tmp_value) {
xdebug_str_add(str, xdebug_sprintf("%s", tmp_value), 1);
View
56 xdebug_tracing.c
@@ -107,18 +107,36 @@ static void xdebug_return_trace_stack_common(xdebug_str *str, function_stack_ent
xdebug_str_addl(str, " >=> ", 7, 0);
}
-char* xdebug_return_trace_stack_retval(function_stack_entry* i, zval* retval TSRMLS_DC)
+static char* return_trace_stack_retval_normal(function_stack_entry* i, zval* retval TSRMLS_DC)
{
xdebug_str str = {0, 0, NULL};
char *tmp_value;
- if (XG(trace_format) != 0) {
+ xdebug_return_trace_stack_common(&str, i TSRMLS_CC);
+
+ tmp_value = xdebug_get_zval_value(retval, 0, NULL);
+ if (tmp_value) {
+ xdebug_str_add(&str, tmp_value, 1);
+ }
+ xdebug_str_addl(&str, "\n", 2, 0);
+
+ return str.d;
+}
+
+static char* return_trace_stack_retval_computerized(function_stack_entry* i, int fnr, zval* retval TSRMLS_DC)
+{
+ xdebug_str str = {0, 0, NULL};
+ char *tmp_value;
+
+ if (XG(collect_params) != 5) {
return xdstrdup("");
}
- xdebug_return_trace_stack_common(&str, i TSRMLS_CC);
+ xdebug_str_add(&str, xdebug_sprintf("%d\t", i->level), 1);
+ xdebug_str_add(&str, xdebug_sprintf("%d\t", fnr), 1);
+ xdebug_str_add(&str, "R\t\t\t", 0);
- tmp_value = xdebug_get_zval_value(retval, 0, NULL);
+ tmp_value = xdebug_get_zval_value_serialized(retval, 0, NULL);
if (tmp_value) {
xdebug_str_add(&str, tmp_value, 1);
}
@@ -127,6 +145,18 @@ char* xdebug_return_trace_stack_retval(function_stack_entry* i, zval* retval TSR
return str.d;
}
+char* xdebug_return_trace_stack_retval(function_stack_entry* i, int fnr, zval* retval TSRMLS_DC)
+{
+ switch (XG(trace_format)) {
+ case 0:
+ return return_trace_stack_retval_normal(i, retval TSRMLS_CC);
+ case 1:
+ return return_trace_stack_retval_computerized(i, fnr, retval TSRMLS_CC);
+ default:
+ return xdstrdup("");
+ }
+}
+
#if PHP_VERSION_ID >= 50500
char* xdebug_return_trace_stack_generator_retval(function_stack_entry* i, zend_generator* generator TSRMLS_DC)
{
@@ -191,7 +221,7 @@ static char* return_trace_stack_frame_begin_normal(function_stack_entry* i TSRML
c = 1;
}
- if (i->var[j].name && XG(collect_params) >= 4) {
+ if (i->var[j].name && XG(collect_params) == 4) {
xdebug_str_add(&str, xdebug_sprintf("$%s = ", i->var[j].name), 1);
}
@@ -200,10 +230,14 @@ static char* return_trace_stack_frame_begin_normal(function_stack_entry* i TSRML
case 2:
tmp_value = xdebug_get_zval_synopsis(i->var[j].addr, 0, NULL);
break;
- case 3:
+ case 3: /* full */
+ case 4: /* full (with var) */
default:
tmp_value = xdebug_get_zval_value(i->var[j].addr, 0, NULL);
break;
+ case 5: /* serialized */
+ tmp_value = xdebug_get_zval_value_serialized(i->var[j].addr, 0, NULL);
+ break;
}
if (tmp_value) {
xdebug_str_add(&str, tmp_value, 1);
@@ -284,7 +318,7 @@ static char* return_trace_stack_frame_computerized(function_stack_entry* i, int
xdebug_str_addl(&str, "\t", 1, 0);
- if (i->var[j].name && XG(collect_params) >= 4) {
+ if (i->var[j].name && XG(collect_params) == 4) {
xdebug_str_add(&str, xdebug_sprintf("$%s = ", i->var[j].name), 1);
}
@@ -293,10 +327,14 @@ static char* return_trace_stack_frame_computerized(function_stack_entry* i, int
case 2:
tmp_value = xdebug_get_zval_synopsis(i->var[j].addr, 0, NULL);
break;
- case 3:
+ case 3: /* full */
+ case 4: /* full (with var) */
default:
tmp_value = xdebug_get_zval_value(i->var[j].addr, 0, NULL);
break;
+ case 5: /* serialized */
+ tmp_value = xdebug_get_zval_value_serialized(i->var[j].addr, 0, NULL);
+ break;
}
if (tmp_value) {
xdebug_str_add(&str, tmp_value, 1);
@@ -459,7 +497,7 @@ char* xdebug_start_trace(char* fname, long options TSRMLS_DC)
if (XG(trace_file)) {
if (XG(trace_format) == 1) {
fprintf(XG(trace_file), "Version: %s\n", XDEBUG_VERSION);
- fprintf(XG(trace_file), "File format: 2\n");
+ fprintf(XG(trace_file), "File format: 3\n");
}
if (XG(trace_format) == 0 || XG(trace_format) == 1) {
str_time = xdebug_get_time();
View
2 xdebug_tracing.h
@@ -19,7 +19,7 @@
#ifndef XDEBUG_TRACING_H
#define XDEBUG_TRACING_H
-char* xdebug_return_trace_stack_retval(function_stack_entry* i, zval* retval TSRMLS_DC);
+char* xdebug_return_trace_stack_retval(function_stack_entry* i, int fnr, zval* retval TSRMLS_DC);
#if PHP_VERSION_ID >= 50500
char* xdebug_return_trace_stack_generator_retval(function_stack_entry* i, zend_generator* generator TSRMLS_DC);
#endif
View
34 xdebug_var.c
@@ -19,6 +19,7 @@
#include "php.h"
#include "ext/standard/php_string.h"
#include "ext/standard/url.h"
+#include "ext/standard/php_smart_str.h"
#include "zend.h"
#include "zend_extensions.h"
@@ -1595,6 +1596,39 @@ char* xdebug_get_zval_value_fancy(char *name, zval *val, int *len, int debug_zva
return str.d;
}
+char* xdebug_get_zval_value_serialized(zval *val, int debug_zval, xdebug_var_export_options *options)
+{
+ php_serialize_data_t var_hash;
+ smart_str buf = {0};
+
+ PHP_VAR_SERIALIZE_INIT(var_hash);
+ php_var_serialize(&buf, &val, &var_hash TSRMLS_CC);
+ PHP_VAR_SERIALIZE_DESTROY(var_hash);
+
+ if (EG(exception)) {
+ smart_str_free(&buf);
+ return NULL;
+ }
+
+ if (buf.c) {
+ int new_len;
+ char *tmp_base64, *tmp_ret;
+
+ /* now we need to base64 it */
+ tmp_base64 = (char*) xdebug_base64_encode((unsigned char*) buf.c, buf.len, &new_len);
+
+ /* we need a malloc'ed and not an emalloc'ed string */
+ tmp_ret = xdstrdup(tmp_base64);
+
+ efree(tmp_base64);
+ smart_str_free(&buf);
+
+ return tmp_ret;
+ } else {
+ return NULL;
+ }
+}
+
static void xdebug_var_synopsis_fancy(zval **struc, xdebug_str *str, int level, int debug_zval, xdebug_var_export_options *options TSRMLS_DC)
{
HashTable *myht;
View
1 xdebug_var.h
@@ -71,6 +71,7 @@ char* xdebug_get_zval_value_text_ansi(zval *val, int mode, int debug_zval, xdebu
#define xdebug_get_zval_value_ansi(v,d,o) xdebug_get_zval_value_text_ansi(v,1,d,o TSRMLS_CC);
char* xdebug_get_zval_value_xml(char *name, zval *val);
char* xdebug_get_zval_value_fancy(char *name, zval *val, int *len, int debug_zval, xdebug_var_export_options *options TSRMLS_DC);
+char* xdebug_get_zval_value_serialized(zval *val, int debug_zval, xdebug_var_export_options *options);
void xdebug_attach_static_vars(xdebug_xml_node *node, xdebug_var_export_options *options, zend_class_entry *ce TSRMLS_DC);
void xdebug_attach_uninitialized_var(xdebug_xml_node *node, char *name);

0 comments on commit c53907b

Please sign in to comment.
Something went wrong with that request. Please try again.