Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate \Phalcon\Debug with XDebug #1402

Merged
merged 3 commits into from Oct 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 55 additions & 9 deletions ext/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "php_phalcon.h"
#include "phalcon.h"

#include "ext/standard/php_string.h"

#include "Zend/zend_operators.h"
#include "Zend/zend_exceptions.h"
#include "Zend/zend_interfaces.h"
Expand Down Expand Up @@ -574,6 +576,34 @@ PHP_METHOD(Phalcon_Debug, getJsSources){
RETURN_CTOR(sources);
}

PHP_METHOD(Phalcon_Debug, getFileLink) {

zval **file, **line, **format;

phalcon_fetch_params_ex(3, 0, &file, &line, &format);

PHALCON_ENSURE_IS_STRING(file);
PHALCON_ENSURE_IS_STRING(line);

if (Z_TYPE_PP(format) == IS_STRING) {
char *tmp, *link;
int tmp_len, link_len;
zval z_link = zval_used_for_init;

tmp = php_str_to_str_ex(Z_STRVAL_PP(format), Z_STRLEN_PP(format), SL("%f"), Z_STRVAL_PP(file), Z_STRLEN_PP(file), &tmp_len, 1, NULL);
link = php_str_to_str_ex(tmp, tmp_len, SL("%l"), Z_STRVAL_PP(line), Z_STRLEN_PP(line), &link_len, 1, NULL);

ZVAL_STRINGL(&z_link, link, link_len, 0);

efree(tmp);
PHALCON_CONCAT_SVSVS(return_value, "<a href=\"", &z_link, "\">", *file, "</a>");
efree(link);
}
else {
RETVAL_ZVAL(*file, 1, 0);
}
}

/**
* Shows a backtrace item
*
Expand All @@ -582,7 +612,7 @@ PHP_METHOD(Phalcon_Debug, getJsSources){
*/
PHP_METHOD(Phalcon_Debug, showTraceItem){

zval *n, *trace, *space, *two_spaces, *underscore;
zval *n, *trace, *link_format, *space, *two_spaces, *underscore;
zval *minus, *html, *class_name, *pattern, *is_phalcon_class;
zval *namespace_separator, *prepare_uri_class;
zval *class_reflection, *is_internal = NULL, *lower_class_name;
Expand All @@ -596,15 +626,15 @@ PHP_METHOD(Phalcon_Debug, showTraceItem){
zval *comment_pattern, *charset, *tab;
zval *comment, *i = NULL, *line_position = NULL, *current_line = NULL;
zval *trimmed = NULL, *is_comment = NULL, *spaced_current_line = NULL;
zval *escaped_line = NULL;
zval *escaped_line = NULL, *formatted_file = NULL;
HashTable *ah0;
HashPosition hp0;
zval **hd;
zend_class_entry *ce0, *ce1;

PHALCON_MM_GROW();

phalcon_fetch_params(1, 2, 0, &n, &trace);
phalcon_fetch_params(1, 3, 0, &n, &trace, &link_format);

PHALCON_INIT_VAR(space);
ZVAL_STRING(space, " ", 1);
Expand Down Expand Up @@ -790,11 +820,14 @@ PHP_METHOD(Phalcon_Debug, showTraceItem){

PHALCON_OBS_VAR(line);
phalcon_array_fetch_string(&line, trace, SL("line"), PH_NOISY);

PHALCON_OBS_VAR(formatted_file);
phalcon_call_method_p3_ex(formatted_file, &formatted_file, getThis(), "getfilelink", file, line, link_format);

/**
* Realpath to the file and its line using a special header
*/
PHALCON_SCONCAT_SVSVS(html, "<br/><div class=\"error-file\">", file, " (", line, ")</div>");
PHALCON_SCONCAT_SVSVS(html, "<br/><div class=\"error-file\">", formatted_file, " (", line, ")</div>");

PHALCON_OBS_VAR(show_files);
phalcon_read_property_this(&show_files, this_ptr, SL("_showFiles"), PH_NOISY_CC);
Expand Down Expand Up @@ -954,10 +987,14 @@ PHP_METHOD(Phalcon_Debug, onUncaughtException){
zval *_REQUEST, *value = NULL, *key_request = NULL, *joined_value = NULL, *_SERVER;
zval *key_server = NULL, *files, *key_file = NULL;
zval *memory, *data_var = NULL, *key_var = NULL, *variable = NULL, *dumped_argument = NULL;
zval *js_sources;
zval *js_sources, *formatted_file;
HashTable *ah0, *ah1, *ah2, *ah3, *ah4;
HashPosition hp0, hp1, hp2, hp3, hp4;
zval **hd;
char* link_format;
zend_bool ini_exists = 1;
zval z_link_format = zval_used_for_init;


PHALCON_MM_GROW();

Expand Down Expand Up @@ -1023,12 +1060,22 @@ PHP_METHOD(Phalcon_Debug, onUncaughtException){
PHALCON_INIT_VAR(line);
phalcon_call_method(line, exception, "getline");

link_format = zend_ini_string_ex(SS("xdebug.file_link_format"), 0, &ini_exists);
if (!link_format || !ini_exists) {
link_format = "file://%f#%l";
}

ZVAL_STRING(&z_link_format, link_format, 0);

PHALCON_OBS_VAR(formatted_file);
phalcon_call_method_p3_ex(formatted_file, &formatted_file, getThis(), "getfilelink", file, line, &z_link_format);

/**
* Main exception info
*/
phalcon_concat_self_str(&html, SL("<div align=\"center\"><div class=\"error-main\">") TSRMLS_CC);
PHALCON_SCONCAT_SVSVS(html, "<h1>", class_name, ": ", escaped_message, "</h1>");
PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-file\">", file, " (", line, ")</span>");
PHALCON_SCONCAT_SVSVS(html, "<span class=\"error-file\">", formatted_file, " (", line, ")</span>");
phalcon_concat_self_str(&html, SL("</div>") TSRMLS_CC);

PHALCON_OBS_VAR(show_back_trace);
Expand All @@ -1038,10 +1085,9 @@ PHP_METHOD(Phalcon_Debug, onUncaughtException){
* Check if the developer wants to show the backtrace or not
*/
if (zend_is_true(show_back_trace)) {

PHALCON_OBS_VAR(data_vars);
phalcon_read_property_this(&data_vars, this_ptr, SL("_data"), PH_NOISY_CC);

/**
* Create the tabs in the page
*/
Expand Down Expand Up @@ -1076,7 +1122,7 @@ PHP_METHOD(Phalcon_Debug, onUncaughtException){
* Every line in the trace is rendered using 'showTraceItem'
*/
PHALCON_INIT_NVAR(html_item);
phalcon_call_method_p2(html_item, this_ptr, "showtraceitem", n, trace_item);
phalcon_call_method_p3(html_item, this_ptr, "showtraceitem", n, trace_item, &z_link_format);
phalcon_concat_self(&html, html_item TSRMLS_CC);

zend_hash_move_forward_ex(ah0, &hp0);
Expand Down
8 changes: 8 additions & 0 deletions ext/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ PHP_METHOD(Phalcon_Debug, getLinesBeforeContext);
PHP_METHOD(Phalcon_Debug, setLinesBeforeContext);
PHP_METHOD(Phalcon_Debug, getLinesAfterContext);
PHP_METHOD(Phalcon_Debug, setLinesAfterContext);
PHP_METHOD(Phalcon_Debug, getFileLink);

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_seturi, 0, 0, 1)
ZEND_ARG_INFO(0, uri)
Expand Down Expand Up @@ -84,6 +85,12 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_setlines, 0, 0, 1)
ZEND_ARG_INFO(0, lines)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_debug_getfilelink, 0, 0, 3)
ZEND_ARG_INFO(0, file)
ZEND_ARG_INFO(0, line)
ZEND_ARG_INFO(0, format)
ZEND_END_ARG_INFO()

PHALCON_INIT_FUNCS(phalcon_debug_method_entry){
PHP_ME(Phalcon_Debug, setUri, arginfo_phalcon_debug_seturi, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, setShowBackTrace, arginfo_phalcon_debug_setshowbacktrace, ZEND_ACC_PUBLIC)
Expand All @@ -109,5 +116,6 @@ PHALCON_INIT_FUNCS(phalcon_debug_method_entry){
PHP_ME(Phalcon_Debug, setLinesBeforeContext, arginfo_phalcon_debug_setlines, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, getLinesAfterContext, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, setLinesAfterContext, arginfo_phalcon_debug_setlines, ZEND_ACC_PUBLIC)
PHP_ME(Phalcon_Debug, getFileLink, arginfo_phalcon_debug_getfilelink, ZEND_ACC_PROTECTED)
PHP_FE_END
};
2 changes: 1 addition & 1 deletion ext/tests/issue-1099.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ $d->listen(true, true);
throw new \Exception('Тест');
?>
--EXPECTREGEX--
^.*?<meta http-equiv="Content-Type" content="text\/html; charset=utf-8"\/>.*$
.*?<meta http-equiv="Content-Type" content="text\/html; charset=utf-8"\/>.*
19 changes: 19 additions & 0 deletions ext/tests/issue-1401.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
Phalcon\Debug and link to file with an error - https://github.com/phalcon/cphalcon/issues/1401
--SKIPIF--
<?php include('skipif.inc'); ?>
--FILE--
<?php
include('skipif.inc'); // This is to make sure the list of the included files is not empty

function do_it()
{
throw new \Exception('Test');
}

$d = new \Phalcon\Debug();
$d->listen(true, true);
do_it();
?>
--EXPECTREGEX--
.*<\/h1><span class="error-file"><a href="file:\/\/.*?\/issue-1401\.phpt?\#[0-9]+">.+?<a href="file:\/\/.*?\/issue-1401\.phpt?\#[0-9]+">.*