static void xdebug_xml_text_node_dtor(xdebug_xml_text_node* node) { if (node->free_value && node->text) { xdfree(node->text); } xdfree(node); }
void xdebug_coverage_file_dtor(void *data) { xdebug_coverage_file *file = (xdebug_coverage_file *) data; xdebug_hash_destroy(file->lines); xdfree(file->name); xdfree(file); }
void xdebug_monitored_function_dtor(void *dummy, void *elem) { xdebug_monitored_function_entry *mfe = (xdebug_monitored_function_entry*) elem; xdfree(mfe->func_name); xdfree(mfe->filename); xdfree(mfe); }
void xdebug_coverage_function_dtor(void *data) { xdebug_coverage_function *function = (xdebug_coverage_function *) data; if (function->branch_info) { xdebug_branch_info_free(function->branch_info); } xdfree(function->name); xdfree(function); }
void xdebug_profile_aggr_call_entry_dtor(void *elem) { xdebug_aggregate_entry *xae = (xdebug_aggregate_entry *) elem; if (xae->filename) { xdfree(xae->filename); } if (xae->function) { xdfree(xae->function); } }
void xdebug_hash_eval_info_dtor(xdebug_eval_info *ei) { ei->refcount--; if (ei->refcount == 0) { xdfree(ei->contents); xdfree(ei); } else { /* refcount wasn't 0 yet, so we won't free it yet */ } }
static void xdebug_xml_attribute_dtor(xdebug_xml_attribute *attr) { if (attr->next) { xdebug_xml_attribute_dtor(attr->next); } if (attr->free_name) { xdfree(attr->name); } if (attr->free_value) { xdfree(attr->value); } xdfree(attr); }
void xdebug_profile_call_entry_dtor(void *dummy, void *elem) { xdebug_call_entry *ce = elem; if (ce->function) { xdfree(ce->function); } if (ce->filename) { xdfree(ce->filename); } xdfree(ce); }
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); } } }
xdebug_xml_node* xdebug_get_value_xml_node(const char* name, const Variant& val, XDebugVarType type /* = XDebugVarType::Normal */, XDebugExporter& exporter) { // Compute the short and full name of the passed value char* short_name = nullptr; char* full_name = nullptr; if (name) { switch (type) { case XDebugVarType::Normal: { char* tmp_name = prepare_variable_name(name); short_name = xdstrdup(tmp_name); full_name = xdstrdup(tmp_name); xdfree(tmp_name); break; } case XDebugVarType::Static: short_name = xdebug_sprintf("::%s", name); full_name = xdebug_sprintf("::%s", name); break; case XDebugVarType::Constant: short_name = xdstrdup(name); full_name = xdstrdup(name); break; default: throw Exception("Invalid variable type"); } } // Recursively construct the xml return xdebug_var_export_xml_node(short_name, full_name, nullptr, val, exporter); }
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_brk_info_dtor(xdebug_brk_info *brk_info) { if (brk_info->classname) { xdfree(brk_info->classname); } if (brk_info->functionname) { xdfree(brk_info->functionname); } if (brk_info->file) { xdfree(brk_info->file); } if (brk_info->condition) { xdfree(brk_info->condition); } xdfree(brk_info); }
char *xdebug_sprintf(const char* fmt, ...) { char *new_str; int size = 1; va_list args; char *orig_locale; orig_locale = xdstrdup(setlocale(LC_ALL, NULL)); setlocale(LC_ALL, "C"); new_str = (char *) xdmalloc(size); for (;;) { int n; va_start(args, fmt); n = vsnprintf(new_str, size, fmt, args); va_end(args); if (n > -1 && n < size) { break; } if (n < 0) { size *= 2; } else { size = n + 1; } new_str = (char *) xdrealloc(new_str, size); } setlocale(LC_ALL, orig_locale); xdfree(orig_locale); return new_str; }
void xdebug_path_info_dtor(xdebug_path_info *path_info) { unsigned int i; for (i = 0; i < path_info->paths_count; i++) { xdebug_path_free(path_info->paths[i]); } xdfree(path_info->paths); path_info->paths = NULL; if (path_info->path_hash) { xdebug_hash_destroy(path_info->path_hash); path_info->path_hash = NULL; } xdfree(path_info); }
void xdebug_xml_node_dtor(xdebug_xml_node* xml) { if (xml->next) { xdebug_xml_node_dtor(xml->next); } if (xml->child) { xdebug_xml_node_dtor(xml->child); } if (xml->attribute) { xdebug_xml_attribute_dtor(xml->attribute); } if (xml->free_tag) { xdfree(xml->tag); } if (xml->text) { xdebug_xml_text_node_dtor(xml->text); } xdfree(xml); }
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_trace_function_end(function_stack_entry *fse, int function_nr TSRMLS_DC) { if (XG(do_trace) && XG(trace_file)) { char *t = return_trace_stack_frame_end(fse, function_nr TSRMLS_CC); if (fprintf(XG(trace_file), "%s", t) < 0) { fclose(XG(trace_file)); XG(trace_file) = NULL; } else { fflush(XG(trace_file)); } xdfree(t); } }
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); } }
void xdebug_str_add(xdebug_str *xs, char *str, int f) { int l = strlen(str); if (xs->l + l > xs->a - 1) { xs->d = (char*) xdrealloc(xs->d, xs->a + l + XDEBUG_STR_PREALLOC); xs->a = xs->a + l + XDEBUG_STR_PREALLOC; } if (!xs->l) { xs->d[0] = '\0'; } memcpy(xs->d + xs->l, str, l); xs->d[xs->l + l] = '\0'; xs->l = xs->l + l; if (f) { xdfree(str); } }
void xdebug_str_addl(xdebug_str *xs, char *str, int le, int f) { if (xs->l + le > xs->a - 1) { xs->d = (char*) xdrealloc(xs->d, xs->a + le + XDEBUG_STR_PREALLOC); xs->a = xs->a + le + XDEBUG_STR_PREALLOC; } if (!xs->l) { xs->d[0] = '\0'; } memcpy(xs->d + xs->l, str, le); xs->d[xs->l + le] = '\0'; xs->l = xs->l + le; if (f) { xdfree(str); } }
// TODO(#3704) Clean this up-- this was taken from php5 xdebug char* XDebugUtils::pathToUrl(const char* fileurl) { int l, i, new_len; char *tmp = nullptr; char *encoded_fileurl; /* encode the url */ encoded_fileurl = xdebug_raw_url_encode(fileurl, strlen(fileurl), &new_len, 1); if (strncmp(fileurl, "phar://", 7) == 0) { /* ignore, phar is cool */ tmp = xdstrdup(fileurl); } else if (fileurl[0] != '/' && fileurl[0] != '\\' && fileurl[1] != ':') { String path(fileurl, CopyString); Variant realpath = HHVM_FN(realpath)(path); if (realpath.isString()) { char* realpath_str = realpath.toString().get()->mutableData(); tmp = xdebug_sprintf("file://%s", realpath_str); } else { // Couldn't convert, use raw path tmp = xdstrdup(encoded_fileurl); } } else if (fileurl[1] == '/' || fileurl[1] == '\\') { // convert UNC paths (eg. \\server\sharepath) // http://blogs.msdn.com/ie/archive/2006/12/06/file-uris-in-windows.aspx tmp = xdebug_sprintf("file:%s", encoded_fileurl); } else if (fileurl[0] == '/' || fileurl[0] == '\\') { /* convert *nix paths (eg. /path) */ tmp = xdebug_sprintf("file://%s", encoded_fileurl); } else if (fileurl[1] == ':') { /* convert windows drive paths (eg. c:\path) */ tmp = xdebug_sprintf("file:///%s", encoded_fileurl); } else { /* no clue about it, use it raw */ tmp = xdstrdup(encoded_fileurl); } l = strlen(tmp); /* convert '\' to '/' */ for (i = 0; i < l; i++) { if (tmp[i] == '\\') { tmp[i]='/'; } } xdfree(encoded_fileurl); // Needs to be free return tmp; }
void xdebug_branch_find_paths(xdebug_branch_info *branch_info) { unsigned int i; for (i = 0; i < branch_info->entry_points->size; i++) { if (xdebug_set_in(branch_info->entry_points, i)) { xdebug_branch_find_path(i, branch_info, NULL); } } branch_info->path_info.path_hash = xdebug_hash_alloc(128, NULL); for (i = 0; i < branch_info->path_info.paths_count; i++) { xdebug_str str = { 0, 0, NULL }; xdebug_create_key_for_path(branch_info->path_info.paths[i], &str); xdebug_hash_add(branch_info->path_info.path_hash, str.d, str.l, branch_info->path_info.paths[i]); xdfree(str.d); } }
static void xdebug_hash_function_monitor_dtor(char *function) { xdfree(function); }
void xdebug_coverage_line_dtor(void *data) { xdebug_coverage_line *line = (xdebug_coverage_line *) data; xdfree(line); }
void xdebug_str_free(xdebug_str *s) { if (s->d) { xdfree(s->d); } }
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); } } } }