[Israel.pm] Backtrace

Peter Gordon peter at pg-consultants.com
Sun Jun 6 05:53:08 PDT 2010


I have a trivial program shown below. In order to better debug an
application I would like to be able to obtain a stack trace. 

If I run the program normally, I get 
Can't call method "hello" on an undefined value at a4.pl line 32.

If I run with debug,  I get a much more informative
Can't call method "hello" on an undefined value at a4.pl line 32.
 at a4.pl line 32
	p7::func7() called at a4.pl line 27
	p6::func6() called at a4.pl line 23
	p5::func5() called at a4.pl line 19
	p4::func4() called at a4.pl line 15
	p3::func3() called at a4.pl line 11
	p2::func2() called at a4.pl line 7
	p1::func1() called at a4.pl line 35

Is there any way to get this stack trace without the debugger?

Peter

#! /usr/bin/perl

use strict ;

package p1 ;
sub func1 { 
    p2::func2() ; 
} 
package p2 ;
sub func2 { 
    p3::func3() ; 
} 
package p3 ;
sub func3 { 
    p4::func4() ; 
} 
package p4 ;
sub func4 { 
    p5::func5() ; 
} 
package p5 ;
sub func5 { 
    p6::func6() ; 
} 
package p6 ;
sub func6 { 
    p7::func7() ; 
} 
package p7 ;
sub func7 { 
    my $x7 ;
    $x7->hello() ;
} 
 
p1::func1() ;





More information about the Perl mailing list