void xdebug_append_error_description(xdebug_str *str, int html, const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno TSRMLS_DC) { char **formats = select_formats(html TSRMLS_CC); char *escaped; #if PHP_VERSION_ID >= 50400 size_t newlen; #else int newlen; #endif if (html) { escaped = php_escape_html_entities_ex(buffer, strlen(buffer), &newlen, 0, 0, NULL, 1 TSRMLS_CC); } else { escaped = estrdup(buffer); } if (strlen(XG(file_link_format)) > 0 && html) { char *file_link; create_file_link(&file_link, error_filename, error_lineno TSRMLS_CC); xdebug_str_add(str, xdebug_sprintf(formats[11], error_type_str, escaped, file_link, error_filename, error_lineno), 1); xdfree(file_link); } else { xdebug_str_add(str, xdebug_sprintf(formats[1], error_type_str, escaped, error_filename, error_lineno), 1); } efree(escaped); }
void xdebug_xml_return_node(xdebug_xml_node* node, struct xdebug_str *output) { xdebug_str_addl(output, "<", 1, 0); xdebug_str_add(output, node->tag, 0); if (node->text && node->text->encode) { xdebug_xml_add_attribute_ex(node, "encoding", "base64", 0, 0); } if (node->attribute) { xdebug_xml_return_attribute(node->attribute, output); } xdebug_str_addl(output, ">", 1, 0); if (node->child) { xdebug_xml_return_node(node->child, output); } if (node->text) { xdebug_xml_return_text_node(node->text, output); } xdebug_str_addl(output, "</", 2, 0); xdebug_str_add(output, node->tag, 0); xdebug_str_addl(output, ">", 1, 0); if (node->next) { xdebug_xml_return_node(node->next, output); } }
static int create_file_link(char **filename, const char *error_filename, int error_lineno TSRMLS_DC) { xdebug_str fname = {0, 0, NULL}; char *format = XG(file_link_format); while (*format) { if (*format != '%') { xdebug_str_addl(&fname, (char *) format, 1, 0); } else { format++; switch (*format) { case 'f': /* filename */ xdebug_str_add(&fname, xdebug_sprintf("%s", error_filename), 1); break; case 'l': /* line number */ xdebug_str_add(&fname, xdebug_sprintf("%d", error_lineno), 1); break; case '%': /* literal % */ xdebug_str_addl(&fname, "%", 1, 0); break; } } format++; } *filename = fname.d; return fname.l; }
static void dump_used_var_with_contents(void *htmlq, xdebug_hash_element* he, void *argument) { int html = *(int *)htmlq; int len; zval *zvar; char *contents; char *name = (char*) he->ptr; HashTable *tmp_ht; char **formats; xdebug_str *str = (xdebug_str *) argument; TSRMLS_FETCH(); if (!he->ptr) { return; } /* Bail out on $this and $GLOBALS */ if (strcmp(name, "this") == 0 || strcmp(name, "GLOBALS") == 0) { return; } #if PHP_VERSION_ID >= 50300 if (!EG(active_symbol_table)) { zend_rebuild_symbol_table(TSRMLS_C); } #endif tmp_ht = XG(active_symbol_table); XG(active_symbol_table) = EG(active_symbol_table); zvar = xdebug_get_php_symbol(name, strlen(name) + 1); XG(active_symbol_table) = tmp_ht; formats = select_formats(PG(html_errors) TSRMLS_CC); if (!zvar) { xdebug_str_add(str, xdebug_sprintf(formats[9], name), 1); return; } if (html) { contents = xdebug_get_zval_value_fancy(NULL, zvar, &len, 0, NULL TSRMLS_CC); } else { contents = xdebug_get_zval_value(zvar, 0, NULL); } if (contents) { xdebug_str_add(str, xdebug_sprintf(formats[8], name, contents), 1); } else { xdebug_str_add(str, xdebug_sprintf(formats[9], name), 1); } xdfree(contents); }
void xdebug_log_stack(const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno TSRMLS_DC) { xdebug_llist_element *le; function_stack_entry *i; char *tmp_log_message; tmp_log_message = xdebug_sprintf( "PHP %s: %s in %s on line %d", error_type_str, buffer, error_filename, error_lineno); php_log_err(tmp_log_message TSRMLS_CC); xdfree(tmp_log_message); if (XG(stack) && XG(stack)->size) { php_log_err("PHP Stack trace:" TSRMLS_CC); for (le = XDEBUG_LLIST_HEAD(XG(stack)); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { int c = 0; /* Comma flag */ unsigned int j = 0; /* Counter */ char *tmp_name; xdebug_str log_buffer = {0, 0, NULL}; i = XDEBUG_LLIST_VALP(le); tmp_name = xdebug_show_fname(i->function, 0, 0 TSRMLS_CC); xdebug_str_add(&log_buffer, xdebug_sprintf("PHP %3d. %s(", i->level, tmp_name), 1); xdfree(tmp_name); /* Printing vars */ for (j = 0; j < i->varc; j++) { char *tmp_varname, *tmp_value; if (c) { xdebug_str_addl(&log_buffer, ", ", 2, 0); } else { c = 1; } tmp_varname = i->var[j].name ? xdebug_sprintf("$%s = ", i->var[j].name) : xdstrdup(""); xdebug_str_add(&log_buffer, tmp_varname, 0); xdfree(tmp_varname); if (i->var[j].addr) { tmp_value = xdebug_get_zval_value(i->var[j].addr, 0, NULL); xdebug_str_add(&log_buffer, tmp_value, 0); xdfree(tmp_value); } else { xdebug_str_addl(&log_buffer, "*uninitialized*", 15, 0); } } xdebug_str_add(&log_buffer, xdebug_sprintf(") %s:%d", i->filename, i->lineno), 1); php_log_err(log_buffer.d TSRMLS_CC); xdebug_str_free(&log_buffer); } } }
void xdebug_append_error_description(xdebug_str *str, int html, const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno TSRMLS_DC) { char **formats = select_formats(html TSRMLS_CC); if (strlen(XG(file_link_format)) > 0 && html) { char *file_link; create_file_link(&file_link, error_filename, error_lineno TSRMLS_CC); xdebug_str_add(str, xdebug_sprintf(formats[11], error_type_str, buffer, file_link, error_filename, error_lineno), 1); xdfree(file_link); } else { xdebug_str_add(str, xdebug_sprintf(formats[1], error_type_str, buffer, error_filename, error_lineno), 1); } }
static void xdebug_xml_return_text_node(xdebug_xml_text_node* node, xdebug_str* output) { xdebug_str_addl(output, "<![CDATA[", 9, 0); if (node->encode) { /* if cdata tags are in the text, then we must base64 encode */ String encoded_str = string_base64_encode((char*) node->text, node->text_len); char* encoded_text = encoded_str.get()->mutableData(); xdebug_str_add(output, encoded_text, 0); } else { xdebug_str_add(output, node->text, 0); } xdebug_str_addl(output, "]]>", 3, 0); }
static void xdebug_xml_return_attribute(xdebug_xml_attribute* attr, xdebug_str* output) { char *tmp; int newlen; xdebug_str_addl(output, " ", 1, 0); /* attribute name */ tmp = xdebug_xmlize(attr->name, attr->name_len, &newlen); xdebug_str_addl(output, tmp, newlen, 0); efree(tmp); /* attribute value */ xdebug_str_addl(output, "=\"", 2, 0); if (attr->value) { tmp = xdebug_xmlize(attr->value, attr->value_len, &newlen); xdebug_str_add(output, tmp, 0); efree(tmp); } xdebug_str_addl(output, "\"", 1, 0); if (attr->next) { xdebug_xml_return_attribute(attr->next, output); } }
static void xdebug_xml_return_text_node(xdebug_xml_text_node* node, xdebug_str* output) { xdebug_str_addl(output, "<![CDATA[", 9, 0); if (node->encode) { /* if cdata tags are in the text, then we must base64 encode */ int new_len = 0; char *encoded_text; encoded_text = (char*) xdebug_base64_encode((unsigned char*) node->text, node->text_len, &new_len); xdebug_str_add(output, encoded_text, 0); efree(encoded_text); } else { xdebug_str_add(output, node->text, 0); } xdebug_str_addl(output, "]]>", 3, 0); }
xdebug_str* xdebug_join(const char *delim, xdebug_arg *args, int begin, int end) { int i; xdebug_str *ret = xdebug_str_new(); if (begin < 0) { begin = 0; } if (end > args->c - 1) { end = args->c - 1; } for (i = begin; i < end; i++) { xdebug_str_add(ret, args->args[i], 0); xdebug_str_add(ret, delim, 0); } xdebug_str_add(ret, args->args[end], 0); return ret; }
static char *get_printable_stack(int html, const char *error_type_str, char *buffer, const char *error_filename, const int error_lineno TSRMLS_DC) { char *prepend_string; char *append_string; xdebug_str str = {0, 0, NULL}; prepend_string = INI_STR("error_prepend_string"); append_string = INI_STR("error_append_string"); xdebug_str_add(&str, prepend_string ? prepend_string : "", 0); xdebug_append_error_head(&str, html TSRMLS_CC); xdebug_append_error_description(&str, html, error_type_str, buffer, error_filename, error_lineno TSRMLS_CC); xdebug_append_printable_stack(&str, html TSRMLS_CC); xdebug_append_error_footer(&str, html TSRMLS_CC); xdebug_str_add(&str, append_string ? append_string : "", 0); return str.d; }
static void xdebug_xml_return_attribute(xdebug_xml_attribute* attr, xdebug_str* output) { char *tmp; int newlen; xdebug_str_addl(output, " ", 1, 0); xdebug_str_add(output, attr->name, 0); xdebug_str_addl(output, "=\"", 2, 0); if (attr->value) { // tmp = xmlize(attr->value, strlen(attr->value), &newlen); xdebug_str_add(output, attr->value, 0); // efree(tmp); } xdebug_str_addl(output, "\"", 1, 0); if (attr->next) { xdebug_xml_return_attribute(attr->next, output); } }
void xdebug_create_key_for_path(xdebug_path *path, xdebug_str *str) { unsigned int i; char temp_nr[16]; for (i = 0; i < path->elements_count; i++) { snprintf(temp_nr, 15, "%u:", path->elements[i]); xdebug_str_add(str, temp_nr, 0); } }
void XDebugServer::sendMessage(xdebug_xml_node& xml) { // Convert xml to an xdebug_str xdebug_str xml_message = {0, 0, nullptr}; xdebug_xml_return_node(&xml, &xml_message); size_t msg_len = xml_message.l + sizeof(XML_MSG_HEADER) - 1; // Log the message log("-> %s\n\n", xml_message.d); logFlush(); // Format the message xdebug_str* message; xdebug_str_ptr_init(message); xdebug_str_add(message, xdebug_sprintf("%d", msg_len, 1), 1); xdebug_str_addl(message, "\0", 1, 0); xdebug_str_add(message, XML_MSG_HEADER, 0); xdebug_str_add(message, xml_message.d, 0); xdebug_str_addl(message, "\0", 1, 0); xdebug_str_dtor(xml_message); // Write the message write(m_socket, message->d, message->l); xdebug_str_ptr_dtor(message); }
char* xdebug_return_trace_assignment(function_stack_entry *i, char *varname, zval *retval, char *op, char *filename, int lineno TSRMLS_DC) { int j = 0; xdebug_str str = {0, 0, NULL}; char *tmp_value; if (XG(trace_format) != 0) { return xdstrdup(""); } xdebug_str_addl(&str, " ", 20, 0); if (XG(show_mem_delta)) { xdebug_str_addl(&str, " ", 8, 0); } for (j = 0; j <= i->level; j++) { xdebug_str_addl(&str, " ", 2, 0); } xdebug_str_addl(&str, " => ", 6, 0); xdebug_str_add(&str, varname, 0); if (op[0] != '\0' ) { /* pre/post inc/dec ops are special */ xdebug_str_add(&str, xdebug_sprintf(" %s ", op), 1); tmp_value = xdebug_get_zval_value(retval, 0, NULL); if (tmp_value) { xdebug_str_add(&str, tmp_value, 1); } else { xdebug_str_addl(&str, "NULL", 4, 0); } } xdebug_str_add(&str, xdebug_sprintf(" %s:%d\n", filename, lineno), 1); return str.d; }
static void xdebug_xml_return_attribute(xdebug_xml_attribute* attr, xdebug_str* output) { String tmp; xdebug_str_addl(output, " ", 1, 0); /* attribute name */ tmp = xdebug_xmlize(attr->name, attr->name_len); xdebug_str_addl(output, tmp.get()->mutableData(), tmp.size(), 0); /* attribute value */ xdebug_str_addl(output, "=\"", 2, 0); if (attr->value) { tmp = xdebug_xmlize(attr->value, attr->value_len); xdebug_str_add(output, tmp.get()->mutableData(), 0); } xdebug_str_addl(output, "\"", 1, 0); if (attr->next) { xdebug_xml_return_attribute(attr->next, output); } }
void xdebug_append_printable_stack(xdebug_str *str, int html TSRMLS_DC) { xdebug_llist_element *le; function_stack_entry *i; int len; char **formats = select_formats(html TSRMLS_CC); if (XG(stack) && XG(stack)->size) { i = XDEBUG_LLIST_VALP(XDEBUG_LLIST_HEAD(XG(stack))); xdebug_str_add(str, formats[2], 0); for (le = XDEBUG_LLIST_HEAD(XG(stack)); le != NULL; le = XDEBUG_LLIST_NEXT(le)) { int c = 0; /* Comma flag */ int j = 0; /* Counter */ char *tmp_name; i = XDEBUG_LLIST_VALP(le); tmp_name = xdebug_show_fname(i->function, html, 0 TSRMLS_CC); if (html) { #if HAVE_PHP_MEMORY_USAGE xdebug_str_add(str, xdebug_sprintf(formats[3], i->level, i->time - XG(start_time), i->memory, tmp_name), 1); #else xdebug_str_add(str, xdebug_sprintf(formats[3], i->level, i->time - XG(start_time), tmp_name), 1); #endif } else { #if HAVE_PHP_MEMORY_USAGE xdebug_str_add(str, xdebug_sprintf(formats[3], i->time - XG(start_time), i->memory, i->level, tmp_name), 1); #else xdebug_str_add(str, xdebug_sprintf(formats[3], i->time - XG(start_time), i->level, tmp_name), 1); #endif } xdfree(tmp_name); /* Printing vars */ for (j = 0; j < i->varc; j++) { char *tmp_value, *tmp_fancy_value, *tmp_fancy_synop_value; int newlen; if (c) { xdebug_str_addl(str, ", ", 2, 0); } else { c = 1; } 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 { xdebug_str_add(str, xdebug_sprintf("$%s = ", i->var[j].name), 1); } } if (i->var[j].addr) { if (html) { tmp_value = xdebug_get_zval_value(i->var[j].addr, 0, NULL); tmp_fancy_value = xdebug_xmlize(tmp_value, strlen(tmp_value), &newlen); tmp_fancy_synop_value = xdebug_get_zval_synopsis_fancy("", i->var[j].addr, &len, 0, NULL TSRMLS_CC); switch (XG(collect_params)) { case 1: // synopsis xdebug_str_add(str, xdebug_sprintf("<span>%s</span>", tmp_fancy_synop_value), 1); break; case 2: // synopsis + full in tooltip xdebug_str_add(str, xdebug_sprintf("<span title='%s'>%s</span>", tmp_fancy_value, tmp_fancy_synop_value), 1); break; case 3: // full default: xdebug_str_add(str, xdebug_sprintf("<span>%s</span>", tmp_fancy_value), 1); break; } xdfree(tmp_value); efree(tmp_fancy_value); xdfree(tmp_fancy_synop_value); } else { switch (XG(collect_params)) { case 1: // synopsis case 2: tmp_value = xdebug_get_zval_synopsis(i->var[j].addr, 0, NULL); break; case 3: default: tmp_value = xdebug_get_zval_value(i->var[j].addr, 0, NULL); break; } if (tmp_value) { xdebug_str_add(str, xdebug_sprintf("%s", tmp_value), 1); xdfree(tmp_value); } else { xdebug_str_addl(str, "???", 3, 0); } } } else { xdebug_str_addl(str, "???", 3, 0); } } if (i->include_filename) { xdebug_str_add(str, xdebug_sprintf(formats[4], i->include_filename), 1); } if (html) { if (strlen(XG(file_link_format)) > 0) { char *just_filename = strrchr(i->filename, DEFAULT_SLASH); char *file_link; create_file_link(&file_link, i->filename, i->lineno TSRMLS_CC); xdebug_str_add(str, xdebug_sprintf(formats[10], i->filename, file_link, just_filename, i->lineno), 1); xdfree(file_link); } else { char *just_filename = strrchr(i->filename, DEFAULT_SLASH); xdebug_str_add(str, xdebug_sprintf(formats[5], i->filename, just_filename, i->lineno), 1); } } else { xdebug_str_add(str, xdebug_sprintf(formats[5], i->filename, i->lineno), 1); } } if (XG(dump_globals) && !(XG(dump_once) && XG(dumped))) { char *tmp = xdebug_get_printable_superglobals(html TSRMLS_CC); if (tmp) { xdebug_str_add(str, tmp, 1); } XG(dumped) = 1; } if (XG(show_local_vars) && XG(stack) && XDEBUG_LLIST_TAIL(XG(stack))) { int scope_nr = XG(stack)->size; i = XDEBUG_LLIST_VALP(XDEBUG_LLIST_TAIL(XG(stack))); if (i->user_defined == XDEBUG_INTERNAL && XDEBUG_LLIST_PREV(XDEBUG_LLIST_TAIL(XG(stack))) && XDEBUG_LLIST_VALP(XDEBUG_LLIST_PREV(XDEBUG_LLIST_TAIL(XG(stack))))) { i = XDEBUG_LLIST_VALP(XDEBUG_LLIST_PREV(XDEBUG_LLIST_TAIL(XG(stack)))); scope_nr--; } if (i->used_vars && i->used_vars->size) { xdebug_hash *tmp_hash; xdebug_str_add(str, xdebug_sprintf(formats[6], scope_nr), 1); tmp_hash = xdebug_used_var_hash_from_llist(i->used_vars); xdebug_hash_apply_with_argument(tmp_hash, (void*) &html, dump_used_var_with_contents, (void *) str); xdebug_hash_destroy(tmp_hash); } } } }
void xdebug_append_error_footer(xdebug_str *str, int html TSRMLS_DC) { char **formats = select_formats(html TSRMLS_CC); xdebug_str_add(str, formats[7], 0); }
static void xdebug_xml_return_text_node(xdebug_xml_text_node* node, xdebug_str* output) { xdebug_str_addl(output, "<![CDATA[", 9, 0); xdebug_str_add(output, node->text, 0); xdebug_str_addl(output, "]]>", 3, 0); }