From 4b17bfa891c1dd495558090ef8f558a51222b7a3 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Fri, 4 May 2007 09:24:41 +0000 Subject: [PATCH] =?utf8?q?Mehr=20Debugm=C3=B6glichkeiten=20f=C3=BCr=20DBUt?= =?utf8?q?ils.pm=20und=20allgemein=20f=C3=BCr=20Fehlersituationen=20eingef?= =?utf8?q?=C3=BChrt,=20die=20=C3=BCber=20$form->error()=20signalisiert=20w?= =?utf8?q?erden.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DBUtils.pm | 33 +++++++++++++++++++++++++++++++++ SL/Form.pm | 2 ++ SL/LXDebug.pm | 32 ++++++++++++++++++++++++-------- lx-erp.conf | 1 + 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/SL/DBUtils.pm b/SL/DBUtils.pm index 8e1ea811a..fd2873ebf 100644 --- a/SL/DBUtils.pm +++ b/SL/DBUtils.pm @@ -29,6 +29,8 @@ sub conv_dateq { } sub do_query { + $main::lxdebug->enter_sub(2); + my ($form, $dbh, $query) = splice(@_, 0, 3); dump_query(LXDebug::QUERY, '', $query, @_); @@ -39,11 +41,15 @@ sub do_query { $dbh->do($query, undef, @_) || $form->dberror($query . " (" . join(", ", @_) . ")"); } + + $main::lxdebug->leave_sub(2); } sub selectrow_query { &selectfirst_array_query } sub do_statement { + $main::lxdebug->enter_sub(2); + my ($form, $sth, $query) = splice(@_, 0, 3); dump_query(LXDebug::QUERY, '', $query, @_); @@ -54,6 +60,8 @@ sub do_statement { $sth->execute(@_) || $form->dberror($query . " (" . join(", ", @_) . ")"); } + + $main::lxdebug->leave_sub(2); } sub dump_query { @@ -84,15 +92,22 @@ sub quote_db_date { } sub prepare_query { + $main::lxdebug->enter_sub(2); + my ($form, $dbh, $query) = splice(@_, 0, 3); dump_query(LXDebug::QUERY, '', $query, @_); my $sth = $dbh->prepare($query) || $form->dberror($query); + + $main::lxdebug->leave_sub(2); + return $sth; } sub prepare_execute_query { + $main::lxdebug->enter_sub(2); + my ($form, $dbh, $query) = splice(@_, 0, 3); dump_query(LXDebug::QUERY, '', $query, @_); @@ -104,10 +119,14 @@ sub prepare_execute_query { $sth->execute() || $form->dberror($query); } + $main::lxdebug->leave_sub(2); + return $sth; } sub selectall_hashref_query { + $main::lxdebug->enter_sub(2); + my ($form, $dbh, $query) = splice(@_, 0, 3); my $sth = prepare_execute_query($form, $dbh, $query, @_); @@ -117,10 +136,14 @@ sub selectall_hashref_query { } $sth->finish(); + $main::lxdebug->leave_sub(2); + return $result; } sub selectall_array_query { + $main::lxdebug->enter_sub(2); + my ($form, $dbh, $query) = splice(@_, 0, 3); my $sth = prepare_execute_query($form, $dbh, $query, @_); @@ -130,26 +153,36 @@ sub selectall_array_query { } $sth->finish(); + $main::lxdebug->leave_sub(2); + return @result; } sub selectfirst_hashref_query { + $main::lxdebug->enter_sub(2); + my ($form, $dbh, $query) = splice(@_, 0, 3); my $sth = prepare_execute_query($form, $dbh, $query, @_); my $ref = $sth->fetchrow_hashref(); $sth->finish(); + $main::lxdebug->leave_sub(2); + return $ref; } sub selectfirst_array_query { + $main::lxdebug->enter_sub(2); + my ($form, $dbh, $query) = splice(@_, 0, 3); my $sth = prepare_execute_query($form, $dbh, $query, @_); my @ret = $sth->fetchrow_array(); $sth->finish(); + $main::lxdebug->leave_sub(2); + return @ret; } diff --git a/SL/Form.pm b/SL/Form.pm index 6aedf1d6e..77d8307c3 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -258,6 +258,8 @@ sub hide_form { sub error { $main::lxdebug->enter_sub(); + $main::lxdebug->full_error_call_trace(); + my ($self, $msg) = @_; if ($ENV{HTTP_USER_AGENT}) { $msg =~ s/\n/
/g; diff --git a/SL/LXDebug.pm b/SL/LXDebug.pm index 8a4dd2923..f59e61011 100644 --- a/SL/LXDebug.pm +++ b/SL/LXDebug.pm @@ -1,12 +1,13 @@ package LXDebug; -use constant NONE => 0; -use constant INFO => 1; -use constant DEBUG1 => 2; -use constant DEBUG2 => 4; -use constant QUERY => 8; -use constant TRACE => 16; -use constant ALL => 31; +use constant NONE => 0; +use constant INFO => 1; +use constant DEBUG1 => 2; +use constant DEBUG2 => 4; +use constant QUERY => 8; +use constant TRACE => 16; +use constant CALL_TRACE_ON_ERROR => 32; +use constant ALL => 63; use constant FILE_TARGET => 0; use constant STDERR_TARGET => 1; @@ -99,6 +100,21 @@ sub leave_sub { return 1; } +sub full_error_call_trace { + my ($self) = @_; + + return 1 unless ($global_level & CALL_TRACE_ON_ERROR); + + $self->message(CALL_TRACE_ON_ERROR, "Starting full caller dump:"); + my $level = 0; + while (my ($dummy, $filename, $line, $subroutine) = caller $level) { + $self->message(CALL_TRACE_ON_ERROR, "${subroutine} from ${filename}:${line}"); + $level++; + } + + return 1; +} + sub message { my ($self, $level, $message) = @_; @@ -146,7 +162,7 @@ sub _write { sub level2string { # use $_[0] as a bit mask and return levelstrings separated by / - join '/', qw(info debug1 debug2 query trace)[ grep { (reverse split //, sprintf "%05b", $_[0])[$_] } 0..4 ] + join '/', qw(info debug1 debug2 query trace error_call_trace)[ grep { (reverse split //, sprintf "%05b", $_[0])[$_] } 0..5 ] } 1; diff --git a/lx-erp.conf b/lx-erp.conf index 8ab6ce8d1..1bf389580 100644 --- a/lx-erp.conf +++ b/lx-erp.conf @@ -77,6 +77,7 @@ $dbcharset = "ISO-8859-15"; # LXDebug::DEBUG2 # LXDebug::QUERY - SQL Queries # LXDebug::TRACE - Tracing von Funktionsaufrufen +# LXDebug::CALL_TRACE_ON_ERROR - Vollständiger Aufrufpfad, wenn $form->error() aufgerufen wird # LXDebug::ALL - alle Debugausgaben # # Beipiel: -- 2.20.1