From 6fcf6f5b5891c5fbbe12c01ee80c289f9bf46d97 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Thu, 9 Dec 2010 11:07:41 +0000 Subject: [PATCH] Debug backtrace on all errors when go_debug is set to 2 --- includes/errors.inc | 7 +++-- includes/ui/ui_msgs.inc | 7 +++-- includes/ui/ui_view.inc | 61 ++++++++++++++++++++++------------------- 3 files changed, 42 insertions(+), 33 deletions(-) diff --git a/includes/errors.inc b/includes/errors.inc index bcb3cd3f..f55951cf 100644 --- a/includes/errors.inc +++ b/includes/errors.inc @@ -29,8 +29,9 @@ function error_handler($errno, $errstr, $file, $line) { } // error_reporting==0 when messages are set off with @ - if ($errno & error_reporting()) - $messages[] = array($errno, $errstr, $file, $line); + if ($errno & error_reporting()) { + $messages[] = array($errno, $errstr, $file, $line); + } else if($errno&~E_NOTICE) { // log all not displayed messages $user = @$_SESSION["wa_current_user"]->loginname; $context = isset($SysPrefs) && !$SysPrefs->db_ok ? '[before upgrade]' : ''; @@ -131,7 +132,7 @@ function display_db_error($msg, $sql_statement=null, $exit=true) $cur_prefix = $db_connections[$_SESSION["wa_current_user"]->cur_con]['tbpref']; $str .= "sql that failed was : ".str_replace(TB_PREF, $cur_prefix, $sql_statement)."
"; - if ($go_debug > 1) display_backtrace(); +// if ($go_debug > 1) display_backtrace(); } $str .= "

"; diff --git a/includes/ui/ui_msgs.inc b/includes/ui/ui_msgs.inc index 8925c030..5c28c893 100644 --- a/includes/ui/ui_msgs.inc +++ b/includes/ui/ui_msgs.inc @@ -11,7 +11,10 @@ ***********************************************************************/ function display_error($msg, $center=true) { - trigger_error($msg, E_USER_ERROR); + global $go_debug; + + $bt = $go_debug>1 ? ('
'.get_backtrace(true)) : ''; + trigger_error($msg.$bt, E_USER_ERROR); } function display_notification($msg, $center=true) @@ -55,7 +58,7 @@ function stock_item_heading($stock_id) { if ($stock_id != "") { - $result = db_query("SELECT description, units FROM ".TB_PREF."stock_master WHERE stock_id='$stock_id'"); + $result = db_query("SELECT description, units FROM ".TB_PREF."stock_master WHERE stock_id=".db_escape($stock_id)); $myrow = db_fetch_row($result); display_heading("$stock_id - $myrow[0]"); diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 69810222..c0e9e8c9 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -1306,42 +1306,47 @@ function _vl($mixed, $title = '', $exit = false) } function display_backtrace($cond=true, $msg='') { - if ($cond) { if ($msg) $str = "
$msg
\n"; else $str = ''; - $str .= ''; - $trace = debug_backtrace(); - foreach($trace as $trn => $tr) { - if (!$trn) continue; - $str .= ''; } -} + if ($html) $str .= '
'; - $str .= $tr['file'].':'.$tr['line'].': '; - $str .= ''; - if (isset($tr['type'])) { - if($tr['type'] == '::') { - $str .= $tr['class'].'::'; - } else if($tr['type'] == '->') { - $str .= '('.$tr['class'].' Object)'.'->'; - } - } - foreach($tr['args'] as $n=>$a) { - if (is_object($tr['args'][$n])) - $tr['args'][$n] = "(".get_class($tr['args'][$n])." Object)"; - if (is_array($tr['args'][$n])) - $tr['args'][$n] = "(Array[".count($tr['args'][$n])."])"; - else - $tr['args'][$n] = "'".$tr['args'][$n]."'"; + $str .= get_backtrace(true); + display_error($str); + } +} + +function get_backtrace($html = false) +{ + $str = ''; + if ($html) $str .= ''; + $trace = debug_backtrace(); + + foreach($trace as $trn => $tr) { + if (!$trn) continue; + if ($html) $str .= ''; + } - $str .= ''; + foreach($tr['args'] as $n=>$a) { + if (is_object($tr['args'][$n])) + $tr['args'][$n] = "(".get_class($tr['args'][$n])." Object)"; + if (is_array($tr['args'][$n])) + $tr['args'][$n] = "(Array[".count($tr['args'][$n])."])"; + else + $tr['args'][$n] = "'".$tr['args'][$n]."'"; } - - $str .= '
'; + $str .= $tr['file'].':'.$tr['line'].': '; + if ($html) $str .= ''; + if (isset($tr['type'])) { + if($tr['type'] == '::') { + $str .= $tr['class'].'::'; + } else if($tr['type'] == '->') { + $str .= '('.$tr['class'].' Object)'.'->'; } - $str .= $tr['function'].'('. implode(',',$tr['args']).')
'; - display_error($str); + $str .= $tr['function'].'('. implode(',',$tr['args']).')
'; + return $str; +} ?> \ No newline at end of file -- 2.30.2