Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need help in debugging a small perl program 1

Status
Not open for further replies.

LustyLearner

Programmer
Feb 4, 2005
5
US
Hi there,
I am a new B to the perl programming. I just started it just coule of days ago. I am just trying to understand few basic debugging concepts and i am running into problems.

Here is the program i am using for my testing:


********* program begin****************
#!/usr/bin/perl -w
# Author: Learner
# Copyright 2004.
#
# This program demonstrates the Perl debugger.
use strict;

looper();

sub looper {
my $arg = 0;
while ($arg < 10) {
++$arg;
}
}


**********program End*****************
The problem with debugging commands are a (action) and b (breakpoints).

When i try as below:

C:\Perl\Assignment3>perl -d testDebugger.pl

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(testDebugger.pl:8): looper();
DB<1> v
5 # This program demonstrates the Perl debugger.
6: use strict;
7
8==> looper();
9
10 sub looper {
11: my $arg = 0;
12: while ($arg < 10) {
13: ++$arg;
14 }
DB<1> a 12 print "arg is now $arg... "
DB<2> b 12 ($arg > 8)
DB<3> c

i am expecting result which looks like
********************Begin Expected result*******************
arg is now 0... arg is now 0... arg is now 1... arg is now 1... arg is now 2...
arg is now 2... arg is now 3... arg is now 3... arg is now 4... arg is now 4...
arg is now 5... arg is now 5... arg is now 6... arg is now 6... arg is now 7...
arg is now 7... arg is now 8... arg is now 8... main::looper(testDebugger.pl:12)
: while ($arg < 10) {
DB<3> ow 9...
******************************End of expected result*******


But instead of this i am getting some thing different ... i dont' know what exactly it is but i can paste down here.
************** begin of my program output*******************
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
Use of uninitialized value in concatenation (.) or string at (eval 8)[D:/Perl/lib/perl5db.pl:628] line 1.
at (eval 8)[D:/Perl/lib/perl5db.pl:628] line 1
eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main; print "arg is now $arg... ";

;' called at D:/Perl/lib/perl5db.pl line 628
DB::eval called at D:/Perl/lib/perl5db.pl line 2127
DB::DB called at D:/Perl/lib/perl5db.pl line 9421
DB::fake::at_exit() called at D:/Perl/lib/perl5db.pl line 8993
DB::END() called at (eval 8)[D:/Perl/lib/perl5db.pl:628] line 0
eval {...} called at (eval 8)[D:/Perl/lib/perl5db.pl:628] line 0
DB<3> arg is now 0... arg is now ...
**************End of my program out put*********************


I don't understand what exactly it means. I am not sure if i am missing some thing here. Please help me out what should i do.

Thanks in advance.
Learner
 
Hi Learner,
From first glance it seems to be a problem with your perl debugger. I copied your code into a file and ran the debugger and was successful in the commands that you were supposed to do. Where did you get your build of perl from?
I would try to run the program first without the debugger and see what happens... Maybe actually add this line: print "arg is now $arg... "; at line 12 so you can get some output, and then run "perl testDebugger.pl" from your command prompt. See what output you get.
And if you have time, I would try to re-install active perl:
Get the latest build, and then re-try your debugging exercise. Because everything seems to work right when I do your lesson on my PC, so I am thinking something is wrong with either your build, or your perl5db.pl file.

Have a great day!
 
Hi BrainAtWork,
Thanks for the advice i just tried putting the print "arg is now $arg... \n"; line at 12 and when i just ran it with out debugging it did work well. I am not sure why its behaving differently. I have got it off the web from the same website, activeperl.com. I have downloaded it onto my work place as well as on my home computer. i am getting the same thing on my home computer too. May be like you said i will have to redownload it from the URL you provided and try reinstalling it.
Thanks for your time and have a wonderful weekend.
thanks
Learner
 
Hi BrainAtWork,
I just got both ActivePerl-5.6.1.638-MSWin32-x86.msi and ActivePerl-5.8.6.811-MSWin32-x86-122208.msi from the site
and tried running the program with both the versions of perl. I had to uninstall and reinstall the two versions couple of times but no luck yet. i am using windows 2000 server at work and XP professional at home. Do you think these OSs make any difference? reinstallation process went well every thing looks good to me. No luck yet. I will keep trying on it. If you have any work please shoot it.
thanks
Learner
 
Hmmm - That is strange. Can you try debugging again, and this time paste all of the output? It looks like you only pasted the bottom portion. And also - I copied directly what you pasted into this post and ran it with the debugger, and it worked - maybe you try doing the same? Maybe there is a typo in your code that you are running? Yeah - far off chance, but worth a try...
 
Works OK for me too. activeperl 5.8.0 on windows98
 
HI all,

I just tried it from home i still get the same error. Here is what i have tried.

********* Debugging transcript *************
C:\Perl5.8.6\Assignment3>perl -d testDebugger.pl

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(testDebugger.pl:8): looper();
DB<1> v
5 # This program demonstrates the Perl debugger.
6: use strict;
7
8==> looper();
9
10 sub looper {
11: my $arg = 0;
12: while ($arg < 10) {
13: ++$arg;
14 }
DB<1> a 12 print "arg is now $arg... "
DB<2> b 12 ($arg > 8)
DB<3> c
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
Use of uninitialized value in concatenation (.) or string at (eval 8)[C:/Program
Files/Perl/lib/perl5db.pl:628] line 1.
at (eval 8)[C:/Program Files/Perl/lib/perl5db.pl:628] line 1
eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main; print "arg
is now $arg... ";

;' called at C:/Program Files/Perl/lib/perl5db.pl line 628
DB::eval called at C:/Program Files/Perl/lib/perl5db.pl line 2127
DB::DB called at C:/Program Files/Perl/lib/perl5db.pl line 9421
DB::fake::at_exit() called at C:/Program Files/Perl/lib/perl5db.pl line
8993
DB::END() called at (eval 8)[C:/Program Files/Perl/lib/perl5db.pl:628] l
ine 0
eval {...} called at (eval 8)[C:/Program Files/Perl/lib/perl5db.pl:628]
line 0
DB<3> arg is now 0... arg is now ...

******************* End of debugging transcript*************

**************** The original program***************
#!/usr/bin/perl -w
# Author: Learner
# Copyright 2004.
#
# This program demonstrates the Perl debugger.
use strict;

looper();

sub looper {
my $arg = 0;
while ($arg < 10) {
++$arg;
}
}

************** End of original program***************

Hope this helps. And also i am getting another break point error. When i try to put a break point at line 12 and try continuing the debugging using c command i am getting following error/result.

********* here is the results********************
10 sub looper {
11: my $arg = 0;
12: while ($arg < 10) {
13: ++$arg;
14 }
DB<1> b 12 ($arg > 5)
DB<2> c
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<2>
**********End of the result********************.


But instead i am expected the result as below:
****************** Expected result*************
DB<1> b 12 ($arg > 5)
DB<2> c
main::looper(testDebugger.pl:12): while ($arg < 10) {
DB<2> p $arg
6
DB<3>
********************End of expected result*************

Please help me with these.
Thanks in advance
Learner
 
I'm kind of running out of ideas - It really looks like something is wrong with the debugger, but uninstalling/reinstalling did not fix that...

One last thing - if it isn't already, add your perl directory to your path (at the dos command prompt):
Code:
path=%PATH%; c:\Perl5.8.6;
Also - try taking the "-w" out of your first line in your code. That shouldn't affect the debugger, but I can't think of anything else =)

Hope that will help...

Brian
 
Also - try taking the "-w" out of your first line in your code. That shouldn't affect the debugger, but I can't think of anything else =)

Oh, naughty, naughty. Even for the best of reasons you shouldn't ever encourage anyone not to use warnings or strict mode when programming perl - and certainly not to anyone who's learning it. Ten demerits and you get to sit at the back of the class for the rest of the week ;-)
 
:-D
True - I never go without the -w or use strict; but in this case, I was trying to think of all possibilities - If it still doesn't work when you take the -w out, definitely, put it back in - never leave home without it!
 
Hi BrainAtWork,
I tried again doing like you said. Here is the output i have got. No change. When installing and uninstalling i have changed my directory to perl instead of perl 5.8.6 so i just used c:\perl to set the path. Your guess may be right there should be some thing wrong with the debugger. I also have removed -w from the top line. when i asked one of my friends to run on his Unix box he says it works pretty well. But it doesn't work on my computer with windows OS. I will personally go run it on Unix box and see how it goes. I will let you know how it goes. I really appriciate of your time.
Thanks
-Learner


Here is the output i have got:


C:\>path=%PATH%; c:\perl;

C:\>cd perl

C:\Perl>perl -d testDebugger.pl

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(testDebugger.pl:8): looper();
DB<1> v
5 # This program demonstrates the Perl debugger.
6: use strict;
7
8==> looper();
9
10 sub looper {
11: my $arg = 0;
12: while ($arg < 10) {
13: ++$arg;
14 }
DB<1> a 12 print "arg is now $arg..."
DB<2> b 12 ($arg > 8)
DB<3> c
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
DB<3> arg is now 0...arg is now ...q

C:\Perl>perl -d testDebugger.pl

Loading DB routines from perl5db.pl version 1.28
Editor support available.

Enter h or `h h' for help, or `perldoc perldebug' for more help.

main::(testDebugger.pl:8): looper();
DB<1> v
5 # This program demonstrates the Perl debugger.
6: use strict;
7
8==> looper();
9
10 sub looper {
11: my $arg = 0;
12: while ($arg < 10) {
13: ++$arg;
14 }
DB<1> a 12 print "arg is now $arg...\n"
DB<2> b 12 ($arg > 8)
DB<3> c
arg is now 0...
Debugged program terminated. Use q to quit or R to restart,
use O inhibit_exit to avoid stopping after program termination,
h q, h R or h O to get additional info.
arg is now ...
DB<3>
 
Looking at how the debugger is evaluating the lines of code, you could try one thing - more for my curiosity than anything else - instead of declaring my $arg = 0; inside the looper() function, try declaring it globally before the looper() call. If it doesn't come up with the uninitialised error, or even manages to work, then the debugger is indeed truly useless, as it would only ever be able to perform tests on global variables. However, this is what it looks like it might just do to me, given the output which read eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main; print "arg is now $arg... ";'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top