読者です 読者をやめる 読者になる 読者になる

perldebugの使い方

●変数に値を設定して表示($xxx=yyy, p $xxx)

12: my $pattern;
DB<1> $pattern='perl'

DB<2> p $pattern
perl
DB<3>

●周辺のソースを表示(l, v)

DB<3> l
12==> my $pattern;
13 #print "Enter search string: ";
14 #chomp ($pattern = <> );
15: chomp ($pattern = './perl_debugger.pl' );
16: return $pattern;
17 }
18
19 # Function : find_files
20 # Description : to get list of filenames that contains the input pattern.
21 sub find_files
DB<3>

#----

DB<11> v
28
29 # taking out the filenames that contains pattern.
30: @list = grep {
31==> $file = $_;
32: open $FH,"$file";
33: @lines = <$FH>;
34: $count = grep { /$pattern/ } @lines;
35: $file if($count);
36 } @files;
37: return @list;
DB<11>

●現在のpackageの変数を表示(V)
DB<8> V
$GLOB_ALPHASORT = 8192
(略)
$GLOB_NOCHECK = 16
DB<8>


●現在読み込んでいるモジュールとバージョンを表示(M)
DB<11> M
'/usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int/auto/Term/ReadLine/Gnu/XS/autosplit.ix' => '/usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int/auto/Term/ReadLine/Gnu/XS/autosplit.ix'
'AutoLoader.pm' => '5.71 from /usr/lib/perl5/5.14/AutoLoader.pm'
'Carp.pm' => '1.20 from /usr/lib/perl5/5.14/Carp.pm'
'Config.pm' => '/usr/lib/perl5/5.14/i686-cygwin-threads-64int/Config.pm'
'Config_git.pl' => '/usr/lib/perl5/5.14/i686-cygwin-threads-64int/Config_git.pl'
'Config_heavy.pl' => '/usr/lib/perl5/5.14/i686-cygwin-threads-64int/Config_heavy.pl'
'DynaLoader.pm' => '1.13 from /usr/lib/perl5/5.14/i686-cygwin-threads-64int/DynaLoader.pm'
'Exporter.pm' => '5.64_03 from /usr/lib/perl5/5.14/Exporter.pm'
'File/Glob.pm' => '1.13 from /usr/lib/perl5/5.14/i686-cygwin-threads-64int/File/Glob.pm'
'IO.pm' => '1.25_04 from /usr/lib/perl5/5.14/i686-cygwin-threads-64int/IO.pm'
'IO/Handle.pm' => '1.31 from /usr/lib/perl5/5.14/i686-cygwin-threads-64int/IO/Handle.pm'
'SelectSaver.pm' => '1.02 from /usr/lib/perl5/5.14/SelectSaver.pm'
'Symbol.pm' => '1.07 from /usr/lib/perl5/5.14/Symbol.pm'
'Term/ReadLine.pm' => '1.07 from /usr/lib/perl5/5.14/Term/ReadLine.pm'
'Term/ReadLine/Gnu.pm' => '1.20 from /usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int/Term/ReadLine/Gnu.pm'
'Term/ReadLine/Gnu/XS.pm' => '1.17 from /usr/lib/perl5/vendor_perl/5.14/i686-cygwin-threads-64int/Term/ReadLine/Gnu/XS.pm'
'XSLoader.pm' => '0.13 from /usr/lib/perl5/5.14/XSLoader.pm'
'dumpvar.pl' => '/usr/lib/perl5/5.14/dumpvar.pl'
'feature.pm' => '1.20 from /usr/lib/perl5/5.14/feature.pm'
'perl5db.pl' => '1.33 from /usr/lib/perl5/5.14/perl5db.pl'
'strict.pm' => '1.04 from /usr/lib/perl5/5.14/strict.pm'
'vars.pm' => '1.02 from /usr/lib/perl5/5.14/vars.pm'
'warnings.pm' => '1.12 from /usr/lib/perl5/5.14/warnings.pm'
'warnings/register.pm' => '1.02 from /usr/lib/perl5/5.14/warnings/register.pm'
DB<11>

●現在のサブルーチンをreturnまで続行(r)
DB<11> r
list context return from File::Glob::csh_glob:
0 './perl_debugger.pl'
main::find_files(perl_debugger.pl:31):
31: $file = $_;
DB<11>

●内部変数を表示(r)
DB<13> y
$file = './perl_debugger.pl'
$pattern = './perl_debugger.pl'
@files = (
0 './perl_debugger.pl'
)
@list = (
empty array
)
DB<13>

●プログラムを実行(n, s)


●配列の中身を表示(x)
DB<13> x @files
0 './perl_debugger.pl'
DB<14>


●breakpointを設定して表示(b [line], L)
DB<14> b 33
DB<15> L
perl_debugger.pl:
33: @lines = <$FH>;
break if (1)
DB<15>


●breakpoint を特定の条件の数値で指定して実行(b [line] [condition])
main::(check_breakpoint.pl:3): foreach my $i (1..100){
DB<1> v
1 #!/usr/bin/perl
2
3==> foreach my $i (1..100){
4: if($i==50) {
5: print "i=50\n";
6 }
7 }
8
DB<1> b 4 $i==50
DB<2> L
check_breakpoint.pl:
4: if($i==50) {
break if ($i==50)
DB<2> c
main::(check_breakpoint.pl:4): if($i==50) {
DB<2> s
main::(check_breakpoint.pl:5): print "i=50\n";
DB<2>

●breakpoint を特定の条件の文字列($_)で指定して実行(b [line] [condition])
DB<5> v
6 Enjoy Perl Debug!
7 END
8
9==> foreach (split(/\n/,$data)){
10: if (/test/) {
11: print $_, "\n";
12 }
13 }
DB<5> b 10 /test/ ★9行目に設定すると意図した動作とならない
DB<6> L
check_breakpoint2.pl:
10: if (/test/) {
break if (/test/)
DB<6> c
main::(check_breakpoint2.pl:10): if (/test/) {
DB<6> v
7 END
8
9: foreach (split(/\n/,$data)){
10==>b if (/test/) {
11: print $_, "\n";
12 }
13 }
DB<6> s
main::(check_breakpoint2.pl:11): print $_, "\n";
DB<6>

●breakpoint を特定の条件の文字列($str)で指定して実行(b [line] [condition])
DB<1> v
6 Enjoy Perl Debug!
7 END
8
9==> foreach my $str (split(/\n/,$data)){
10: if ($str =~ /test/) {
11: print $str, "\n";
12 }
13 }
DB<1> b 10 $str=~/test/ ★
DB<2> L
check_breakpoint3.pl:
10: if ($str =~ /test/) {
break if ($str=~/test/)
DB<2> c
main::(check_breakpoint3.pl:10): if ($str =~ /test/) {
DB<2> v
7 END
8
9: foreach my $str (split(/\n/,$data)){
10==>b if ($str =~ /test/) {
11: print $str, "\n";
12 }
13 }
DB<2> s
main::(check_breakpoint3.pl:11): print $str, "\n";
DB<2>

デバッグを再実行(R)

●全てのbreakpointを削除(B *)
DB<1> B *
Deleting all breakpoints...
DB<2> L
DB<2>